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


Python Folder.child方法代码示例

本文整理汇总了Python中fswrap.Folder.child方法的典型用法代码示例。如果您正苦于以下问题:Python Folder.child方法的具体用法?Python Folder.child怎么用?Python Folder.child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fswrap.Folder的用法示例。


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

示例1: __upload

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
def __upload(proj, repo, branch, data, maker, force=True):
    root, source, dist = (None, None, None)
    try:
        root = Folder(data.root or '~')
        source = root.child_folder('src')
        source.make()
        source = source.child_folder(proj)
        dist = root.child_folder('dist')
        tree = Tree(source, repo=repo, branch=branch)
        key = None
        if not force:
            key = check_revision_already_published(proj, data.bucket, tree)

        if not key:
            b = Bucket(data.bucket)
            b.make()
            key_folder = Folder(proj).child_folder(branch)
            zippath = dist.child_file(proj + '.zip')
            tree.clone(tip_only=True)
            sha = tree.get_revision(short=False)
            key_folder = key_folder.child_folder(sha)
            target = dist.child_folder(proj)
            target.make()
            maker(source, target)
            target.zip(zippath.path)
            b.add_file(zippath, target_folder=key_folder.path)
            key = b.bucket.get_key(key_folder.child(zippath.name))
    finally:
        if source:
            source.delete()
        if dist:
            dist.delete()

    return key.generate_url(30000)
开发者ID:gitbot,项目名称:builder,代码行数:36,代码来源:builder.py

示例2: begin_site

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
    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
                for child in node.walk():
                    child.relative_deploy_path = target.path
开发者ID:jperry,项目名称:hyde,代码行数:30,代码来源:structure.py

示例3: check_revision_already_published

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
def check_revision_already_published(proj, bucket_name, tree):
    b = Bucket(bucket_name)
    if not b.connect():
        return None

    sha = tree.get_revision_remote()
    key_folder = Folder(proj).child_folder(tree.branch_name)
    key_folder = key_folder.child_folder(sha)
    key_path = key_folder.child(proj + '.zip')
    return b.bucket.get_key(key_path)
开发者ID:gitbot,项目名称:builder,代码行数:12,代码来源:builder.py

示例4: Dependents

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
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:AlfiyaZi,项目名称:hyde,代码行数:22,代码来源:model.py

示例5: has_resource_changed

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
    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_template_if_needed()
        self.load_site_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
        if self.site.config.needs_refresh() or \
           not target.has_changed_since(self.site.config.last_modified):
            logger.debug("Site configuration changed")
            return True

        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:GitOffice,项目名称:hyde,代码行数:43,代码来源:generator.py

示例6: setup_env

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
def setup_env(user_name, data):
    os.setuid(pwd.getpwnam(user_name)[2])
    home = Folder('/mnt').child_folder(user_name)
    os.environ['HOME'] = home.path
    os.environ['BASH_ENV'] = home.child('.profile')
    os.chdir(home.path)
    venv = user_name.replace('gu', 'ge')
    check_call(['/usr/bin/virtualenv', '--system-site-packages', venv])

    def activate():
        f = home.child_folder(venv).child('bin/activate_this.py')
        execfile(f, dict(__file__=f))

    activate()

    if 'github_oauth' in data:
        check_call(['git', 'config', '--global', 'credential.helper', 'store'])
        credential = 'https://{oauth}:[email protected]'
        cred_file = home.child_file('.git-credentials')
        cred_file.write(credential.format(oauth=data['github_oauth']))
    return home, activate
开发者ID:,项目名称:,代码行数:23,代码来源:

