当前位置: 首页>>代码示例>>Python>>正文


Python fs.Folder类代码示例

本文整理汇总了Python中hyde.fs.Folder的典型用法代码示例。如果您正苦于以下问题:Python Folder类的具体用法?Python Folder怎么用?Python Folder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Folder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_node

    def add_node(self, a_folder):
        """
        Adds a new node to this folder's hierarchy.
        Also adds to to the hashtable of path to node associations
        for quick lookup.
        """
        folder = Folder(a_folder)
        node = self.node_from_path(folder)
        if node:
            logger.debug("Node exists at [%s]" % node.relative_path)
            return node

        if not folder.is_descendant_of(self.source_folder):
            raise HydeException("The given folder [%s] does not"
                                " belong to this hierarchy [%s]" %
                                (folder, self.source_folder))

        p_folder = folder
        parent = None
        hierarchy = []
        while not parent:
            hierarchy.append(p_folder)
            p_folder = p_folder.parent
            parent = self.node_from_path(p_folder)

        hierarchy.reverse()
        node = parent if parent else self
        for h_folder in hierarchy:
            node = node.add_child_node(h_folder)
            self.node_map[unicode(h_folder)] = node
            logger.debug("Added node [%s] to [%s]" % (
                            node.relative_path, self.source_folder))

        return node
开发者ID:jmvldz,项目名称:jmvldz,代码行数:34,代码来源:site.py

示例2: create

    def create(self, args):
        """
        The create command. Creates a new site from the template at the given
        sitepath.
        """
        self.main(args)
        sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
        markers = ['content', 'layout', 'site.yaml']
        exists = any((FS(sitepath.child(item)).exists for item in markers))

        if exists and not args.overwrite:
            raise HydeException(
                    "The given site path [%s] already contains a hyde site."
                    " Use -f to overwrite." % sitepath)
        layout = Layout.find_layout(args.layout)
        logger.info(
            "Creating site at [%s] with layout [%s]" % (sitepath, layout))
        if not layout or not layout.exists:
            raise HydeException(
            "The given layout is invalid. Please check if you have the"
            " `layout` in the right place and the environment variable(%s)"
            " has been setup properly if you are using custom path for"
            " layouts" % HYDE_DATA)
        layout.copy_contents_to(args.sitepath)
        logger.info("Site creation complete")
开发者ID:benallard,项目名称:hyde,代码行数:25,代码来源:engine.py

示例3: begin_site

    def begin_site(self):
        """
        Finds all the folders that need flattening and changes the
        relative deploy path of all resources in those folders.
        """
        items = []
        try:
            items = self.site.config.flattener.items
        except AttributeError:
            pass

        for item in items:
            node = None
            target = ''
            try:
                node = self.site.content.node_from_relative_path(item.source)
                target = Folder(item.target)
            except AttributeError:
                continue
            if node:
                for resource in node.walk_resources():
                    target_path = target.child(resource.name)
                    self.logger.debug(
                        'Flattening resource path[%s] to [%s]' %
                            (resource, target_path))
                    resource.relative_deploy_path = target_path
开发者ID:chewable,项目名称:hyde,代码行数:26,代码来源:folders.py

示例4: has_resource_changed

 def has_resource_changed(self, resource):
     """
     Checks if the given resource has changed since the
     last generation.
     """
     logger.debug("Checking for changes in %s" % resource)
     self.load_site_if_needed()
     self.load_template_if_needed()
     target = File(self.site.config.deploy_root_path.child(
                             resource.relative_deploy_path))
     if not target.exists or target.older_than(resource.source_file):
         logger.debug("Found changes in %s" % resource)
         return True
     if resource.source_file.is_binary:
         logger.debug("No Changes found in %s" % resource)
         return False
     deps = self.get_dependencies(resource)
     if not deps or None in deps:
         logger.debug("No changes found in %s" % resource)
         return False
     content = self.site.content.source_folder
     layout = Folder(self.site.sitepath).child_folder('layout')
     logger.debug("Checking for changes in dependents:%s" % deps)
     for dep in deps:
         if not dep:
             return True
         source = File(content.child(dep))
         if not source.exists:
             source = File(layout.child(dep))
         if not source.exists:
             return True
         if target.older_than(source):
             return True
     logger.debug("No changes found in %s" % resource)
     return False
