-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_paths.py
63 lines (49 loc) · 2.02 KB
/
validate_paths.py
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
import os
import json
def validate_nothing(path, value):
pass
def validate_not_empty_path(path, value):
if value == "":
return "[ERROR] '" + path + "' cannot be empty"
def validate_standard_folder_path(path, value):
if value == "":
return "[ERROR] '" + path + "' cannot be empty"
elif not os.path.exists(value):
return "[ERROR] '" + path + "' does not exist"
elif not os.path.isdir(value):
return "[ERROR] '" + path + "' is not a folder"
def validate_standard_file_path(path, value):
if value == "":
return "[ERROR] '" + path + "' cannot be empty"
elif not os.path.exists(value):
return "[ERROR] '" + path + "' does not exist"
elif not os.path.isfile(value):
return "[ERROR] '" + path + "' is not a file"
def validate_locres_file_path(path, value):
if value == "":
return "[ERROR] '" + path + "' cannot be empty"
elif not os.path.exists(value):
return "[ERROR] '" + path + "' does not exist"
elif not os.path.isfile(value):
return "[ERROR] '" + path + "' is not a file"
else:
try:
with open(value, "rt", encoding="utf-8") as json_file:
json.load(json_file)
except ValueError:
return "[ERROR] Error found while opening '" + path + "'"
validator_hub = {"valorant_path": validate_standard_folder_path,
"umodel_path": validate_standard_file_path,
"aes_path": validate_standard_file_path,
"locres_path": validate_not_empty_path,
"extract_path": validate_not_empty_path,
"target_path": validate_not_empty_path}
def validate_paths_json(paths_dict):
for path, value in paths_dict.items():
validate_function = validator_hub.get(path, None)
if validate_function:
validate_result = validate_function(path, value)
if validate_result:
return validate_result
else:
print("[WARN] '" + path + "' is not an expected path")