示例7: SphinxPlugin

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
class SphinxPlugin(Plugin):
    """The plugin class for rendering sphinx-generated documentation."""

    def __init__(self, site):
        self.sphinx_build_dir = None
        self._sphinx_config = None
        super(SphinxPlugin, self).__init__(site)

    @property
    def plugin_name(self):
        """The name of the plugin, obivously."""
        return "sphinx"

    @property
    def settings(self):
        """Settings for this plugin.

        This property combines default settings with those specified in the
        site config to produce the final settings for this plugin.
        """
        settings = Expando({})
        settings.sanity_check = True
        settings.conf_path = "."
        settings.block_map = {}
        try:
            user_settings = getattr(self.site.config, self.plugin_name)
        except AttributeError:
            pass
        else:
            for name in dir(user_settings):
                if not name.startswith("_"):
                    setattr(settings,name,getattr(user_settings,name))
        return settings

    @property
    def sphinx_config(self):
        """Configuration options for sphinx.

        This is a lazily-generated property giving the options from the
        sphinx configuration file.  It's generated by actualy executing
        the config file, so don't do anything silly in there.
        """
        if self._sphinx_config is None:
            conf_path = self.settings.conf_path
            conf_path = self.site.sitepath.child_folder(conf_path)
            #  Sphinx always execs the config file in its parent dir.
            conf_file = conf_path.child("conf.py")
            self._sphinx_config = {"__file__":conf_file}
            curdir = os.getcwd()
            os.chdir(conf_path.path)
            try:
                execfile(conf_file,self._sphinx_config)
            finally:
                os.chdir(curdir)
        return self._sphinx_config

    def begin_site(self):
        """Event hook for when site processing begins.

        This hook checks that the site is correctly configured for building
        with sphinx, and adjusts any sphinx-controlled resources so that
        hyde will process them correctly.
        """
        settings = self.settings
        if settings.sanity_check:
            self._sanity_check()
        #  Find and adjust all the resource that will be handled by sphinx.
        #  We need to:
        #    * change the deploy name from .rst to .html
        #    * if a block_map is given, switch off default_block
        suffix = self.sphinx_config.get("source_suffix",".rst")
        for resource in self.site.content.walk_resources():
            if resource.source_file.path.endswith(suffix):
                new_name = resource.source_file.name_without_extension + ".html"
                target_folder = File(resource.relative_deploy_path).parent
                resource.relative_deploy_path = target_folder.child(new_name)
                if settings.block_map:
                    resource.meta.default_block = None

    def begin_text_resource(self,resource,text):
        """Event hook for processing an individual resource.

        If the input resource is a sphinx input file, this method will replace
        replace the text of the file with the sphinx-generated documentation.

        Sphinx itself is run lazily the first time this method is called.
        This means that if no sphinx-related resources need updating, then
        we entirely avoid running sphinx.
        """
        suffix = self.sphinx_config.get("source_suffix",".rst")
        if not resource.source_file.path.endswith(suffix):
            return text
        if self.sphinx_build_dir is None:
            self._run_sphinx()
        output = []
        settings = self.settings
        sphinx_output = self._get_sphinx_output(resource)
        #  If they're set up a block_map, use the specific blocks.
        #  Otherwise, output just the body for use by default_block.
        if not settings.block_map:
#.........这里部分代码省略.........
开发者ID:jaredly,项目名称:hyde,代码行数:103,代码来源:sphinx.py

