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


Python fswrap.Folder类代码示例

本文整理汇总了Python中fswrap.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 it 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[str(h_folder)] = node
            logger.debug("Added node [%s] to [%s]" % (
                         node.relative_path, self.source_folder))

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

示例2: 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
                for child in node.walk():
                    child.relative_deploy_path = target.path
开发者ID:jperry,项目名称:hyde,代码行数:28,代码来源:structure.py

示例3: _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(unicode(root)).child_folder(LAYOUTS)
     layout_folder = layouts_folder.child_folder(layout_name)
     return layout_folder if layout_folder.exists else None
开发者ID:AlfiyaZi,项目名称:hyde,代码行数:8,代码来源:layout.py

示例4: check_revision_already_published

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,代码行数:10,代码来源:builder.py

示例5: translate_path

    def translate_path(self, path):
        """
        Finds the absolute path of the requested file by
        referring to the `site` variable in the server.
        """
        site = self.server.site
        result = urlparse.urlparse(urllib.unquote(self.path).decode("utf-8"))
        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
                for ext in site.config.urlcleaner.strip_extensions:
                    new_path = site.config.deploy_root_path.child(path + "." + ext)
                    if File(new_path).exists:
                        return new_path
        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:JeNeSuisPasDave,项目名称:hyde,代码行数:35,代码来源:server.py

示例6: __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:jiivan,项目名称:hyde,代码行数:8,代码来源:model.py

示例7: __init__

 def __init__(self, source, repo=None, remote='origin', branch='master'):
     if not source:
         raise Exception('You must provide the source')
     self.source = Folder(source)
     self.repo = repo
     self.remote = remote
     self.branch_name = branch
     self.tagger = Tagger(self)
     self.git = ShellCommand(cwd=self.source.path, cmd='git')
开发者ID:cnuber,项目名称:gitbot,代码行数:9,代码来源:git.py

示例8: gen

def gen(source, data, target=None):
    source_command = ShellCommand(cwd=source.path)
    if source.child_file("requirements.txt").exists:
        source_command.call("pip", "install", "-r", "requirements.txt")
    if source.child_file("package.json").exists:
        source_command.call("npm", "install")

    # Generate
    target = target or data.target or source.parent.child("dist/www")
    dist = Folder(target)
    dist.make()

    template = source.child_file(data.config_template or "env.yaml")
    conf = source.child_file(data.config_file_name or "settings.gitbot")
    transform(template, conf, data)

    source_command.call("hyde", "gen", "-r", "-c", conf.name, "-d", dist.path)
    return dist
开发者ID:gitbot,项目名称:gitbot,代码行数:18,代码来源:hyde.py

示例9: 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_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,代码行数:41,代码来源:generator.py

示例10: setup_env

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:,项目名称:,代码行数:21,代码来源:

示例11: __upload

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,代码行数:34,代码来源:builder.py

示例12: get_worker_outputs

def get_worker_outputs(data):
    result = None
    try:
        region = data.region or 'us-east-1'
        root = Folder(data.root or '~')
        source = root.child_folder('src')
        source.make()
        source = source.child_folder('worker')
        repo = data.worker_repo or 'git://github.com/gitbot/worker.git'
        branch = data.worker_branch or 'master'

        #   1. Pull worker repo
        tree = Tree(source, repo, branch)
        tree.clone(tip_only=True)

        #   2. Call gitbot.stack.publish with 'gitbot.yaml'
        worker_stack_name = stack.publish_stack(
                                    source.child_file('gitbot.yaml'),
                                    wait=True)
        result = stack.get_outputs(worker_stack_name, region)
    except Exception, e:
        print repr(e)
        raise
开发者ID:gitbot,项目名称:builder,代码行数:23,代码来源:builder.py

示例13: __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(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 = []
开发者ID:LestherSK,项目名称:hyde,代码行数:16,代码来源:site.py

示例14: _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:jaredly,项目名称:hyde,代码行数:18,代码来源:sphinx.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:AlfiyaZi,项目名称:hyde,代码行数:20,代码来源:model.py


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