-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
66 lines (56 loc) · 2.18 KB
/
script.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
64
65
66
import sys
import traceback
try:
with open('traceback.log', 'w') as f:
pass
from util.config import Config
from util.logger import logger
from util.file_manager import FileManager
from modules.install_chara import InstallChara
from modules.remove_chara import RemoveChara
from modules.fc_kks import FilterConvertKKS
from modules.create_backup import CreateBackup
class Script:
def __init__(self, config, file_manager):
"""Initializes the primary azurlane-auto instance with the passed in
Config instance;
Args:
config (Config): BAAuto Config instance
"""
self.config = config
self.file_manager = file_manager
self.task_to_module = {
'CreateBackup': CreateBackup,
'FilterConvertKKS': FilterConvertKKS,
'InstallChara': InstallChara,
'RemoveChara': RemoveChara,
}
def run(self):
for task, module in self.task_to_module.items():
if not self.config.config_data[task]["Enable"]:
continue
logger.info("SCRIPT", f'Start Task: {task}')
try:
module(self.config, self.file_manager).run()
except:
logger.error("SCRIPT", f'Task error: {task}. For more info, check the traceback.log file.')
self.write_traceback(task)
sys.exit(1)
sys.exit(0)
def write_traceback(self, task):
with open('traceback.log', 'a') as f:
f.write(f'[{task}]\n')
traceback.print_exc(None, f, True)
f.write('\n')
except:
print(f'[ERROR] Script Initialisation Error. For more info, check the traceback.log file.')
with open('traceback.log', 'w') as f:
f.write(f'Script Initialisation Error\n')
traceback.print_exc(None, f, True)
f.write('\n')
sys.exit(1)
if __name__ == "__main__":
config = Config('app/config/config.json')
file_manager = FileManager(config)
script = Script(config, file_manager)
script.run()