本文整理汇总了Python中itools.uri.Path类的典型用法代码示例。如果您正苦于以下问题:Python Path类的具体用法?Python Path怎么用?Python Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_links
def update_links(self, source, target):
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
handler = self.handler
get_value = handler.get_record_value
for record in handler.get_records_in_order():
path = get_value(record, 'name')
if not path:
continue
ref = get_reference(path)
if ref.scheme:
continue
# Strip the view
path = ref.path
name = path.get_name()
if name and name[0] == ';':
view = '/' + name
path = path[:-1]
else:
view = ''
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
# Build the new reference with the right path
new_ref = deepcopy(ref)
new_ref.path = str(new_base.get_pathto(target)) + view
handler.update_record(record.id, **{'name': str(new_ref)})
get_context().server.change_resource(self)
示例2: update_links
def update_links(self, source, target):
WebPage.update_links(self, source, target)
site_root = self.get_site_root()
available_languages = site_root.get_property('website_languages')
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
for lang in available_languages:
path = self.get_property('thumbnail', language=lang)
if not path:
continue
ref = get_reference(path)
if ref.scheme:
continue
path, view = get_path_and_view(ref.path)
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
# Build the new reference with the right path
new_ref = deepcopy(ref)
new_ref.path = str(new_base.get_pathto(target)) + view
self.set_property('thumbnail', str(new_ref), language=lang)
get_context().database.change_resource(self)
示例3: update_links
def update_links(self, source, target):
# FIXME BaseTheme does not take into account 'child'
BaseTheme.update_links(self, source, target)
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
# banner_path
site_root = self.get_site_root()
available_languages = site_root.get_property("website_languages")
for language in available_languages:
value = self.get_property("banner_path", language=language)
if not value:
continue
path = old_base.resolve2(value)
if path == source:
# Hit the old name
# Build the new reference with the right path
self.set_property("banner_path", new_base.get_pathto(target), language=language)
get_context().database.change_resource(self)
示例4: get_resource
def get_resource(self, path, soft=False):
if type(path) is not Path:
path = Path(path)
# 1. Get the metadata
if path.is_absolute():
abspath = path
else:
abspath = self.abspath.resolve2(path)
return self.database.get_resource(abspath, soft=soft)
示例5: update_links
def update_links(self, source, target):
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
site_root = self.get_site_root()
languages = site_root.get_property('website_languages')
links = []
for key, datatype in self.get_metadata_schema().items():
multilingual = getattr(datatype, 'multilingual', False)
langs = languages if multilingual is True else [None]
if issubclass(datatype, XHTMLBody):
for lang in langs:
events = self.get_property(key, language=lang)
if not events:
continue
events = _change_link(source, target, old_base, new_base,
events)
events = list(events)
self.set_property(key, events, language=lang)
elif issubclass(datatype, PathDataType):
# Relative path
for lang in langs:
path = self.get_property(key, language=lang)
if path is None:
continue
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
new_path = str(new_base.get_pathto(target))
self.set_property(key, new_path, language=lang)
elif issubclass(datatype, AbsolutePathDataTypeEnumerate):
# Absolute path
for lang in langs:
path = self.get_property(key, language=lang)
if path is None:
continue
path = str(path)
path = resources_new2old.get(path, path)
if path == source:
# Hit the old name
self.set_property(key, str(target), language=lang)
# Tagaware ?
if isinstance(self, TagsAware):
TagsAware.update_links(self, source, target)
# Change resource
get_context().database.change_resource(self)
示例6: PathComparisonTestCase
class PathComparisonTestCase(TestCase):
def setUp(self):
self.path_wo_slash = Path('/a/b/c')
self.path_w_slash = Path('/a/b/c/')
self.wo_to_w = self.path_wo_slash.get_pathto(self.path_w_slash)
#########################################################################
# Comparing Path objects
def test_with_eq_without_trailing_slash(self):
"""A path is not the same with a trailing slash."""
self.assertNotEqual(self.path_wo_slash, self.path_w_slash)
def test_wo_to_w_eq_path_dot(self):
"""The path to the same with a trailing slash returns Path('.')."""
self.assertEqual(self.wo_to_w, Path('.'))
#########################################################################
# Comparing with string conversions.
def test_path_wo_slash_eq_string(self):
"""A path without trailing slash equals its string conversion."""
self.assertEqual(self.path_wo_slash, str(self.path_wo_slash))
def test_path_w_slash_eq_string(self):
"""A path with trailing slash equals its string conversion."""
self.assertEqual(self.path_w_slash, str(self.path_w_slash))
def test_path_to_similar_eq_string_dot(self):
"""The path to the same with a trailing slash equals '.'."""
self.assertEqual(self.wo_to_w, '.')
示例7: update_links
def update_links(self, source, target):
source = Path(source)
site_root = self.get_site_root()
# Tags
tags_base = site_root.get_abspath().resolve2("tags")
if tags_base.get_prefix(source) == tags_base:
tags = list(self.get_property("tags"))
source_name = source.get_name()
target_name = Path(target).get_name()
for tag in tags:
if tag == source_name:
# Hit
index = tags.index(source_name)
tags[index] = target_name
self.set_property("tags", tags)
get_context().database.change_resource(self)
示例8: get_available_languages
def get_available_languages(self):
"""Returns the language codes for the user interface.
"""
source = itools_source_language
target = itools_target_languages
# A package based on itools
cls = self.__class__
if cls is not Root:
exec('import %s as pkg' % cls.__module__.split('.', 1)[0])
config = Path(pkg.__path__[0]).resolve_name('setup.conf')
config = ro_database.get_handler(str(config), ConfigFile)
source = config.get_value('source_language', default=source)
target = config.get_value('target_languages', default=target)
target = target.split()
if source in target:
target.remove(source)
target.insert(0, source)
return target
示例9: update_links
def update_links(self, source, target):
super(BoxFeed, self).update_links(source, target)
container_path = self.get_property('container_path')
if container_path:
if container_path == '/':
# Even if site_root is renammed, '/' is '/'
pass
else:
resources_new2old = get_context().database.resources_new2old
site_root_abspath = self.get_site_root().abspath
base = str(site_root_abspath)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
# Path is relative to site_root
path = old_base.resolve2(container_path)
if path == source:
# Hit the old name
new_path = site_root_abspath.get_pathto(target)
self.set_property('container_path', new_path)
示例10: update_links
def update_links(self, source, target):
super(DiaporamaTable, self).update_links(source, target)
# Caution multilingual property
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
site_root = self.get_site_root()
available_languages = site_root.get_property('website_languages')
handler = self.handler
record_properties = handler.record_properties
# TODO To improve
get_value = handler.get_record_value
for record in handler.get_records():
for lang in available_languages:
for key in ('img_path', 'img_link'):
path = get_value(record, key, lang)
if not path:
continue
ref = get_reference(path)
if ref.scheme:
continue
path, view = get_path_and_view(ref.path)
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
# Build the new reference with the right path
new_ref = deepcopy(ref)
new_ref.path = str(new_base.get_pathto(target)) + view
datatype = record_properties.get(key, String)
new_path = Property(datatype.decode(str(new_ref)),
language=lang)
handler.update_record(record.id, **{key: new_path})
get_context().database.change_resource(self)
示例11: get_item_value
def get_item_value(self, resource, context, item, column):
if column == 'checkbox':
if self.is_folder(item):
return None
proxy = super(AddImage_BrowseContent, self)
return proxy.get_item_value(resource, context, item, column)
elif column == 'icon':
if self.is_folder(item):
# icon
path_to_icon = item.get_resource_icon(48)
if path_to_icon.startswith(';'):
path_to_icon = Path('%s/' % item.name).resolve(path_to_icon)
else:
path = item.abspath
path_to_icon = ";thumb?width=48&height=48"
if path:
path_to_resource = Path(str(path) + '/')
path_to_icon = path_to_resource.resolve(path_to_icon)
return path_to_icon
else:
proxy = super(AddImage_BrowseContent, self)
return proxy.get_item_value(resource, context, item, column)
示例12: get_resource
def get_resource(self, path, soft=False):
if type(path) is not Path:
path = Path(path)
if path.is_absolute():
here = self.get_root()
else:
here = self
while path and path[0] == '..':
here = here.parent
path = path[1:]
for name in path:
resource = here._get_resource(name)
if resource is None:
if soft is True:
return None
raise LookupError, 'resource "%s" not found' % path
resource.parent = here
resource.name = name
here = resource
return here
示例13: update_links
def update_links(self, source, target):
WebPage.update_links(self, source, target)
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
path = self.get_property('title_link')
if path:
ref = get_reference(path)
if not ref.scheme:
path, view = get_path_and_view(ref.path)
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
# Build the new reference with the right path
new_ref = deepcopy(ref)
new_ref.path = str(new_base.get_pathto(target)) + view
self.set_property('title_link', str(new_ref))
get_context().database.change_resource(self)
示例14: update_links
def update_links(self, source, target):
Folder.update_links(self, source, target)
TagsAware.update_links(self, source, target)
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
# metadata
schema = self.class_schema
for key, datatype in schema.iteritems():
if issubclass(datatype, PathDataType) is False:
continue
value = self.get_property(key)
if not value:
continue
ref = get_reference(value)
if ref.scheme:
continue
path, view = get_path_and_view(ref.path)
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
# Build the new path with the right path
new_path = str(new_base.get_pathto(target)) + view
self.set_property(key, Path(new_path))
# comments
comments = self.metadata.get_property('comment') or []
for comment in comments:
# XXX hardcoded, not typed
for key in ('attachment',):
value = comment.get_parameter(key)
if not value:
continue
ref = get_reference(value)
if ref.scheme:
continue
path, view = get_path_and_view(ref.path)
path = str(old_base.resolve2(path))
if path == source:
# Hit the old name
# Build the new path with the right path
new_path = str(new_base.get_pathto(target)) + view
comment.set_parameter(key, new_path)
self.set_property('comment', comments)
示例15: update_links
def update_links(self, source, target):
source = Path(source)
site_root = self.get_site_root()
available_languages = site_root.get_property('website_languages')
# Tags
tags_base = site_root.get_abspath().resolve2('tags')
if tags_base.get_prefix(source) == tags_base:
tags = list(self.get_property('tags'))
source_name = source.get_name()
target_name = Path(target).get_name()
for tag in tags:
if tag == source_name:
# Hit
index = tags.index(source_name)
tags[index] = target_name
self.set_property('tags', tags)
# Thumbnail
base = self.get_canonical_path()
resources_new2old = get_context().database.resources_new2old
base = str(base)
old_base = resources_new2old.get(base, base)
old_base = Path(old_base)
new_base = Path(base)
for lang in available_languages:
path = self.get_property('thumbnail', lang)
if not path:
continue
ref = get_reference(path)
if ref.scheme:
continue
path = old_base.resolve2(path)
if path == source:
# Hit
self.set_property('thumbnail', new_base.get_pathto(target),
lang)
get_context().database.change_resource(self)