2020-04-25 12:28:57 +08:00
|
|
|
import CustomConfig
|
2020-04-05 22:34:11 +08:00
|
|
|
import DecoratorCore
|
2020-04-09 11:21:52 +08:00
|
|
|
import ServerCore
|
2020-04-05 22:34:11 +08:00
|
|
|
import os
|
|
|
|
import sys
|
2020-04-25 12:28:57 +08:00
|
|
|
import getopt
|
2020-08-22 15:47:37 +08:00
|
|
|
import logging
|
2020-04-05 22:34:11 +08:00
|
|
|
|
2020-04-25 12:28:57 +08:00
|
|
|
try:
|
2020-08-22 15:47:37 +08:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "hi:o:e:c:fd")
|
2020-04-25 12:28:57 +08:00
|
|
|
except getopt.GetoptError:
|
|
|
|
print('Wrong arguments!')
|
2020-08-22 15:47:37 +08:00
|
|
|
print('python SuperScriptViewer.py -i <export.db> -o <decorated.db> -e <env.db> -c <codec_name> -f -d')
|
2020-04-25 12:28:57 +08:00
|
|
|
sys.exit(1)
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == '-h':
|
2020-08-22 15:47:37 +08:00
|
|
|
print('python SuperScriptViewer.py -i <export.db> -o <decorated.db> -e <env.db> -c <codec_name> -f -d')
|
2020-04-25 12:28:57 +08:00
|
|
|
sys.exit(0)
|
|
|
|
elif opt == '-i':
|
|
|
|
CustomConfig.export_db = arg
|
|
|
|
elif opt == '-o':
|
|
|
|
CustomConfig.decorated_db = arg
|
|
|
|
elif opt == '-e':
|
|
|
|
CustomConfig.env_db = arg
|
2020-08-12 15:07:41 +08:00
|
|
|
elif opt == '-c':
|
|
|
|
CustomConfig.database_encoding = arg
|
2020-04-25 12:28:57 +08:00
|
|
|
elif opt == '-f':
|
|
|
|
CustomConfig.force_regenerate = True
|
2020-08-22 15:47:37 +08:00
|
|
|
elif opt == '-d':
|
|
|
|
CustomConfig.debug_mode = True
|
2020-04-25 12:28:57 +08:00
|
|
|
|
2020-08-22 15:47:37 +08:00
|
|
|
print('Super Script View')
|
|
|
|
print('Homepage: https://github.com/yyc12345/SuperScriptMaterializer')
|
|
|
|
print('Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues')
|
|
|
|
print('')
|
2020-04-25 12:28:57 +08:00
|
|
|
# process -f
|
|
|
|
if (CustomConfig.force_regenerate):
|
|
|
|
if os.path.isfile(CustomConfig.decorated_db):
|
|
|
|
os.remove(CustomConfig.decorated_db)
|
2020-04-05 22:34:11 +08:00
|
|
|
|
2020-04-25 12:28:57 +08:00
|
|
|
if not os.path.isfile(CustomConfig.env_db):
|
|
|
|
print('No environment database. Fail to generate. Exit app.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not os.path.isfile(CustomConfig.decorated_db):
|
2020-04-05 22:34:11 +08:00
|
|
|
print('No decorated database, generating it.')
|
2020-04-25 12:28:57 +08:00
|
|
|
if not os.path.isfile(CustomConfig.export_db):
|
2020-04-05 22:34:11 +08:00
|
|
|
print('No export.db. Fail to generate. Exit app.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# generate db
|
2020-08-22 15:47:37 +08:00
|
|
|
if CustomConfig.debug_mode:
|
|
|
|
DecoratorCore.run()
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
DecoratorCore.run()
|
|
|
|
except Exception as ex:
|
|
|
|
print("!!! An error occurs. Please report follwoing error output and reproduce file to developer. !!!")
|
|
|
|
logging.exception(ex)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-04-05 22:34:11 +08:00
|
|
|
print('Decorated database generating done.')
|
|
|
|
|
|
|
|
# todo: start flask
|
2020-04-11 22:51:03 +08:00
|
|
|
ServerCore.run()
|