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


Python Path.get_pathto方法代码示例

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


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

示例1: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:hforge,项目名称:crm,代码行数:52,代码来源:base.py

示例2: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:nkhine,项目名称:ztm-ikaaro,代码行数:27,代码来源:theme.py

示例3: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:nkhine,项目名称:ztm-ikaaro,代码行数:32,代码来源:news.py

示例4: PathComparisonTestCase

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
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, '.')
开发者ID:Nabellaleen,项目名称:itools,代码行数:37,代码来源:test_uri.py

示例5: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:hforge,项目名称:shop,代码行数:37,代码来源:images.py

示例6: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:hforge,项目名称:shop,代码行数:53,代码来源:folder.py

示例7: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:hforge,项目名称:itws,代码行数:42,代码来源:diaporama.py

示例8: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:nkhine,项目名称:ztm-ikaaro,代码行数:42,代码来源:tags.py

示例9: update_links

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
    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)
开发者ID:nkhine,项目名称:ztm-ikaaro,代码行数:26,代码来源:html.py

示例10: update_locale

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
def update_locale(srx_handler, exclude_folders, no_wrap=False):
    # Read configuration for languages
    config = get_config()
    src_language = config.get_value('source_language', default='en')

    # Get local folder
    package_root = config.get_value('package_root')
    if lfs.exists(package_root):
        locale_folder_path = Path('{0}/locale'.format(package_root))
    else:
        locale_folder_path = Path('locale/')
    locale_folder = lfs.open(locale_folder_path)

    # Initialize message catalog
    po = POFile()
    lines = []
    for line in open('MANIFEST').readlines():
        line = line.strip()
        exclude_folder = False
        for x in exclude_folders:
            if line.startswith(x):
                exclude_folder = True
                break
        if exclude_folder is False:
            lines.append(line)

    # Process Python and HTML files
    write('* Extract text strings')
    extensions = [
        '.py',
        '.js',
        '.xhtml.%s' % src_language,
        '.xml.%s' % src_language,
        '.html.%s' % src_language]

    for path in lines:
        # Filter files
        for extension in extensions:
            if path.endswith(extension):
                break
        else:
            continue
        # Get the units
        write('.')
        try:
            handler = ro_database.get_handler(path)
        except Exception:
            print
            print '*'
            print '* Error:', path
            print '*'
            raise
        try:
            units = handler.get_units(srx_handler=srx_handler)
            units = list(units)
        except Exception:
            print
            print '*'
            print '* Error:', path
            print '*'
            raise

        relative_path = locale_folder_path.get_pathto(path)
        for source, context, line in units:
            po.add_unit(relative_path, source, context, line)
    print

    write('* Update PO template ')
    data = po.to_str()

    # Write the po into the locale.pot
    try:
        locale_pot = locale_folder.open('locale.pot', WRITE)
    except IOError:
        # The locale.pot file does not exist create and open
        locale_pot = locale_folder.make_file('locale.pot')
    else:
        with locale_pot:
            locale_pot.write(data)

    # Update PO files
    filenames = set([ x for x in locale_folder.get_names() if x[-3:] == '.po' ])
    filenames.add('%s.po' % src_language)
    for language in config.get_value('target_languages'):
        filenames.add('%s.po' % language)
    filenames = list(filenames)
    filenames.sort()

    print '* Update PO files:'
    locale_pot_path = locale_folder.get_absolute_path('locale.pot')
    for filename in filenames:
        if locale_folder.exists(filename):
            write('  %s ' % filename)
            file_path = locale_folder.get_absolute_path(filename)
            if no_wrap:
                call(['msgmerge', '--no-wrap', '-U', '-s', file_path, locale_pot_path])
            else:
                call(['msgmerge', '-U', '-s', file_path, locale_pot_path])
        else:
            print '  %s (new)' % filename
#.........这里部分代码省略.........
开发者ID:hforge,项目名称:itools,代码行数:103,代码来源:update_locale.py

示例11: test_pathto_w_slash

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import get_pathto [as 别名]
 def test_pathto_w_slash(self):
     before = Path('/a/b/')
     after = Path('/a/b/c')
     self.assertEqual(before.get_pathto(after), 'c')
开发者ID:Nabellaleen,项目名称:itools,代码行数:6,代码来源:test_uri.py


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