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


Python Path.rel_path_to方法代码示例

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


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

示例1: SheerSite

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rel_path_to [as 别名]
class SheerSite(object):

    def __init__(self, slug):
        self.slug = slug
        if slug in settings.SHEER_SITES:
            self.path = Path(settings.SHEER_SITES[slug])
        else:
            self.path = None

    @property
    def urls(self):
        return self.urls_for_prefix()

    def urls_for_prefix(self, prefix='.'):
        url_patterns = []

        if self.path is None or not self.path.exists():
            return url_patterns

        prefixed_path = Path(self.path, prefix)
        for html_path in prefixed_path.walk():
            # skip files that don't end in .html
            if not html_path.endswith('.html'):
                continue
            rel_path = self.path.rel_path_to(html_path)
            prefix_rel_path = prefixed_path.rel_path_to(html_path)
            # skip files in underscore directories
            if rel_path.startswith('_'):
                continue
            view = SheerTemplateView.as_view(
                template_engine=self.slug,
                template_name=str(rel_path))
            regex_template = r'^%s$'
            index_template = r'^%s/$'
            if rel_path.name == 'index.html':
                if prefix_rel_path.parent:
                    slash_regex = index_template % prefix_rel_path.parent
                else:
                    slash_regex = r'^$'
                pattern = url(slash_regex, view)
                redirect_regex = regex_template % prefix_rel_path
                index_redirect = RedirectView.as_view(url='./', permanent=True)
                redirect_pattern = url(redirect_regex, index_redirect)
                url_patterns += [pattern, redirect_pattern]
            else:
                regex = regex_template % prefix_rel_path
                pattern = url(regex, view)
                url_patterns.append(pattern)
        return url_patterns
开发者ID:amymok,项目名称:cfgov-refresh,代码行数:51,代码来源:sites.py

示例2: sync

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rel_path_to [as 别名]
def sync():
    params = {
        "aws_access_key_id": app.config["AWS_ACCESS_KEY_ID"],
        "aws_secret_access_key": app.config["AWS_ACCESS_KEY"],
    }

    if app.config.get('AWS_S3_CALLING_FORMAT'):
        params['calling_format'] = app.config['AWS_S3_CALLING_FORMAT']

    if app.config.get("AWS_REGION"):
        c = boto.s3.connect_to_region(app.config["AWS_REGION"], **params)
    else:
        c = boto.connect_s3(**params)

    b = c.get_bucket(app.config["S3_BUCKET"])
    k = Key(b)

    local_path = app.config["FREEZER_DESTINATION"]
    destination_path = app.config["S3_DESTINATION"]

    local_path = Path(local_path)
    destination_path = Path(destination_path)

    for path, file_dir, files in os.walk(local_path):
        for local_file in files:
            file_path = Path(path, local_file)
            rel_path = Path(destination_path,
                            local_path.rel_path_to(file_path))

            logger.info("- Uploading file %s" % (rel_path,))

            k.key = rel_path
            k.set_contents_from_filename(file_path)
            b.set_acl("public-read", k.key)

    logger.info("Sync complete!")
开发者ID:marteinn,项目名称:AtomicPress,代码行数:38,代码来源:__init__.py

示例3: test4

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rel_path_to [as 别名]
 def test4(self):
     p1 = Path("swedish", "chef")
     assert p1.rel_path_to(self.d) == Path(os.path.pardir, os.path.pardir)
开发者ID:Mondego,项目名称:pyreco,代码行数:5,代码来源:allPythonContent.py

示例4: test3

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rel_path_to [as 别名]
 def test3(self):
     p1 = Path("animals", "elephant")
     assert p1.rel_path_to(self.d) == Path(os.path.pardir)
开发者ID:Mondego,项目名称:pyreco,代码行数:5,代码来源:allPythonContent.py

示例5: test2

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rel_path_to [as 别名]
 def test2(self):
     p1 = Path("animals", "elephant")
     p2 = Path("images", "image1.gif")
     assert p1.rel_path_to(p2) == Path(os.path.pardir, "images", "image1.gif")
开发者ID:Mondego,项目名称:pyreco,代码行数:6,代码来源:allPythonContent.py

示例6: test1

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rel_path_to [as 别名]
 def test1(self):
     p1 = Path("animals", "elephant")
     p2 = Path("animals", "mouse")
     assert p1.rel_path_to(p2) == Path("mouse")
开发者ID:Mondego,项目名称:pyreco,代码行数:6,代码来源:allPythonContent.py


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