123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | #!/usr/bin/env python import sys import shutil import os class CpBasicModules(): def get_python_info(self): version = sys.version[:3] if len(sys.argv) == 1: print('default python version is {}'.format(version)) elif len(sys.argv) == 2: version = sys.argv[1].strip().strip('python') if version[0].isdigit() and version[1] == '.' and version[2].isdigit(): print('your python version is {}'.format(version)) else: print('input python version like 2.7 , 3.3, or else') exit(1) else: print("too many paras") exit(1) self.python_zip = 'python{}{}.zip'.format(version[0], version[2]) self.version = version def get_basic_modules(self): try: this_file = open('../bin/verbose.txt', 'r') except: print(''' make sure verbose.txt is in your bin folder, and this file is in code folder, and code folder is parallel with bin folder ''') exit(1) lines = this_file.readlines() this_file.close() basic_module = [] for line in lines: if '.pyc' not in line:continue parts = line.split(self.python_zip) pyc_name = parts[-1].lstrip('/').rstrip('\n') basic_module.append(pyc_name) self.basic_modules = basic_module def init_target_folder(self): target_folder = os.path.join(os.getcwd(), '../lib/python{}.min'.format(self.version)) if os.path.exists(target_folder): shutil.rmtree(target_folder) os.mkdir(target_folder) self.target_folder = target_folder def cp_files(self): sh_name = 'get_python_min_lib.sh' sh_file_path = os.path.join(os.getcwd(), sh_name) src_folder = os.path.join(os.getcwd(), '../lib/python{}.bak'.format(self.version)) with open(sh_file_path, 'w') as sh_file: str = 'cd {}'.format(src_folder) str += ' && ' str += 'cp --parents '+' '.join(self.basic_modules)+' '+self.target_folder sh_file.write(str) os.system('chmod +x {}'.format(sh_file_path)) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |