SuperScriptMaterializer/SuperScriptDecorator/SuperScriptDecorator.py

52 lines
1.5 KiB
Python
Raw Normal View History

2023-02-19 21:59:05 +08:00
import CustomConfig, DecoratorCore, Progressbar
import os, sys, getopt, logging, time
2023-02-19 21:59:05 +08:00
# print banner
print('Super Script Decorator')
print('Homepage: https://github.com/yyc12345/SuperScriptMaterializer')
print('Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues')
print('')
# try get args
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:e:c:fd")
except getopt.GetoptError:
print('Wrong arguments!')
print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d')
sys.exit(1)
2023-02-19 21:59:05 +08:00
# analyze args
cfg: CustomConfig.CustomConfig = CustomConfig.CustomConfig()
for opt, arg in opts:
if opt == '-h':
print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d')
sys.exit(0)
elif opt == '-i':
2023-02-19 21:59:05 +08:00
cfg.m_ImportTxt = arg
elif opt == '-o':
2023-02-19 21:59:05 +08:00
cfg.m_DecoratedDb = arg
elif opt == '-c':
2023-02-19 21:59:05 +08:00
cfg.m_DatabaseEncoding = arg
elif opt == '-d':
2023-02-19 21:59:05 +08:00
cfg.m_DebugMode = True
2023-02-19 21:59:05 +08:00
# regulate data
if not cfg.Regulate():
# failed. exit program
sys.exit(1)
2023-02-19 21:59:05 +08:00
# if in debug mode, run directly
# otherwise, run with a try wrapper.
if cfg.m_DebugMode:
DecoratorCore.run(cfg)
else:
try:
2023-02-19 21:59:05 +08:00
DecoratorCore.run(cfg)
except Exception as ex:
print("!!! An error occurs. Please report follwoing error output and reproduce file to developer. !!!")
logging.exception(ex)
sys.exit(1)
2023-02-19 21:59:05 +08:00
print('Decorated database generation done.')