Created
November 29, 2019 06:32
-
-
Save tosmart01/a048fc56ff967f7e8a1f173a514f73b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import compileall,os,shutil | |
import re | |
replace='__pycache__' | |
# print(fa_list.__next__()) | |
# print(fa_list.__next__()) | |
def bulk_editing_files(fa_list): | |
''' | |
将备份后的编译文件处理 | |
:param 文件列表信息: | |
:return None: | |
''' | |
for j,k,l in fa_list: | |
if replace not in j: | |
if replace in k: | |
pycfile_list=os.listdir(os.path.join(j,'__pycache__')) | |
for i in pycfile_list: | |
pycfile_name=os.path.join(j,replace,i) | |
print(pycfile_name) | |
move_path=re.sub(r'(cpython-36.)|(cpython-35.)|(/__pycache__)|(\__pycache__)','',pycfile_name) | |
shutil.move(pycfile_name,move_path) | |
os.rmdir(os.path.join(j,replace)) | |
for i in l: | |
if i.endswith('.py'): | |
os.remove(os.path.join(j, i)) | |
if __name__ == '__main__': | |
path=os.path.dirname(os.path.abspath(__file__)) | |
for i in os.listdir(path): | |
dir_path=os.path.join(path,i) | |
print(dir_path) | |
work_file=os.path.isdir(dir_path) | |
if work_file: | |
#文件备份后名称 | |
new_dir_path=dir_path+'_new' | |
#备份文件 | |
shutil.copytree(dir_path,new_dir_path) | |
compileall.compile_dir(new_dir_path) | |
fa_list=os.walk(new_dir_path) | |
bulk_editing_files(fa_list) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment