def init_app_db(): from imagius.db import dbmgr settings_db_file = QtCore.QFileInfo( "%s/%s/%s" % (USER_APPDATA_DIR, APP_NAME, DB_SETTINGS)) if not settings_db_file.exists(): db = dbmgr(settings_db_file.absoluteFilePath()) db.create_settings_db_from_schema() # Add the current version info db = dbmgr(settings_db_file.absoluteFilePath()) db.connect() query = 'INSERT INTO settings (key, value) VALUES (?, ?)' params = ('VERSION', APP_VERSION) db.run_insert_query(query, params) db.disconnect() meta_db_file = QtCore.QFileInfo( "%s/%s/%s" % (USER_APPDATA_DIR, APP_NAME, DB_META)) if not meta_db_file.exists(): db = dbmgr(meta_db_file.absoluteFilePath()) db.create_meta_db_from_schema()
def init_settings_db(): from imagius.db import dbmgr p = Path(settings_db_path()) if not p.exists(): db = dbmgr(p) db.create_settings_db_from_schema() # Add the current version info db.connect() query = 'INSERT INTO settings (key, value) VALUES (?, ?)' params = ('VERSION', APP_VERSION) db.run_insert_query(query, params) db.disconnect()
def persist_to_disk(): db = dbmgr(settings_db_path()) db.connect() print(SETTINGS) select_query = 'SELECT key FROM settings WHERE key = ?' update_query = 'UPDATE settings set value = ? WHERE key = ?' insert_query = 'INSERT INTO settings (key, value) VALUES (?, ?)' for key, value in SETTINGS.items(): res = db.run_select_query(select_query, (key, )) if len(res) > 0: db.run_query(update_query, (value, key)) else: db.run_insert_query(insert_query, (key, value)) db.disconnect()
def load_settings(): db = dbmgr(settings_db_path()) db.connect() query = 'SELECT * FROM settings' dr = db.run_select_query(query) db.disconnect() for row in dr: SETTINGS[row['key']] = row['value'] # If the version in the db is lesser than the in-code version, # that means a new version was installed. # So run any version specific upgrade code if Version(SETTINGS['VERSION']) < Version(APP_VERSION): upgrade_from_previous_versions(Version(SETTINGS['VERSION']), meta_db_path()) SETTINGS['VERSION'] = APP_VERSION
def persist_to_disk(): settings_db_file = QtCore.QFileInfo( "%s/%s/%s" % (USER_APPDATA_DIR, APP_NAME, DB_SETTINGS)) db = dbmgr(settings_db_file.absoluteFilePath()) db.connect() print(SETTINGS) select_query = 'SELECT key FROM settings WHERE key = ?' update_query = 'UPDATE settings set value = ? WHERE key = ?' insert_query = 'INSERT INTO settings (key, value) VALUES (?, ?)' for key, value in SETTINGS.items(): res = db.run_select_query(select_query, (key,)) if len(res) > 0: db.run_query(update_query, (value, key)) else: db.run_insert_query(insert_query, (key, value)) db.disconnect()
def load_settings(): settings_db_file = QtCore.QFileInfo( "%s/%s/%s" % (USER_APPDATA_DIR, APP_NAME, DB_SETTINGS)) db = dbmgr(settings_db_file.absoluteFilePath()) db.connect() query = 'SELECT * FROM settings' dr = db.run_select_query(query) db.disconnect() for row in dr: SETTINGS[row['key']] = row['value'] # If the version in the db is lesser than the in-code version, # that means a new version was installed. # So run any version specific upgrade code if Version(SETTINGS['VERSION']) < Version(APP_VERSION): upgrade_from_previous_versions( Version(SETTINGS['VERSION']), get_meta_db_path()) SETTINGS['VERSION'] = APP_VERSION
def upgrade_from_previous_versions(cur_version, meta_db_path): meta_db = dbmgr(meta_db_path) meta_db.connect() # Upgrade code to Version(0.8.1) if cur_version < Version('0.8.1'): LOGGER.info('Upgrading from Version:%s to Version:%s' % (cur_version, '0.8.1')) queries = [ 'CREATE TEMPORARY TABLE scan_img_backup(a,b,c,d,e,f,g,h);', """INSERT INTO scan_img_backup SELECT id, abspath, name, thumb, sdid, mtime, integrity_check, serial FROM scan_img; """, 'DROP TABLE scan_img;', """CREATE TABLE IF NOT EXISTS "scan_img" ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `abspath` TEXT NOT NULL UNIQUE, `name` TEXT NOT NULL, `thumb` BLOB NOT NULL, `sdid` INTEGER NOT NULL DEFAULT 0, `mtime` INTEGER, `integrity_check` INTEGER, `serial` INTEGER, FOREIGN KEY(`sdid`) REFERENCES `scan_dir`(`id`) ON DELETE CASCADE ) """, 'INSERT INTO scan_img SELECT a,b,c,d,e,f,g,h FROM scan_img_backup;', 'DROP TABLE scan_img_backup;', ] for query in queries: meta_db.run_query(query) meta_db.commit() cur_version = Version('0.8.1') meta_db.disconnect() return
def __init__(self, meta_path=settings.get_meta_db_path(), settings_path=settings.get_settings_db_path()): self._meta_db = dbmgr(meta_path) self._settings_db = dbmgr(settings_path)
def __init__(self, dbpath=settings.get_settings_db_path(), meta_dbpath=settings.get_meta_db_path()): super(FolderManager, self).__init__() self._db = dbmgr(dbpath) self._meta_db = dbmgr(meta_dbpath)
def init_meta_db(): from imagius.db import dbmgr p = Path(meta_db_path()) if not p.exists(): db = dbmgr(p) db.create_meta_db_from_schema()