Beispiel #1
0
def init_log(level=logging.DEBUG):
    """Start logger.

    Throw a FileNotFoundException if pushsync directory is not initialized."""
    logger = logging.getLogger()
    logger.removeHandler(logger.handlers[0])
    handler = logging.FileHandler(gnc.touch('debug.log'), encoding='utf-8', delay=True)
    formatter = logging.Formatter('>>> %(asctime)s.%(msecs)03d %(levelname)-8s %(message)s', datefmt="%Y-%m-%d %H:%M:%S")
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(level)
Beispiel #2
0
def pushsync_init(opts, args):
    """Create the .pushsync directory in %APPDATA% and populate it with operation files."""

    try:
        psy_path = gnc.pushsync_init()
        
        # Create dirs and files.

        gnc.mkdir('indexes')
        gnc.mkdir('indexes/local')
        gnc.mkdir('indexes/remote')
        gnc.mkdir('mappings')
        gnc.mkdir('remotes')    
        gnc.mkdir('cwd')
        gnc.mkdir('cwd/local')
        gnc.mkdir('cwd/remote')

        gnc.touch('.psyignore')            # TODO: w or a?
        gnc.touch('.psyrc') 
        gnc.touch('config')
        gnc.touch('history')
        gnc.touch('map_head')
        gnc.touch('cwd/local/local')

        # Initialize

        global config
        access_resources('config')
        write_config('config', config)

        gnc.write("*.tmp\n" + "~$*.doc\n" + "Thumbs.db\n", 'a', '.psyignore')        
        gnc.write("app_key = []\n" + "app_secret = []\n" + "access_token = []\n", 'a', 'remotes/dropbox')
        gnc.write("master\n", 'a', 'map_head')        

        # Initialize SQL stuff

        gnc.access_db('indexes/local/lindex.db')
        dbindex = gnc.db['indexes/local/lindex.db']
        curin = dbindex.cursor()
        curin.execute('''CREATE TABLE inodes
            (
                path TEXT NOT NULL PRIMARY KEY,
                head_id INTEGER NOT NULL,
                refcount INTEGER NOT NULL,
                FOREIGN KEY (head_id) REFERENCES revs (rev_id)
            )''')
        curin.execute('''CREATE TABLE revs
            (
                rev_id INTEGER PRIMARY KEY,
                parent_id INTEGER,
                mtime TEXT,
                size INTEGER,
                refcount INTEGER NOT NULL,
                misc TEXT
            )''')
        dbindex.commit()
        gnc.release_db('indexes/local/lindex.db')

        gnc.access_db('mappings/master.db')
        dbmapping = gnc.db['mappings/master.db']
        curma = dbmapping.cursor()
        curma.execute('''CREATE TABLE mapping
            (
                lpath TEXT NOT NULL,
                rpath TEXT NOT NULL
            )''')
        curma.execute('''CREATE TABLE domains
            (
                local TEXT,
                remote TEXT
            )''')
        curma.execute('''CREATE TABLE syncs
            (
                local_rev INTEGER NOT NULL,
                remote_rev INTEGER NOT NULL
            )''')
        curma.execute('''CREATE INDEX lpath ON mapping(lpath)''')
        curma.execute('''CREATE INDEX rpath ON mapping(rpath)''')
        curma.execute('''CREATE INDEX local_rev ON syncs(local_rev)''')
        curma.execute('''CREATE INDEX remote_rev ON syncs(remote_rev)''')
        curma.execute('''INSERT INTO domains(local, remote) VALUES (?, NULL)''', ('lindex',))

        dbmapping.commit()
        gnc.release_db('mappings/master.db')

        init()
    except (OSError, sqlite3.DatabaseError):
        return None

    return psy_path