77import base64
88import os
99
10- DEFAULT_TEMP_FILE_LOCATION = "./temp/"
1110
1211
13- def extract_dot_vex (vex_file_location : str , save_folder_location : str , progress ):
12+ def extract_dot_vex (vex_file_location : str , save_folder_location : str ,temp_location , progress ):
1413 """
1514
1615 :param vex_file_location: the .vex file location, should include the .vex file
@@ -20,24 +19,25 @@ def extract_dot_vex(vex_file_location: str, save_folder_location: str, progress)
2019
2120 progress ("extracting json from .vex tar file" )
2221 dot_vex_file = tarfile .open (vex_file_location )
23- dot_vex_file .extractall (DEFAULT_TEMP_FILE_LOCATION )
22+ dot_vex_file .extractall (temp_location )
2423 dot_vex_file .close ()
2524 progress ("file extracted, loading json" )
26- with open (DEFAULT_TEMP_FILE_LOCATION + "___ThIsisATemPoRaRyFiLE___.json" ) as content :
25+ with open (temp_location + "/ ___ThIsisATemPoRaRyFiLE___.json" ) as content :
2726 dot_vex_json : dict = json .load (content )
2827 if not os .path .isdir (save_folder_location ):
2928 os .mkdir (save_folder_location )
3029 progress ("extracting and decode files from json" )
3130 for x in dot_vex_json ["files" ]:
3231 with open (save_folder_location + "/" + x , "wb" ) as file :
3332 file .write (base64 .b64decode (dot_vex_json ["files" ][x ]))
34- progress (len (dot_vex_json ["files" ]), "Files extracted from .vex" )
33+ progress (str ( len (dot_vex_json ["files" ])) + "Files extracted from .vex" )
3534
3635
3736def update_dot_vex (vex_file_location : str ,
3837 save_folder_location : str ,
3938 save_file_name : str ,
4039 vex_decode_folder_location : str ,
40+ temp_location ,
4141 progress = print
4242 ):
4343 """
@@ -51,31 +51,31 @@ def update_dot_vex(vex_file_location: str,
5151
5252 progress ("extracting json from .vex tar file" )
5353 dot_vex_file = tarfile .open (vex_file_location )
54- dot_vex_file .extractall (DEFAULT_TEMP_FILE_LOCATION )
54+ dot_vex_file .extractall (temp_location )
5555 dot_vex_file .close ()
5656 if not os .path .isdir (save_folder_location ):
5757 os .mkdir (save_folder_location )
5858 progress ("loading json" )
59- with open (DEFAULT_TEMP_FILE_LOCATION + "___ThIsisATemPoRaRyFiLE___.json" ) as content :
59+ with open (temp_location + "/ ___ThIsisATemPoRaRyFiLE___.json" ) as content :
6060 dot_vex_json : dict = json .load (content )
6161 encode_files : list = os .listdir (vex_decode_folder_location )
6262 progress ("replacing file inside json" )
6363 for x in encode_files :
6464 with open (vex_decode_folder_location + x , "rb" ) as file :
6565 dot_vex_json ["files" ][x ] = base64 .b64encode (file .read ()).decode ("utf-8" )
6666 progress ("replace the json file" )
67- os .remove (DEFAULT_TEMP_FILE_LOCATION + "___ThIsisATemPoRaRyFiLE___.json" )
68- with open (DEFAULT_TEMP_FILE_LOCATION + "___ThIsisATemPoRaRyFiLE___.json" , "w" ) as content :
67+ os .remove (temp_location + "/ ___ThIsisATemPoRaRyFiLE___.json" )
68+ with open (temp_location + "/ ___ThIsisATemPoRaRyFiLE___.json" , "w" ) as content :
6969 json .dump (dot_vex_json , content )
7070 try :
7171 os .remove (save_folder_location + "/" + save_file_name )
7272 except :
7373 progress ("we don't need to remove the json file" )
7474 dot_vex_save_file = tarfile .open (save_folder_location + "/" + save_file_name , "w" )
7575 dot_vex_save_file .add (
76- DEFAULT_TEMP_FILE_LOCATION +
77- "___ThIsisATemPoRaRyFiLE___.json" ,
78- "___ThIsisATemPoRaRyFiLE___.json" )
76+ temp_location +
77+ "/ ___ThIsisATemPoRaRyFiLE___.json" ,
78+ "/ ___ThIsisATemPoRaRyFiLE___.json" )
7979
8080 dot_vex_save_file .close ()
8181 progress ("replace/update .vex file complete" )
0 commit comments