Newer
Older
import database_create
from argparse import ArgumentParser
from PyQt5.QtCore import QTranslator
from globals import Global
script_path = os.path.dirname(os.path.abspath(__file__))
parser = ArgumentParser()
parser.add_argument(
'-d',
'--database',
default=script_path + '/database.db',
help='use specified file as database file, if not specified the default file (script_path/database.db} is used',
metavar='PATH'
)
parser.add_argument(
'-fc',
'--force-database-create',
action='store_true',
help='force creation of database - program then overwrites file specified in -d or the default one!'
)
args = parser.parse_args()
# clear and create database if -fc was given or create database if given file doesn't exist
if args.force_database_create is True or not os.path.isfile(args.database):
if os.path.isfile(args.database):
overwrite = input("Are you sure, you want to overwrite file '" + args.database + "'?[Y/N]\n")
if overwrite != 'Y':
exit()
os.remove(args.database)
database_create.create_db(args.database)
try:
Global.db = Database(args.database)
except (sqlite3.DatabaseError, sqlite3.OperationalError) as e:
print('The specified database file is invalid.\nTry rerunning with -fc?')
exit()
translator = QTranslator()
translator.load(script_path + "translations/czech.qm")
app.installTranslator(translator)