Beispiel #1
0
    def init(self, conf, env):

        def track(ns, path):
            if ns != 'resource':
                self.files.add((ns, path))
            elif self.resext and splitext(path)[1] in self.resext:
                self.files.add((ns, path))

        def changed(ns, path):
            if not self.modified:
                self.modified = True

        self.files = set([])
        self.modified = False

        # use extension to check if resource should be tracked (keep image, video and other resources separate)
        self.resext = conf.get('sitemap_resource_ext', [])
        self.imgext = conf.get('sitemap_image_ext', [])
        # video resources require more attributes (image, description)
        # see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668
        #self.vidext = conf.get('sitemap_video_ext', [])

        # track output files
        event.register(track, to=['create', 'update', 'skip', 'identical'])
        event.register(changed, to=['create', 'update'])
Beispiel #2
0
    def init(self, conf, env):

        def track(ns, path):
            if ns != 'resource':
                self.files.add((ns, path))
            elif self.resext and splitext(path)[1] in self.resext:
                self.files.add((ns, path))

        def changed(ns, path):
            if not self.modified:
                self.modified = True

        self.files = set([])
        self.modified = False

        # use extension to check if resource should be tracked (keep image, video and other resources separate)
        self.resext = conf.get('sitemap_resource_ext', [])
        self.imgext = conf.get('sitemap_image_ext', [])
        # video resources require more attributes (image, description)
        # see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668
        #self.vidext = conf.get('sitemap_video_ext', [])

        # track output files
        event.register(track, to=['create', 'update', 'skip', 'identical'])
        event.register(changed, to=['create', 'update'])
Beispiel #3
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
Beispiel #4
0
    def init(self):
        def track(path, *args, **kw):
            self.files.add(path)

        def changed(path, *args, **kw):
            if not self.has_changed:
                self.has_changed = True

        self.files = set([])
        self.has_changed = False

        # track output files
        event.register(track, to=['create', 'update', 'skip', 'identical'])
        event.register(changed, to=['create', 'update', 'identical'])
Beispiel #5
0
    def init(self):
        def track(path, *args, **kw):
            self.files.add(path)

        def changed(path, *args, **kw):
            if not self.has_changed:
                self.has_changed = True

        self.files = set([])
        self.has_changed = False

        # track output files
        event.register(track, to=["create", "update", "skip", "identical"])
        event.register(changed, to=["create", "update", "identical"])
Beispiel #6
0
    def init(self, conf, env):

        def track(ns, path):
            self.files.add((ns, path))

        def changed(ns, path):
            if not self.modified:
                self.modified = True

        self.files = set([])
        self.modified = False

        # track output files
        event.register(track, to=['create', 'update', 'skip', 'identical'])
        event.register(changed, to=['create', 'update', 'identical'])
Beispiel #7
0
def initialize(conf, env):

    global pool

    hooks, blocks = conf.get('hooks', {}), not conf.get('hooks_mt', True)
    pool = Threadpool(1 if blocks else multiprocessing.cpu_count(), wait=blocks)

    force = env.options.force
    normalize = lambda path: path.replace(conf['output_dir'], '')

    for pattern, action in iteritems(hooks):
        if isinstance(action, (types.FunctionType, string_types)):
            event.register(
                callback=partial(simple, pool, pattern, normalize, action),
                to=['create', 'update'] if not force else event.events)
        else:
            event.register(
                callback=partial(advanced, pool, pattern, force, normalize, *action),
                to=event.events)
Beispiel #8
0
def initialize(conf, env):

    global pool

    hooks, blocks = conf.get('hooks', {}), not conf.get('hooks_mt', True)
    pool = Threadpool(1 if blocks else multiprocessing.cpu_count(), wait=blocks)

    force = env.options.force
    normalize = lambda path: path.replace(conf['output_dir'], '')

    for pattern, action in iteritems(hooks):
        if isinstance(action, (types.FunctionType, string_types)):
            event.register(
                callback=partial(simple, pool, pattern, normalize, action),
                to=['create', 'update'] if not force else event.events)
        else:
            event.register(
                callback=partial(advanced, pool, pattern, force, normalize, *action),
                to=event.events)

    discover([conf.get('HOOKS_DIR', 'hooks/')], lambda x: x)
Beispiel #9
0
    def init(self):
        def track(path, *args, **kw):
            self.files.add(path)

        def changed(path, *args, **kw):
            if not self.has_changed:
                self.has_changed = True

        self.files = set([])
        self.has_changed = False

        permalink = self.conf["permalink_format"]
        for pat, repl in [(":year", "\d+"), (":month", "\d+"), (":day", "\d+"), (":[^/]+", "\S+")]:
            permalink = re.sub(pat, repl, permalink)

        # we rank full entries higher
        self.regex = re.compile(joinurl(self.conf["www_root"], permalink))

        # track output files
        event.register(track, to=["create", "update", "skip", "identical"])
        event.register(changed, to=["create", "update", "identical"])
Beispiel #10
0
    def init(self):

        def track(path, *args, **kw):
            self.files.add(path)

        def changed(path, *args, **kw):
            if not self.has_changed:
                self.has_changed = True

        self.files = set([])
        self.has_changed = False

        permalink = self.conf['permalink_format']
        for pat, repl in [(':year', '\d+'), (':month', '\d+'), (':day', '\d+'), (':[^/]+', '\S+')]:
            permalink = re.sub(pat, repl, permalink)

        # we rank full entries higher
        self.regex = re.compile(joinurl(self.conf['www_root'], permalink))

        # track output files
        event.register(track, to=['create', 'update', 'skip', 'identical'])
        event.register(changed, to=['create', 'update', 'identical'])
Beispiel #11
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