示例8: Config

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
class Config(Expando):

    """
    Represents the hyde configuration file
    """

    def __init__(self, sitepath, config_file=None, config_dict=None):
        self.default_config = dict(
            mode='production',
            simple_copy=[],
            content_root='content',
            deploy_root='deploy',
            media_root='media',
            layout_root='layout',
            media_url='/media',
            base_url="/",
            encode_safe=None,
            not_found='404.html',
            plugins=[],
            ignore=["*~", "*.bak", ".hg", ".git", ".svn"],
            meta={
                "nodemeta": 'meta.yaml'
            }
        )
        self.config_file = config_file
        self.config_dict = config_dict
        self.load_time = datetime.min
        self.config_files = []
        self.sitepath = Folder(sitepath)
        super(Config, self).__init__(self.load())

    @property
    def last_modified(self):
        return max((conf.last_modified for conf in self.config_files))

    def needs_refresh(self):
        if not self.config_files:
            return True
        return any((conf.has_changed_since(self.load_time)
                    for conf in self.config_files))

    def load(self):
        conf = dict(**self.default_config)
        conf.update(self.read_config(self.config_file))
        if self.config_dict:
            conf.update(self.config_dict)
        return conf

    def reload(self):
        if not self.config_file:
            return
        self.update(self.load())

    def read_config(self, config_file):
        """
        Reads the configuration file and updates this
        object while allowing for inherited configurations.
        """
        conf_file = self.sitepath.child(
            config_file if
            config_file else 'site.yaml')
        conf = {}
        if File(conf_file).exists:
            self.config_files.append(File(conf_file))
            logger.info("Reading site configuration from [%s]", conf_file)
            with codecs.open(conf_file, 'r', 'utf-8') as stream:
                conf = yaml.load(stream)
                if 'extends' in conf:
                    parent = self.read_config(conf['extends'])
                    parent.update(conf)
                    conf = parent
        self.load_time = datetime.now()
        return conf

    @property
    def deploy_root_path(self):
        """
        Derives the deploy root path from the site path
        """
        return _expand_path(self.sitepath, self.deploy_root)

    @property
    def content_root_path(self):
        """
        Derives the content root path from the site path
        """
        return _expand_path(self.sitepath, self.content_root)

    @property
    def media_root_path(self):
        """
        Derives the media root path from the content path
        """
        path = Folder(self.content_root).child(self.media_root)
        return _expand_path(self.sitepath, path)

    @property
    def layout_root_path(self):
        """
        Derives the layout root path from the site path
#.........这里部分代码省略.........
开发者ID:jiivan,项目名称:hyde,代码行数:103,代码来源:model.py

示例9: File

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
    <style>
        body {
            background-color: @black;
        }
    </style>
    <title>@title</title>
</head>'''
BODY = '''
<body>
    <h1>This is a simple html file</h1>
    <h2>That split up and combined.</h2>
</body>'''
STOP = '''
</html>'''

START_FILE = File(TEMP.child('templates/start_part.html'))
HEAD_FILE = File(TEMP.child('templates/head.html'))
BODY_FILE = File(TEMP.child('templates/body.html'))
STOP_FILE = File(TEMP.child('templates/end_part.html'))
OUT_FILE = File(TEMP.child('output.html'))

HTML = START + HEAD + BODY + STOP


def indent(text):
    result = ''
    for line in text.split('\n'):
        result += '    ' + line + '\n'
    return result.strip('\n')

HTML_INDENTED = START + indent(HEAD) + indent(BODY) + STOP
开发者ID:cnuber,项目名称:gitbot,代码行数:33,代码来源:test_cat.py

示例10: Node

# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import child [as 别名]
class Node(Processable):
    """
    Represents any folder that is processed by hyde
    """

    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(str(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 = []

    def contains_resource(self, resource_name):
        """
        Returns True if the given resource name exists as a file
        in this node's source folder.
        """

        return File(self.source_folder.child(resource_name)).exists

    def get_resource(self, resource_name):
        """
        Gets the resource if the given resource name exists as a file
        in this node's source folder.
        """

        if self.contains_resource(resource_name):
            return self.root.resource_from_path(
                self.source_folder.child(resource_name))
        return None

    def add_child_node(self, folder):
        """
        Creates a new child node and adds it to the list of child nodes.
        """

        if folder.parent != self.source_folder:
            raise HydeException("The given folder [%s] is not a"
                                " direct descendant of [%s]" %
                                (folder, self.source_folder))
        node = Node(folder, self)
        self.child_nodes.append(node)
        return node

    def add_child_resource(self, afile):
        """
        Creates a new resource and adds it to the list of child resources.
        """

        if afile.parent != self.source_folder:
            raise HydeException("The given file [%s] is not"
                                " a direct descendant of [%s]" %
                                (afile, self.source_folder))
        resource = Resource(afile, self)
        self.resources.append(resource)
        return resource

    def walk(self):
        """
        Walks the node, first yielding itself then
        yielding the child nodes depth-first.
        """
        yield self
        for child in sorted([node for node in self.child_nodes]):
            for node in child.walk():
                yield node

    def rwalk(self):
        """
        Walk the node upward, first yielding itself then
        yielding its parents.
        """
        x = self
        while x:
            yield x
            x = x.parent

    def walk_resources(self):
        """
        Walks the resources in this hierarchy.
        """
        for node in self.walk():
            for resource in sorted([resource for resource in node.resources]):
                yield resource

    @property
    def relative_path(self):
        """
        Gets the path relative to the root folder (Content, Media, Layout)
        """
#.........这里部分代码省略.........
开发者ID:LestherSK,项目名称:hyde,代码行数:103,代码来源:site.py


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