Exemplo n.º 1
0
def standardSetup(echo=False, file_handler=True, copy_db=True):
    """Utility function to setup up the configuration, logging and database

    Args:
        echo: enable sqlalchemy db echoing
        file_handler: log to a file if True, log to screen if False
        copy_db: write changes to a copy of the database, which upon cleanup replaces
            the existing one
    """
    global SQL_FILE, TMP_FILE, COPIED, LOCK_FILE
    configure.load()
    util.configureLogging(file_handler=file_handler)
    # I store my database in dropbox and the incremental updates
    # while running the program can get expensive
    LOCK_FILE = LockFile()
    LOCK_FILE.lock()
    SQL_FILE = configure.get('SQL_FILE')
    COPIED = copy_db
    if copy_db:
        TMP_FILE = tempfile.NamedTemporaryFile()
        logger.debug('Temp database is %s', TMP_FILE.name)
        with open(SQL_FILE) as f:
            shutil.copyfileobj(f, TMP_FILE)
            TMP_FILE.flush()
        _setSession(echo, TMP_FILE.name)
    else:
        _setSession(echo, SQL_FILE)
Exemplo n.º 2
0
def standardSetup(echo=False, file_handler=True, copy_db=True):
    """Utility function to setup up the configuration, logging and database

    Args:
        echo: enable sqlalchemy db echoing
        file_handler: log to a file if True, log to screen if False
        copy_db: write changes to a copy of the database, which upon cleanup replaces
            the existing one
    """
    global SQL_FILE, TMP_FILE, COPIED, LOCK_FILE
    configure.load()
    util.configureLogging(file_handler=file_handler)
    # I store my database in dropbox and the incremental updates
    # while running the program can get expensive
    LOCK_FILE = LockFile()
    LOCK_FILE.lock()
    SQL_FILE = configure.get('SQL_FILE')
    COPIED = copy_db
    if copy_db:
        TMP_FILE = tempfile.NamedTemporaryFile()
        logger.debug('Temp database is %s', TMP_FILE.name)
        with open(SQL_FILE) as f:
            shutil.copyfileobj(f, TMP_FILE)
            TMP_FILE.flush()
        _setSession(echo, TMP_FILE.name)
    else:
        _setSession(echo, SQL_FILE)
Exemplo n.º 3
0
import os.path

import sqlalchemy

from porntool import configure
from porntool import db
from porntool import tables

configure.load()

SQL_FILE = configure.get('SQL_FILE')
if not SQL_FILE:
    raise Exception(
        'The location of the database (SQL_FILE) is not specified.')

if os.path.exists(SQL_FILE):
    raise Exception("The file %s already exists.  Can't create database",
                    SQL_FILE)

engine = sqlalchemy.create_engine(db.urlFromFile(SQL_FILE), echo=False)
tables.Base.metadata.create_all(engine)
print "Succesfully created a new database: {}".format(SQL_FILE)
Exemplo n.º 4
0
import argparse
import os
import subprocess

from porntool import configure

configure.load()

parser = argparse.ArgumentParser()
parser.add_argument('playlist')
parser.add_argument('output')
args = parser.parse_args()

concat = 'concat_file'

with open(concat, 'w') as inpt:
    if args.playlist:
        with open(args.playlist) as f:
            for l in f:
                inpt.write("file '{}'\n".format(l.strip()))

video = configure.get('VIDEO')
audio = configure.get('AUDIO')

subprocess.call(['ffmpeg', '-f', 'concat', '-i', concat, '-c', 'copy', args.output])
os.remove(concat)