Пример #1
0
def appcall(function, *args, **kw):
    '''Calls a function passing 'app' as first argument.'''
    from base import app, close
    app = app()
    args = (app,) + args
    try:
        return function(*args, **kw)
    finally:
        transaction.abort()
        close(app)
Пример #2
0
def appcall(func, *args, **kw):
    '''Calls a function passing 'app' as first argument.'''
    from base import app, close
    app = app()
    args = (app,) + args
    try:
        return func(*args, **kw)
    finally:
        transaction.abort()
        close(app)
Пример #3
0
def organizeFiles(models_dir, mults_dir):
    # Decompose the BasePairs file to the set of files containing pairs by model
    # e.g. 1.txt contains pairs of 1 model
    # in  : name of future directory for files

    # read  BasePairs file
    base = open("BasePairs.txt", "r")
    # create a directory for models if it doesn't exist
    if not os.path.exists(models_dir):
        os.makedirs(models_dir)
    if not os.path.exists(mults_dir):
        os.makedirs(mults_dir)
    # work in models directory
    os.chdir(models_dir)
    # list of files in the directory
    filelist = [f for f in os.listdir(".")]
    # delete them
    for f in filelist:
        os.remove(f)
    # start to fill the directory with models files
    cur_model = "1"
    # create a file for the first model
    out = open(str(cur_model) + ".txt", "w")
    # walk througth the pairs
    for line in base:
        model = line.split("\t")[1]
        # write pairs of the same model
        if model != cur_model:
            out.close()
            cur_model = model
            out = open(cur_model + ".txt", "w")
        out.write(line)
    # return to the home directory
    os.chdir("..")
    # close all the files
    out.close()
    base.close()
    return