예제 #1
0
파일: client.py 프로젝트: RyanJenkins/YASA
    def __init__(self, s, db_conn=None):
        self._socket = s
        self._responses = parse.recv_load(self._socket)

        if db_conn:
            self._conn = db_conn
        else:
            self._conn = utils.get_client_connection('yasaclient.db')
예제 #2
0
파일: watcher.py 프로젝트: RyanJenkins/YASA
def reconcile(path, conn):
    """
    Given a path and a connection to a DB, alter the DB to reflect the present
    structure of the directory.
    """
    cursor = conn.cursor()
    added, removed = scan(path, conn)

    for path in added:
        logging.info("Adding file: %s" % path)
        utils.arrow(path,
                    (utils.generate_file_info),
                    (utils.insert_file_record, conn))

    for record in removed:
        logging.info("Recording as gone: %s" % path)
        cursor.execute(('INSERT INTO deleted (del_time, server_id, path) '
                        'VALUES (?, ?, ?)'),
                       [time.time(), record['server_id'], record['path']])
        cursor.execute('DELETE FROM files WHERE id=?', [record['id']])

    conn.commit()
    cursor.close()

if __name__ == '__main__':
    conn = utils.get_client_connection('yasaclient.db')
    lib_dir = utils.read_settings(conn, 'lib_dir').get('lib_dir')

    reconcile(lib_dir, conn)