22from model .EncryptTools import *
33from config import defaults as DEF
44ZIP_PASS = DEF .ZIP_PASS
5+
56import os
67class Ziputil ():
78 def __init__ (self , ziptoolpath :str , zipfilepath :str ):
@@ -22,7 +23,7 @@ def genzipfile(self,folder_path:str):
2223 return code
2324
2425
25- def load_serval (str_serval :str ):
26+ def load_serval (str_serval :str ): #load a serval file
2627 lines = str_serval .split ('\n ' )
2728 serval_dict = {}
2829 for line in lines :
@@ -33,7 +34,7 @@ def load_serval(str_serval:str):
3334 continue
3435 line_split = line .split (':' )
3536 line_path_full = ':' .join ([line_split [0 ],line_split [1 ]])
36- print (line_path_full )
37+ print ("load:" , line_path_full )
3738 line_path_full_split = line_path_full .split ('/' )
3839 path_folder = '/' .join (line_path_full_split [:- 1 ])
3940 file_name = line_path_full_split [- 1 :][0 ]
@@ -43,7 +44,27 @@ def load_serval(str_serval:str):
4344 return serval_dict
4445def get_path_folder (path ):
4546 path_folder = '_' .join (path .split ('/' ))
46- return path_folder .replace (':' ,'' )
47+ return path_folder .replace (':' ,'' ).replace (' ' ,'-' )
48+ def split_serval (serval_dict :dict ):
49+ filename_dic = {}
50+ for key in serval_dict .keys ():
51+ if key != 'label_line' :
52+ path = serval_dict [key ]['path' ]
53+ anno = serval_dict [key ]['anno' ]
54+ str_line = key + ':' + anno
55+ path_filename = get_path_folder (path )
56+ if path_filename not in filename_dic .keys ():
57+ filename_dic [path_filename ]= []
58+ filename_dic [path_filename ].append (str_line )
59+ filename_serval_dic = {}
60+ for key in filename_dic .keys ():
61+ list_to_write = filename_dic [key ]
62+ serval_new = '\n ' .join (list_to_write )
63+ serval_new += '\n '
64+ serval_new_header = addHeader (serval_new )
65+ filename_serval_dic [key ]= serval_new_header
66+ return filename_serval_dic
67+
4768def regenerate_serval (serval_dict :dict ):
4869 list_to_write = []
4970 list_to_write .append (serval_dict ['label_line' ])
@@ -81,21 +102,29 @@ def write_folder_from_dict(path:str, serval_dict:dict):
81102
82103
83104if __name__ == "__main__" :
84- with open ('zip.serval' ,encoding = 'utf-8' ) as f :
105+ import os
106+ print (os .getcwd ())
107+ with open ('zip_decryped_demo.serval' ,encoding = 'utf-8' ) as f :
85108 str_serval = f .read ()
86109 #with open('decrypt.serval','w',encoding='utf-8') as f_write:
87110 # f_write.write(decrypt(ENCRYPT_KEY,str_serval))
88- serval_dict = load_serval (decrypt (DEF .ENCRYPT_KEY ,str_serval ))
111+ serval_dict = load_serval (str_serval )
112+ split_dict = split_serval (serval_dict )
113+
114+ for key in split_dict .keys ():
115+ print (key )
116+ print (split_dict [key ])
117+
89118 #print(serval_dict)
90119 #print(serval_dict['label_line'])
91- import os
92- ls = write_folder_from_dict (os .getcwd (), serval_dict )
93- print (ls )
94120 #import os
95- os .chdir ('../' )
96- print (os .getcwd ())
121+ #ls=write_folder_from_dict(os.getcwd(), serval_dict)
122+ #print(ls)
123+ #import os
124+ #os.chdir('../')
125+ #print(os.getcwd())
97126
98- ZP = Ziputil (os .getcwd ()+ '\\ 7zfiles\\ 7z.exe' ,os .getcwd ()+ '\\ zipdemo.7z' )
99- code = ZP .genzipfile ('"' + os .getcwd ()+ '\\ writing_path"' )
100- print (code )
127+ # ZP=Ziputil(os.getcwd()+'\\7zfiles\\7z.exe',os.getcwd()+'\\zipdemo.7z')
128+ # code=ZP.genzipfile('"'+os.getcwd()+'\\writing_path"')
129+ # print(code)
101130
0 commit comments