PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/ext/plugins/folders.py

http://github.com/hyde/hyde
Python | 44 lines | 29 code | 4 blank | 11 comment | 2 complexity | b89d3918133570ea7a0784d76c9fa522 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Plugins related to folders and paths
 4"""
 5
 6from hyde.plugin import Plugin
 7from hyde.fs import Folder
 8
 9class FlattenerPlugin(Plugin):
10    """
11    The plugin class for flattening nested folders.
12    """
13    def __init__(self, site):
14        super(FlattenerPlugin, self).__init__(site)
15
16    def begin_site(self):
17        """
18        Finds all the folders that need flattening and changes the
19        relative deploy path of all resources in those folders.
20        """
21        items = []
22        try:
23            items = self.site.config.flattener.items
24        except AttributeError:
25            pass
26
27        for item in items:
28            node = None
29            target = ''
30            try:
31                node = self.site.content.node_from_relative_path(item.source)
32                target = Folder(item.target)
33            except AttributeError:
34                continue
35            if node:
36                for resource in node.walk_resources():
37                    target_path = target.child(resource.name)
38                    self.logger.debug(
39                        'Flattening resource path [%s] to [%s]' %
40                            (resource, target_path))
41                    resource.relative_deploy_path = target_path
42                for child in node.walk():
43                    child.relative_deploy_path = target.path
44