def move_path(src, dst): now = datetime.datetime.now() src = convert_many(src) dst = convert_many(dst) assert len(src) == len(dst) data = [(x, now, y) for ((x, ), (y, )) in zip(dst, src)] con = sqlite3.connect(METADATAFILE, detect_types=sqlite3.PARSE_DECLTYPES) with con: cur = con.cursor() cur.executemany("UPDATE metadata SET path = ?, modified = ? WHERE path = ?", data)
def delete_path(path): path = convert_many(path) delsql = 'DELETE FROM metadata WHERE path = ?' con = sqlite3.connect(METADATAFILE, detect_types=sqlite3.PARSE_DECLTYPES) with con: cur = con.cursor() cur.executemany(delsql, path)
def delete_user(user): user = convert_many(user) delsql = 'DELETE FROM userdata WHERE username = ?' con = sqlite3.connect(USERDATAFILE, detect_types=sqlite3.PARSE_DECLTYPES) with con: cur = con.cursor() cur.executemany(delsql, user)
def copy_path(src, dst): now = datetime.datetime.now() src = convert_many(src) dst = convert_many(dst) assert len(src) == len(dst) selsql = 'SELECT owner,permission FROM metadata WHERE path = ?' addsql = 'INSERT INTO metadata VALUES (?, ?, ?, ?, ?, ?)' con = sqlite3.connect(METADATAFILE, detect_types=sqlite3.PARSE_DECLTYPES) with con: cur = con.cursor() temp = [] for x in src: cur.execute(selsql, x) temp.append(cur.fetchone()) # fix for ignored files zipped = ((x, y) for (x, y) in zip(dst, temp) if y is not None) data = [(path, owner, perm, now, now, now) for ((path, ), (owner, perm)) in zipped] cur.executemany(addsql, data)
def add_path(path, owner, permission): now = datetime.datetime.now() validate_permission(permission) validate_owner(owner) data = convert_many(path, owner, permission, now, now, now) addsql = 'INSERT INTO metadata VALUES (?, ?, ?, ?, ?, ?)' con = sqlite3.connect(METADATAFILE, detect_types=sqlite3.PARSE_DECLTYPES) with con: cur = con.cursor() cur.executemany(addsql, data)