Esempio n. 1
0
def path_by_digest(digest):
    conn = connection()
    cursor = conn.cursor()
    query = 'SELECT name, path FROM entries WHERE digest = ?'
    cursor.execute(query, (digest, ))
    result = cursor.fetchone()
    if not result:
        raise Exception('digest %s not found in database' % digest)
    return result['name'], result['path']
Esempio n. 2
0
def get_version(path, name):
    conn = connection()
    cursor = conn.cursor()
    query = 'SELECT version FROM modifications WHERE path = ? AND name = ?'
    cursor.execute(query, (path, name))
    result = cursor.fetchone()
    if not result:
        return None
    return result['version']
Esempio n. 3
0
def add_dir(directory):
    conn = connection()
    query = 'DELETE FROM entries WHERE path = ?'
    conn.execute(query, (str(directory), ))
    for entry in directory.entries.values():
        check_conflict(conn, entry.digest, entry.name, entry.directory.path,
                       False)
        query = 'INSERT OR REPLACE INTO entries(digest, name, path, trash)' \
                'VALUES ( ?, ?, ?, ? )'
        conn.execute(query,
                     (entry.digest, entry.name, entry.directory.path, False))
    conn.commit()
Esempio n. 4
0
def load(filter_dir=None, trash=False):
    conn = connection()
    cursor = conn.cursor()
    query = 'SELECT * FROM entries WHERE trash = ? AND path != ?'
    cursor.execute(query, (trash, str(filter_dir)))
    return cursor.fetchall()
Esempio n. 5
0
def set_version(path, name, version):
    conn = connection()
    query = 'INSERT OR REPLACE INTO modifications(path, name, version) VALUES ( ?, ?, ? )'
    conn.execute(query, (path, name, version))
    conn.commit()
Esempio n. 6
0
def add_trash(digest, name, directory):
    conn = connection()
    check_conflict(conn, digest, name, directory, True)
    query = 'INSERT OR REPLACE INTO entries(digest, name, path, trash) VALUES ( ?, ?, ?, ? )'
    conn.execute(query, (digest, name, directory, True))
    conn.commit()