This repository was archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvex_convert.py
More file actions
98 lines (81 loc) · 3.38 KB
/
vex_convert.py
File metadata and controls
98 lines (81 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# coding=utf-8
"""
I have nothing to say, it is a very simple program works
"""
import json
import tarfile
import base64
import os
def extract_vex(vex_file_location: str, temp_location: str, progress):
"""
:param vex_file_location: the .vex file location, should include the .vex file
:param temp_location: the temp folder location
:param progress: optional way to output the progress
"""
if not os.path.isdir(temp_location):
os.mkdir(temp_location)
progress("extracting json from .vex tar file")
with tarfile.open(vex_file_location) as vex_file:
vex_file.extractall(temp_location)
progress("json extracted")
def pack_vex(save_folder_location: str, save_file_name: str, temp_location: str, progress):
"""
:param save_folder_location: the .vex file location, should include the .vex file
:param save_file_name: the .vex file name
:param temp_location: the temp folder location
:param progress: optional way to output the progress
"""
try:
os.remove(save_folder_location + "/" + save_file_name)
except:
progress("Not a replace or it is a error")
progress("pack json into .vex")
with tarfile.open(save_folder_location + "/" + save_file_name, "w") as vex_file:
vex_file.add(
temp_location +
"/___ThIsisATemPoRaRyFiLE___.json",
"/___ThIsisATemPoRaRyFiLE___.json")
progress("packing done!")
def decode_json(code_folder_location: str, temp_location: str, progress):
"""
:param code_folder_location: should be a folder dedicated for code files
:param temp_location: the temp folder for .json
:param progress: the output for progress, on console it should be "print"
"""
progress("loading json")
with open(temp_location + "/___ThIsisATemPoRaRyFiLE___.json") as content:
dot_vex_json: dict = json.load(content)
progress("extracting and decode files from json")
for x in dot_vex_json["files"]:
with open(code_folder_location + "/" + x, "wb") as file:
file.write(base64.b64decode(dot_vex_json["files"][x]))
progress(str(len(dot_vex_json["files"])) + "Files extracted")
def update_json(code_folder: str, temp_location: str, progress):
"""
:param code_folder: the files you want to put into the .vex
:param temp_location: the folder containing ___ThIsisATemPoRaRyFiLE___.json
:param progress: optional way to output the progress
"""
progress("loading json")
with open(temp_location + "/___ThIsisATemPoRaRyFiLE___.json") as content:
dot_vex_json: dict = json.load(content)
encode_files: list = os.listdir(code_folder)
progress("replacing file inside json")
for x in encode_files:
with open(code_folder + "/" + x, "rb") as file:
dot_vex_json["files"][x] = base64.b64encode(file.read()).decode("utf-8")
progress("replace the json file")
try:
os.remove(temp_location + "/___ThIsisATemPoRaRyFiLE___.json")
except:
progress("failed to remove old json file")
with open(temp_location + "/___ThIsisATemPoRaRyFiLE___.json", "w") as content:
json.dump(dot_vex_json, content)
progress("replace/update json complete")
def main():
"""
I have no idea why someone try to run this and say it is not working....
"""
print("IT IS NOT WORKING")
if __name__ == '__main__':
main()