7
7
import base64
8
8
import os
9
9
10
- DEFAULT_TEMP_FILE_LOCATION = "./temp/"
11
10
12
11
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 ):
14
13
"""
15
14
16
15
: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)
20
19
21
20
progress ("extracting json from .vex tar file" )
22
21
dot_vex_file = tarfile .open (vex_file_location )
23
- dot_vex_file .extractall (DEFAULT_TEMP_FILE_LOCATION )
22
+ dot_vex_file .extractall (temp_location )
24
23
dot_vex_file .close ()
25
24
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 :
27
26
dot_vex_json : dict = json .load (content )
28
27
if not os .path .isdir (save_folder_location ):
29
28
os .mkdir (save_folder_location )
30
29
progress ("extracting and decode files from json" )
31
30
for x in dot_vex_json ["files" ]:
32
31
with open (save_folder_location + "/" + x , "wb" ) as file :
33
32
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" )
35
34
36
35
37
36
def update_dot_vex (vex_file_location : str ,
38
37
save_folder_location : str ,
39
38
save_file_name : str ,
40
39
vex_decode_folder_location : str ,
40
+ temp_location ,
41
41
progress = print
42
42
):
43
43
"""
@@ -51,31 +51,31 @@ def update_dot_vex(vex_file_location: str,
51
51
52
52
progress ("extracting json from .vex tar file" )
53
53
dot_vex_file = tarfile .open (vex_file_location )
54
- dot_vex_file .extractall (DEFAULT_TEMP_FILE_LOCATION )
54
+ dot_vex_file .extractall (temp_location )
55
55
dot_vex_file .close ()
56
56
if not os .path .isdir (save_folder_location ):
57
57
os .mkdir (save_folder_location )
58
58
progress ("loading json" )
59
- with open (DEFAULT_TEMP_FILE_LOCATION + "___ThIsisATemPoRaRyFiLE___.json" ) as content :
59
+ with open (temp_location + "/ ___ThIsisATemPoRaRyFiLE___.json" ) as content :
60
60
dot_vex_json : dict = json .load (content )
61
61
encode_files : list = os .listdir (vex_decode_folder_location )
62
62
progress ("replacing file inside json" )
63
63
for x in encode_files :
64
64
with open (vex_decode_folder_location + x , "rb" ) as file :
65
65
dot_vex_json ["files" ][x ] = base64 .b64encode (file .read ()).decode ("utf-8" )
66
66
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 :
69
69
json .dump (dot_vex_json , content )
70
70
try :
71
71
os .remove (save_folder_location + "/" + save_file_name )
72
72
except :
73
73
progress ("we don't need to remove the json file" )
74
74
dot_vex_save_file = tarfile .open (save_folder_location + "/" + save_file_name , "w" )
75
75
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" )
79
79
80
80
dot_vex_save_file .close ()
81
81
progress ("replace/update .vex file complete" )
0 commit comments