示例#1
0
文件: init.py 项目: juliendz/imagius
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()
示例#2
0
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()
示例#3
0
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()
示例#4
0
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
示例#5
0
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()
示例#6
0
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
示例#7
0
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
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
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()