Пример #1
0
def run(conf, env, options):
    """Attention: this function may eat your data!  Every create, changed
    or skip event call tracks automatically files. After generation,
    ``acrylamid clean`` will call this function and remove untracked files.

    - with OUTPUT_IGNORE you can specify a list of patterns which are ignored.
    - you can use --dry-run to see what would have been removed
    - by default acrylamid does NOT call this function
    - it removes silently every empty directory

    :param conf: user configuration
    :param env: acrylamid environment
    :param force: remove all tracked files, too
    :param dryrun: don't delete, just show what would have been done
    """
    force=options.force
    dryrun=options.dryrun

    # we don't bother the user here
    log.setLevel(env.options.verbosity+5)
    env.options.ignore = True

    # register our track function to events
    event.register(track, to=['create', 'update', 'skip', 'identical'])

    # run a silent compile
    commands.compile(conf, env, dryrun=True, force=False)

    log.setLevel(env.options.verbosity)

    global tracked
    for root, dirs, files in os.walk(conf['output_dir'], topdown=True):
        found = set([join(root, p) for p in files
                     if not readers.ignored(root, p, conf['output_ignore'], conf['output_dir'])])

        for p in found.difference(tracked):
            if not dryrun:
                os.remove(p)
            event.remove(p)

        if force:
            for p in found.intersection(tracked):
                if not dryrun:
                    os.remove(p)
                event.remove(p)

        # don't visit excluded dirs
        for dir in dirs[:]:
            if readers.ignored(root, dir+'/', conf['output_ignore'], conf['output_dir']):
                dirs.remove(dir)

    # remove empty directories
    for root, dirs, files in os.walk(conf['output_dir'], topdown=True):
        for p in (join(root, k) for k in dirs):
            try:
                os.rmdir(p)
            except OSError:
                pass
Пример #2
0
def ignore():

    assert ignored("/path/", "foo", ["foo", "fo*", "/foo"], "/path/")
    assert ignored("/path/", "dir/", ["dir", "dir/"], "/path/")
    assert not ignored("/path/to/", "baz/", ["/baz/", "/baz"], "/path/")

    assert ignored("/", ".git/info/refs", [".git*"], "/")
    assert ignored("/", ".gitignore", [".git*"], "/")

    assert ignored("/", ".DS_Store", [".DS_Store"], "/")
Пример #3
0
def ignore():

    assert ignored('/path/', 'foo', ['foo', 'fo*', '/foo'], '/path/')
    assert ignored('/path/', 'dir/', ['dir', 'dir/'], '/path/')
    assert not ignored('/path/to/', 'baz/', ['/baz/', '/baz'], '/path/')

    assert ignored('/', '.git/info/refs', ['.git*'], '/')
    assert ignored('/', '.gitignore', ['.git*'], '/')

    assert ignored('/', '.DS_Store', ['.DS_Store'], '/')
Пример #4
0
def ignore():

    assert ignored('/path/', 'foo', ['foo', 'fo*', '/foo'], '/path/')
    assert ignored('/path/', 'dir/', ['dir', 'dir/'], '/path/')
    assert not ignored('/path/to/', 'baz/', ['/baz/', '/baz'], '/path/')

    assert ignored('/', '.git/info/refs', ['.git*'], '/')
    assert ignored('/', '.gitignore', ['.git*'], '/')

    assert ignored('/', '.DS_Store', ['.DS_Store'], '/')
Пример #5
0
def run(conf, env, options):
    """Attention: this function may eat your data!  Every create, changed
    or skip event call tracks automatically files. After generation,
    ``acrylamid clean`` will call this function and remove untracked files.

    - with OUTPUT_IGNORE you can specify a list of patterns which are ignored.
    - you can use --dry-run to see what would have been removed
    - by default acrylamid does NOT call this function
    - it removes silently every empty directory

    :param conf: user configuration
    :param env: acrylamid environment
    :param force: remove all tracked files, too
    :param dryrun: don't delete, just show what would have been done
    """
    force = options.force
    dryrun = options.dryrun

    # we don't bother the user here
    log.setLevel(env.options.verbosity + 5)
    env.options.ignore = True

    # register our track function to events
    event.register(track, to=['create', 'update', 'skip', 'identical'])

    # run a silent compile
    commands.compile(conf, env, dryrun=True, force=False)

    log.setLevel(env.options.verbosity)

    global tracked
    for root, dirs, files in os.walk(conf['output_dir'], topdown=True):
        found = set([
            join(root, p) for p in files if not readers.ignored(
                root, p, conf['output_ignore'], conf['output_dir'])
        ])

        for p in found.difference(tracked):
            if not dryrun:
                os.remove(p)
            event.remove(p)

        if force:
            for p in found.intersection(tracked):
                if not dryrun:
                    os.remove(p)
                event.remove(p)

        # don't visit excluded dirs
        for dir in dirs[:]:
            if readers.ignored(root, dir + '/', conf['output_ignore'],
                               conf['output_dir']):
                dirs.remove(dir)

    # remove empty directories
    for root, dirs, files in os.walk(conf['output_dir'], topdown=True):
        for p in (join(root, k) for k in dirs):
            try:
                os.rmdir(p)
            except OSError:
                pass