开发者ID:alanhogan,项目名称:hyde,代码行数:35,代码来源:generator.py

示例5: _get_layout_folder

 def _get_layout_folder(root, layout_name='basic'):
     """
     Finds the layout folder from the given root folder.
     If it does not exist, return None
     """
     layouts_folder = Folder(str(root)).child_folder(LAYOUTS)
     layout_folder = layouts_folder.child_folder(layout_name)
     return layout_folder if layout_folder.exists else None
开发者ID:MeirKriheli,项目名称:hyde,代码行数:8,代码来源:layout.py

示例6: build_url

def build_url(base, path, safe=None):
    """
    Returns the content url by appending the base url
    with the given path. The return value is url encoded.
    """
    scheme, url = split_scheme(base)
    fpath = Folder(url).child(path).replace(os.sep, '/').encode("utf-8")
    if safe is not None:
        fpath = quote(fpath, safe)
    else:
        fpath = quote(fpath)

    if fpath.startswith("/"):
        return fpath
    else:
        return scheme + fpath
开发者ID:SPlyer,项目名称:hyde,代码行数:16,代码来源:site.py

示例7: translate_path

    def translate_path(self, path):
        """
        Finds the absolute path of the requested file by
        referring to the `site` variable in the server.
        """
        path = SimpleHTTPRequestHandler.translate_path(self, path)
        site = self.server.site
        result = urlparse.urlparse(self.path)
        logger.debug("Trying to load file based on request: [%s]" % result.path)
        path = result.path.lstrip('/')
        res = None
        if path.strip() == "" or File(path).kind.strip() == "":
            deployed = site.config.deploy_root_path.child(path)
            deployed = Folder.file_or_folder(deployed)
            if isinstance(deployed, Folder):
                node = site.content.node_from_relative_path(path)
                res = node.get_resource('index.html')
            elif hasattr(site.config, 'urlcleaner') and hasattr(site.config.urlcleaner, 'strip_extensions'):
                for ext in site.config.urlcleaner.strip_extensions:
                    res = site.content.resource_from_relative_deploy_path(path + '.' + ext)
                    if res:
                        break
        else:
            res = site.content.resource_from_relative_deploy_path(path)

        if not res:
            logger.error("Cannot load file: [%s]" % path)
            return site.config.deploy_root_path.child(path)
        else:
            self.server.generate_resource(res)
        new_path = site.config.deploy_root_path.child(
                    res.relative_deploy_path)
        return new_path
开发者ID:dcode,项目名称:hyde,代码行数:33,代码来源:server.py

示例8: __init__

 def __init__(self, sitepath, depends_file_name='.hyde_deps'):
     self.sitepath = Folder(sitepath)
     self.deps_file = File(self.sitepath.child(depends_file_name))
     self.data = {}
     if self.deps_file.exists:
         self.data = yaml.load(self.deps_file.read_all())
     import atexit
     atexit.register(self.save)
开发者ID:DaveRichmond,项目名称:hyde,代码行数:8,代码来源:model.py

示例9: serve

 def serve(self, args):
     """
     The serve command. Serves the site at the given
     deployment directory, address and port. Regenerates
     the entire site or specific files based on ths request.
     """
     self.main(args)
     sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
     config_file = sitepath.child(args.config)
     site = self.make_site(args.sitepath, args.config, args.deploy)
     from hyde.server import HydeWebServer
     server = HydeWebServer(site, args.address, args.port)
     logger.info("Starting webserver at [%s]:[%d]", args.address, args.port)
     try:
         server.serve_forever()
     except KeyboardInterrupt, SystemExit:
         logger.info("Received shutdown request. Shutting down...")
         server.shutdown()
         logger.info("Server successfully stopped")
         exit()
开发者ID:mnemnosi,项目名称:hyde,代码行数:20,代码来源:engine.py

