PK!%%dophon_manager/__init__.pyimport argparse from dophon_manager.actions import * parser = argparse.ArgumentParser(description='dophon project manager') parser.add_argument('action', type=str, default='-h') parser.add_argument('--action_arg', type=str, default='dophon_project') FLAGS = parser.parse_args() ARG_DICT = { 'new': ActionObj().new_action } __version__ = '0.1.0' def main(): # 执行项目管理初始化 action = FLAGS.action if action in ARG_DICT: print(ARG_DICT[action]) ARG_DICT[action](FLAGS.action_arg) PK!l<<dophon_manager/actions.pyimport os import toml import xml.etree.ElementTree as ET import time import subprocess from threading import Thread class ActionObj: def init_modulexml(self, modules_list: list, project_name: str): # 创建根节点(dophon) a = ET.Element("dophon") # 创建子节点,并添加属性 b = ET.SubElement(a, "modules") for m in modules_list: # 创建对应模块节点 c = ET.SubElement(b, 'module') d = ET.SubElement(c, 'pre-name') d.text = 'dophon' e = ET.SubElement(c, 'name') e.text = m # 创建模块文件 tree = ET.ElementTree(a) tree.write(os.sep.join([os.getcwd(), project_name, "module.xml"])) def new_action( self, project_name: str ): # 利用poetry创建项目 print('create new project,name:', project_name) project_path = os.getcwd() + os.sep + project_name # 判断项目是否存在 if os.path.exists(project_path): print('===== warning !! project(' + project_name + ') exists! =====') return os.system('poetry new %s' % (project_name,)) while True: if not os.path.exists(project_path): # 未创建项目,则等待 time.sleep(1) # 询问必要参数 entity_point = input('project boot file (default:dophon_project):\n') entity_point = entity_point if entity_point else 'Bootstrap:run' toml_file_path = os.sep.join([os.getcwd(), project_name, 'pyproject.toml']) # 读取项目toml文件 toml_file = toml.load(open(toml_file_path)) # 组装项目入口信息 toml_file['tool']['poetry']['scripts'] = {project_name: entity_point} toml_file['tool']['poetry']['dependencies']['dophon'] = '*' print('======project name : ' + project_name + '======') # 询问是否添加其他模块 add_modules = input('add others modules?\n(db/mq)\ncan add multi,please sep with ,\n').strip() if add_modules: # 添加其余模块 modules_list = add_modules.split(',') for m in modules_list: print('======add dophon module : dophon-' + m + '======') toml_file['tool']['poetry']['dependencies']['dophon-' + m] = '*' # 询问是否初始化模块文件 init_module_file_flag = input('want to init module.xml?(default:False)\n(True/False)\n') init_module_file_flag = bool(init_module_file_flag) \ if init_module_file_flag \ else False if init_module_file_flag: print('======init module.xml======') # 初始化模块文件 self.init_modulexml(modules_list, project_name) # 保存toml文件信息 with open(toml_file_path, 'w') as final_toml: print('======writing pyproject.toml======') final_toml.write(toml.dumps(toml_file)) self.project_install(project_path) break def project_install(self, project_path): print('======initialing project======') install_process = subprocess.Popen('poetry install', cwd=project_path, shell=True, stdout=subprocess.PIPE, universal_newlines=True) install_process.wait() Thread(target=self.listen_popen, args=(install_process,)).start() def listen_popen(self, popen): before_lines = [] while int(popen.poll()) != 0: result_lines = popen.stdout.readlines() # 从子进程 p 的标准输出中读取所有行,并储存在一个list对象中 # 对比前后行数 for line in result_lines: if line not in before_lines: print(line.strip()) before_lines.append(line) PK!H,},6/dophon_manager-0.1.1.dist-info/entry_points.txtN+I/N.,()J/ϋMKLO-EZ&fqqPK!H9VWX$dophon_manager-0.1.1.dist-info/WHEEL A н#f."jm)!fb҅~ܴA,mTD}E n0H饹*|D[¬c i=0(q3PK!H;Џ'dophon_manager-0.1.1.dist-info/METADATAj1 E M'I*%-:k(3˚ׅRr2^1>SLNԀL2O4c#LWcax¤X8 zwO%O-ޚ@e*n4a󘒻9{1" #Rw^hͦXfl<6fc>諸HI?-daPK!H5%dophon_manager-0.1.1.dist-info/RECORDr0B ."DA@K$׍3m7I:(. %YL0.h1׃r"wөҷV,mݬr{h1@T{ƽ`YZ"9XnQ0Jakqva|_g>Ă4"g%㠠jR ٘IlJ=C^;t:]:%]%qU%ژ-Z [n@:'WEp` vP3P{R '1`lE1)CwxbIg+70PK!%%dophon_manager/__init__.pyPK!l<<]dophon_manager/actions.pyPK!H,},6/dophon_manager-0.1.1.dist-info/entry_points.txtPK!H9VWX$Idophon_manager-0.1.1.dist-info/WHEELPK!H;Џ'dophon_manager-0.1.1.dist-info/METADATAPK!H5%dophon_manager-0.1.1.dist-info/RECORDPK_