def __init__(self, args): self.app = QApplication([]) self.debug = args['--debug'] signal(SIGINT, SIG_DFL) self.args = args # disable qt logging if not debug mode if not self.debug: os.system("export QT_LOGGING_RULES='*=false'") os.environ['QT_LOGGING_RULES'] = '*=false' # AppUtil.create_app_dir() AppUtil.create_default_config() self.check_db()
def createTablesDB(self): """ Creating or updating database tables. """ if AppUtil.isPyinstaller(): self.db.create_tables([Markets, Trades]) else: migrate(self.db) self.check_db()
def get_db(): db_file_path = AppUtil.get_db_file_path() db = SqliteDatabase( db_file_path, pragmas={ 'journal_mode': 'wal', 'cache_size': -1 * 64000, # 64MB 'foreign_keys': 1, 'ignore_check_constraints': 0, 'synchronous': 0 }) return db
def check_db(self): """ Main method to checks related with database. """ self.db.close() # delete database file if is required by user if self.args['--deletedb']: self.deleteDatabaseFile() # update db tables if is required by user if self.args['--updatedb']: self.createTablesDB() # check if db file exists if not AppUtil.existsFileDB(): self.createTablesDB() # check if all tables are created if not self.checkTablesExists(): self.createTablesDB()
def deleteDatabaseFile(self): if AppUtil.existsFileDB(): os.remove(AppUtil.get_db_file_path()) if not AppUtil.isPyinstaller(): shutil.rmtree('migrations', ignore_errors=True) sys.exit("Execute again")
def save_config(self): """ Save configuration changes in config file """ with open(AppUtil.get_config_file_path(), "w") as f: toml.dump(self.config, f)
def app_language(self): qtrans = QTranslator() qtrans.load(self.config['language'], AppUtil.get_i18n_dir()) return qtrans
def config(self): return toml.load(AppUtil.get_config_file_path())