示例10: __init__

 def __init__(self, source_folder, parent=None):
     super(Node, self).__init__(source_folder)
     if not source_folder:
         raise HydeException("Source folder is required"
                             " to instantiate a node.")
     self.root = self
     self.module = None
     self.site = None
     self.source_folder = Folder(unicode(source_folder))
     self.parent = parent
     if parent:
         self.root = self.parent.root
         self.module = self.parent.module if self.parent.module else self
         self.site = parent.site
     self.child_nodes = []
     self.resources = []
开发者ID:jmvldz,项目名称:jmvldz,代码行数:16,代码来源:site.py

示例11: __init__

 def __init__(self, sitepath, config_file=None, config_dict=None):
     default_config = dict(
         content_root='content',
         deploy_root='deploy',
         media_root='media',
         layout_root='layout',
         media_url='/media',
         site_url='/',
         not_found='404.html',
         plugins = []
     )
     conf = dict(**default_config)
     self.sitepath = Folder(sitepath)
     conf.update(self.read_config(config_file))
     if config_dict:
         conf.update(config_dict)
     super(Config, self).__init__(conf)
开发者ID:philips,项目名称:hyde,代码行数:17,代码来源:model.py

示例12: _run_sphinx

    def _run_sphinx(self):
        """Run sphinx to generate the necessary output files.

        This method creates a temporary directory for sphinx's output, then
        run sphinx against the Hyde input directory.
        """
        logger.info("running sphinx")
        self.sphinx_build_dir = Folder(tempfile.mkdtemp())
        conf_path = self.site.sitepath.child_folder(self.settings.conf_path)
        sphinx_args = ["sphinx-build"]
        sphinx_args.extend([
            "-b", "hyde_json",
            "-c", conf_path.path,
            self.site.content.path,
            self.sphinx_build_dir.path
        ])
        if sphinx.main(sphinx_args) != 0:
            raise RuntimeError("sphinx build failed")
开发者ID:DaveRichmond,项目名称:hyde,代码行数:18,代码来源:sphinx.py

示例13: __run_sphinx

    def __run_sphinx(self):
        """Run sphinx to generate the necessary output files.

        This method creates a temporary directory for sphinx's output, then
        run sphinx against the Hyde input directory.
        """
        logger.info("running sphinx")
        self.__build_dir = Folder(tempfile.mkdtemp())
        sphinx_app = Sphinx(
            self.node().path,
            self.node().path,
            self.__build_dir.path,
            self.node().path,
            "json"
        )
        sphinx_app.add_builder(HydeJSONHTMLBuilder)
        sphinx_app._init_builder("hyde_json")
        sphinx_app.build()
开发者ID:rlz,项目名称:hyde,代码行数:18,代码来源:docdirs.py

示例14: __init__

 def __init__(self, sitepath, config_file=None, config_dict=None):
     default_config = dict(
         mode='production',
         content_root='content',
         deploy_root='deploy',
         media_root='media',
         layout_root='layout',
         media_url='/media',
         base_url="/",
         not_found='404.html',
         plugins = [],
         ignore = [ "*~", "*.bak" ]
     )
     conf = dict(**default_config)
     self.sitepath = Folder(sitepath)
     conf.update(self.read_config(config_file))
     if config_dict:
         conf.update(config_dict)
     super(Config, self).__init__(conf)
开发者ID:alanhogan,项目名称:hyde,代码行数:19,代码来源:model.py

示例15: Dependents

class Dependents(IterableUserDict):
    """
    Represents the dependency graph for hyde.
    """

    def __init__(self, sitepath, depends_file_name='.hyde_deps'):
        self.sitepath = Folder(sitepath)
        self.deps_file = File(self.sitepath.child(depends_file_name))
        self.data = {}
        if self.deps_file.exists:
            self.data = yaml.load(self.deps_file.read_all())
        import atexit
        atexit.register(self.save)

    def save(self):
        """
        Saves the dependency graph (just a dict for now).
        """
        if self.deps_file.parent.exists:
            self.deps_file.write(yaml.dump(self.data))
开发者ID:DaveRichmond,项目名称:hyde,代码行数:20,代码来源:model.py


注:本文中的hyde.fs.Folder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。