MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / simple_prep_env

Method simple_prep_env

class/projectModel/pythonModel.py:435–492  ·  view source on GitHub ↗

准备python虚拟环境和服务器应用

(self, values: dict)

Source from the content-addressed store, hash-verified

433
434
435 def simple_prep_env(self, values: dict) -> Optional[bool]:
436 """
437 准备python虚拟环境和服务器应用
438 """
439 log_path: str = "{}/{}.log".format(self._logs_path, values['pjname'])
440 fd = open(log_path, 'w')
441 fd.flush()
442 py_env = EnvironmentManager().get_env_py_path(values.get("python_bin", ""))
443 if not py_env:
444 fd.write("|- 环境丢失,无法继续初始化python环境。")
445 fd.flush()
446 fd.close()
447 return False
448
449 def call_log(log: str) -> None:
450 if log[-1] != "\n":
451 log += "\n"
452 fd.write(log)
453 fd.flush()
454
455 try:
456 # 安装服务器依赖
457 call_log("\n|- 开始安装托管服务依赖库.\n")
458 py_env.init_site_server_pkg(call_log=call_log)
459 py_env.use2project(values['pjname'])
460 # 安装第三方依赖
461 self.install_requirement(values, py_env, call_log=call_log)
462 self.__prepare_start_conf(values, pyenv=py_env)
463 call_log("\n|- 配置文件输出成功\n")
464 initialize = values.get("initialize", '')
465 if initialize:
466 call_log("\n|- 开始执行项目初始化命令.......\n")
467 if values.get("env_list", None) or values.get("env_file", None):
468 env_file = "{}/{}.env".format(self._env_path, values["pjname"])
469 initialize = "source {env_file} \n".format(env_file=env_file) + initialize
470 py_env.exec_shell(initialize, call_log=call_log, user=values.get("user", "root"))
471 call_log("\n|- 项目初始化命令执行结束-------\n")
472
473 # 先尝试启动
474 conf = self._get_project_conf(values['pjname'])
475 self.__start_project(conf)
476 call_log("\n|- 已尝试启动项目\n")
477 for k, v in values.items(): # 更新配置文件
478 if k not in conf:
479 conf[k] = v
480
481 pdata = {
482 "project_config": json.dumps(conf)
483 }
484 public.M('sites').where('name=?', (values['pjname'].strip(),)).update(pdata)
485 fd.close()
486 except:
487 import traceback
488 if not fd.closed:
489 fd.write(traceback.format_exc())
490 fd.write("\n|- 环境准备失败\n")
491 fd.close()
492 return True

Callers 1

mainFunction · 0.80

Calls 15

install_requirementMethod · 0.95
__prepare_start_confMethod · 0.95
_get_project_confMethod · 0.95
__start_projectMethod · 0.95
EnvironmentManagerClass · 0.90
openFunction · 0.85
get_env_py_pathMethod · 0.80
init_site_server_pkgMethod · 0.80
use2projectMethod · 0.80
formatMethod · 0.45
flushMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected