示例#1
0
def find_path(pattern, path, last_folder_only=False, ignored_dirs=''):
    ignored_dirs = ignored_dirs.split(',')
    result = []

    for root, dirs, files in os.walk(path):
        dirs[:] = [d for d in dirs if d not in ignored_dirs]

        for name in files:
            if fnmatch.fnmatch(name, pattern):
                result.append(os.path.join(root, name))

    if not result:
        return ''

    final_path = Path(result[0]).ancestor(1)
    relative_path = final_path.replace(str(path), '')

    if last_folder_only:
        return relative_path.split('/')[-1]
    return relative_path[1:] if relative_path.startswith('/') else relative_path
示例#2
0
def loaddata(local_file):
    '''
    Connect to Dreamhost server, upload a local database dump and
    restore it.

    Usage: fab stage db.restore:dumpfile.bz2
    '''
    require('PROJECT', provided_by=['stage', 'production'])

    local_file = Path(local_file)
    remote_file = Path(env.PROJECT.tmp, local_file.name)

    if put(local_file, remote_file).failed:
        abort('Failed to upload "%s"' % local_file)

    with cd(env.PROJECT.current):
        if '.bz2' in remote_file:
            run('bunzip2 %s' % remote_file)
            remote_file = remote_file.replace('.bz2', '')

        with prefix('source bin/activate'):
            run('python manage.py loaddata %s' % remote_file)

    run('rm %s' % remote_file)
示例#3
0
def loaddata(local_file):
    '''
    Connect to Dreamhost server, upload a local database dump and
    restore it.

    Usage: fab stage db.restore:dumpfile.bz2
    '''
    require('PROJECT', provided_by=['stage', 'production'])

    local_file = Path(local_file)
    remote_file = Path(env.PROJECT.tmp, local_file.name)

    if put(local_file, remote_file).failed:
        abort('Failed to upload "%s"' % local_file)

    with cd(env.PROJECT.current):
        if '.bz2' in remote_file:
            run('bunzip2 %s' % remote_file)
            remote_file = remote_file.replace('.bz2', '')

        with prefix('source bin/activate'):
            run('python manage.py loaddata %s' % remote_file)

    run('rm %s' % remote_file)