本文整理汇总了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
示例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!")
示例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)
示例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)
示例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")
示例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")