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


Python path.relpath函数代码示例

本文整理汇总了Python中mozpack.path.relpath函数的典型用法代码示例。如果您正苦于以下问题:Python relpath函数的具体用法?Python relpath怎么用?Python relpath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __init__

    def __init__(self, topsrcdir, topobjdir, dist, group=Grouping.NO,
                 abspaths=False):
        topsrcdir = mozpath.normsep(os.path.normcase(os.path.abspath(topsrcdir)))
        topobjdir = mozpath.normsep(os.path.normcase(os.path.abspath(topobjdir)))
        dist = mozpath.normsep(os.path.normcase(os.path.abspath(dist)))
        if abspaths:
            topsrcdir_value = topsrcdir
            topobjdir_value = topobjdir
            dist_value = dist
        else:
            topsrcdir_value = '$(topsrcdir)'
            topobjdir_value = '$(DEPTH)'
            dist_value = '$(DIST)'

        self._normpaths = {
            topsrcdir: topsrcdir_value,
            topobjdir: topobjdir_value,
            dist: dist_value,
            '$(topsrcdir)': topsrcdir_value,
            '$(DEPTH)': topobjdir_value,
            '$(DIST)': dist_value,
            '$(depth)': topobjdir_value, # normcase may lowercase variable refs when
            '$(dist)': dist_value,       # they are in the original dependency file
            mozpath.relpath(topsrcdir, os.curdir): topsrcdir_value,
            mozpath.relpath(topobjdir, os.curdir): topobjdir_value,
            mozpath.relpath(dist, os.curdir): dist_value,
        }

        Makefile.__init__(self)
        self._group = group
        self._targets = OrderedDict()
开发者ID:captainbrosset,项目名称:gecko-dev,代码行数:31,代码来源:link_deps.py

示例2: consume_object

    def consume_object(self, obj):
        if isinstance(obj, JARManifest) and \
                obj.install_target.startswith('dist/bin'):
            self._consume_jar_manifest(obj)

        elif isinstance(obj, (FinalTargetFiles,
                              FinalTargetPreprocessedFiles)) and \
                obj.install_target.startswith('dist/bin'):
            defines = obj.defines or {}
            if defines:
                defines = defines.defines
            for path, files in obj.files.walk():
                for f in files:
                    if isinstance(obj, FinalTargetPreprocessedFiles):
                        self._add_preprocess(obj, f.full_path, path,
                                             target=f.target_basename,
                                             defines=defines)
                    elif '*' in f:
                        def _prefix(s):
                            for p in mozpath.split(s):
                                if '*' not in p:
                                    yield p + '/'
                        prefix = ''.join(_prefix(f.full_path))

                        self._install_manifests[obj.install_target] \
                            .add_pattern_symlink(
                                prefix,
                                f.full_path[len(prefix):],
                                mozpath.join(path, f.target_basename))
                    else:
                        self._install_manifests[obj.install_target].add_symlink(
                            f.full_path,
                            mozpath.join(path, f.target_basename)
                        )
                    if isinstance(f, ObjDirPath):
                        dep_target = 'install-%s' % obj.install_target
                        self._dependencies[dep_target].append(
                            mozpath.relpath(f.full_path,
                                            self.environment.topobjdir))

        elif isinstance(obj, ChromeManifestEntry) and \
                obj.install_target.startswith('dist/bin'):
            top_level = mozpath.join(obj.install_target, 'chrome.manifest')
            if obj.path != top_level:
                entry = 'manifest %s' % mozpath.relpath(obj.path,
                                                        obj.install_target)
                self._manifest_entries[top_level].add(entry)
            self._manifest_entries[obj.path].add(str(obj.entry))

        elif isinstance(obj, XPIDLFile):
            self._has_xpidl = True
            # We're not actually handling XPIDL files.
            return False

        else:
            return False

        return True
开发者ID:MekliCZ,项目名称:positron,代码行数:58,代码来源:fastermake.py

示例3: _process_library_definition

 def _process_library_definition(self, libdef, backend_file):
     backend_file.write("LIBRARY_NAME = %s\n" % libdef.basename)
     thisobjdir = libdef.objdir
     topobjdir = libdef.topobjdir.replace(os.sep, "/")
     for objdir, basename in libdef.static_libraries:
         # If this is an external objdir (i.e., comm-central), use the other
         # directory instead of $(DEPTH).
         if objdir.startswith(topobjdir + "/"):
             relpath = "$(DEPTH)/%s" % mozpath.relpath(objdir, topobjdir)
         else:
             relpath = mozpath.relpath(objdir, thisobjdir)
         backend_file.write("SHARED_LIBRARY_LIBS += %s/$(LIB_PREFIX)%s.$(LIB_SUFFIX)\n" % (relpath, basename))
开发者ID:vijayanandh,项目名称:gecko-dev,代码行数:12,代码来源:recursivemake.py

示例4: add

 def add(self, path, content):
     chrome = self._chromepath(path)
     if chrome:
         jar = chrome + '.jar'
         if not self.copier.contains(jar):
             self.copier.add(jar, Jarrer(self._compress, self._optimize))
         if not self.copier[jar].contains(mozpath.relpath(path,
                                                               chrome)):
             self.copier[jar].add(mozpath.relpath(path, chrome),
                                  content)
     else:
         FlatFormatter.add(self, path, content)
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:12,代码来源:formats.py

示例5: process_tests_artifact

    def process_tests_artifact(self, filename, processed_filename):
        from mozbuild.action.test_archive import OBJDIR_TEST_FILES
        added_entry = False

        with JarWriter(file=processed_filename, optimize=False, compress_level=5) as writer:
            reader = JarReader(filename)
            for filename, entry in reader.entries.iteritems():
                for pattern, (src_prefix, dest_prefix) in self.test_artifact_patterns:
                    if not mozpath.match(filename, pattern):
                        continue
                    destpath = mozpath.relpath(filename, src_prefix)
                    destpath = mozpath.join(dest_prefix, destpath)
                    self.log(logging.INFO, 'artifact',
                             {'destpath': destpath},
                             'Adding {destpath} to processed archive')
                    mode = entry['external_attr'] >> 16
                    writer.add(destpath.encode('utf-8'), reader[filename], mode=mode)
                    added_entry = True
                    break
                for files_entry in OBJDIR_TEST_FILES.values():
                    origin_pattern = files_entry['pattern']
                    leaf_filename = filename
                    if 'dest' in files_entry:
                        dest = files_entry['dest']
                        origin_pattern = mozpath.join(dest, origin_pattern)
                        leaf_filename = filename[len(dest) + 1:]
                    if mozpath.match(filename, origin_pattern):
                        destpath = mozpath.join('..', files_entry['base'], leaf_filename)
                        mode = entry['external_attr'] >> 16
                        writer.add(destpath.encode('utf-8'), reader[filename], mode=mode)

        if not added_entry:
            raise ValueError('Archive format changed! No pattern from "{patterns}"'
                             'matched an archive path.'.format(
                                 patterns=LinuxArtifactJob.test_artifact_patterns))
开发者ID:mykmelez,项目名称:spidernode,代码行数:35,代码来源:artifacts.py

示例6: _write_file

    def _write_file(self, path=None, fh=None):
        """Context manager to write a file.

        This is a glorified wrapper around FileAvoidWrite with integration to
        update the BackendConsumeSummary on this instance.

        Example usage:

            with self._write_file('foo.txt') as fh:
                fh.write('hello world')
        """

        if path is not None:
            assert fh is None
            fh = FileAvoidWrite(path)
        else:
            assert fh is not None

        dirname = mozpath.dirname(fh.name)
        try:
            os.makedirs(dirname)
        except OSError as error:
            if error.errno != errno.EEXIST:
                raise

        yield fh

        self._backend_output_files.add(mozpath.relpath(fh.name, self.environment.topobjdir))
        existed, updated = fh.close()
        if not existed:
            self.summary.created_count += 1
        elif updated:
            self.summary.updated_count += 1
        else:
            self.summary.unchanged_count += 1
开发者ID:chuck-lee,项目名称:mozilla-central,代码行数:35,代码来源:base.py

示例7: process_package_artifact

    def process_package_artifact(self, filename, processed_filename):
        added_entry = False

        with JarWriter(file=processed_filename, optimize=False, compress_level=5) as writer:
            with tarfile.open(filename) as reader:
                for f in reader:
                    if not f.isfile():
                        continue

                    if not any(mozpath.match(f.name, p) for p in self.package_artifact_patterns):
                        continue

                    # We strip off the relative "firefox/" bit from the path,
                    # but otherwise preserve it.
                    destpath = mozpath.join('bin',
                                            mozpath.relpath(f.name, "firefox"))
                    self.log(logging.INFO, 'artifact',
                             {'destpath': destpath},
                             'Adding {destpath} to processed archive')
                    writer.add(destpath.encode('utf-8'), reader.extractfile(f), mode=f.mode)
                    added_entry = True

        if not added_entry:
            raise ValueError('Archive format changed! No pattern from "{patterns}" '
                             'matched an archive path.'.format(
                                 patterns=LinuxArtifactJob.package_artifact_patterns))
开发者ID:emilio,项目名称:gecko-dev,代码行数:26,代码来源:artifacts.py

示例8: all_files

 def all_files(self, base):
     all_files = set()
     for root, dirs, files in os.walk(base):
         for f in files:
             all_files.add(
                 mozpath.join(mozpath.relpath(root, base), f))
     return all_files
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:7,代码来源:test_copier.py

示例9: normalize_path

 def normalize_path(path):
     '''
     Remove any bin/ prefix.
     '''
     if mozpath.basedir(path, ['bin']) == 'bin':
         return mozpath.relpath(path, 'bin')
     return path
开发者ID:MekliCZ,项目名称:positron,代码行数:7,代码来源:__init__.py

示例10: is_resource

 def is_resource(self, path, base=None):
     '''
     Return whether the given path corresponds to a resource to be put in an
     omnijar archive.
     '''
     if base is None:
         base = self._get_base(path)
     path = mozpath.relpath(path, base)
     if any(mozpath.match(path, p.replace('*', '**'))
            for p in self._non_resources):
         return False
     path = mozpath.split(path)
     if path[0] == 'chrome':
         return len(path) == 1 or path[1] != 'icons'
     if path[0] == 'components':
         return path[-1].endswith(('.js', '.xpt'))
     if path[0] == 'res':
         return len(path) == 1 or \
             (path[1] != 'cursors' and path[1] != 'MainMenu.nib')
     if path[0] == 'defaults':
         return len(path) != 3 or \
             not (path[2] == 'channel-prefs.js' and
                  path[1] in ['pref', 'preferences'])
     return path[0] in [
         'modules',
         'greprefs.js',
         'hyphenation',
         'update.locale',
     ] or path[0] in STARTUP_CACHE_PATHS
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:29,代码来源:formats.py

示例11: _get_files_info

    def _get_files_info(self, paths):
        from mozpack.files import FileFinder

        # Normalize to relative from topsrcdir.
        relpaths = []
        for p in paths:
            a = mozpath.abspath(p)
            if not mozpath.basedir(a, [self.topsrcdir]):
                raise InvalidPathException('path is outside topsrcdir: %s' % p)

            relpaths.append(mozpath.relpath(a, self.topsrcdir))

        finder = FileFinder(self.topsrcdir, find_executables=False)

        # Expand wildcards.
        allpaths = []
        for p in relpaths:
            if '*' not in p:
                if p not in allpaths:
                    allpaths.append(p)
                continue

            for path, f in finder.find(p):
                if path not in allpaths:
                    allpaths.append(path)

        reader = self._get_reader()
        return reader.files_info(allpaths)
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:28,代码来源:mach_commands.py

示例12: test_relpath

 def test_relpath(self):
     self.assertEqual(relpath("foo", "foo"), "")
     self.assertEqual(relpath(os.path.join("foo", "bar"), "foo/bar"), "")
     self.assertEqual(relpath(os.path.join("foo", "bar"), "foo"), "bar")
     self.assertEqual(relpath(os.path.join("foo", "bar", "baz"), "foo"), "bar/baz")
     self.assertEqual(relpath(os.path.join("foo", "bar"), "foo/bar/baz"), "..")
     self.assertEqual(relpath(os.path.join("foo", "bar"), "foo/baz"), "../bar")
     self.assertEqual(relpath("foo/", "foo"), "")
     self.assertEqual(relpath("foo/bar/", "foo"), "bar")
开发者ID:hibrium,项目名称:Pale-Moon,代码行数:9,代码来源:test_path.py

示例13: consume_object

    def consume_object(self, obj):
        if isinstance(obj, JARManifest) and obj.install_target.startswith("dist/bin"):
            self._consume_jar_manifest(obj)

        elif isinstance(obj, (FinalTargetFiles, FinalTargetPreprocessedFiles)) and obj.install_target.startswith(
            "dist/bin"
        ):
            defines = obj.defines or {}
            if defines:
                defines = defines.defines
            for path, files in obj.files.walk():
                for f in files:
                    if isinstance(obj, FinalTargetPreprocessedFiles):
                        self._add_preprocess(obj, f.full_path, path, target=f.target_basename, defines=defines)
                    elif "*" in f:

                        def _prefix(s):
                            for p in mozpath.split(s):
                                if "*" not in p:
                                    yield p + "/"

                        prefix = "".join(_prefix(f.full_path))

                        self._install_manifests[obj.install_target].add_pattern_symlink(
                            prefix, f.full_path[len(prefix) :], mozpath.join(path, f.target_basename)
                        )
                    else:
                        self._install_manifests[obj.install_target].add_symlink(
                            f.full_path, mozpath.join(path, f.target_basename)
                        )
                    if isinstance(f, ObjDirPath):
                        dep_target = "install-%s" % obj.install_target
                        self._dependencies[dep_target].append(mozpath.relpath(f.full_path, self.environment.topobjdir))

        elif isinstance(obj, ChromeManifestEntry) and obj.install_target.startswith("dist/bin"):
            top_level = mozpath.join(obj.install_target, "chrome.manifest")
            if obj.path != top_level:
                entry = "manifest %s" % mozpath.relpath(obj.path, obj.install_target)
                self._manifest_entries[top_level].add(entry)
            self._manifest_entries[obj.path].add(str(obj.entry))

        elif isinstance(obj, XPIDLFile):
            self._has_xpidl = True

        # We currently ignore a lot of object types, so just acknowledge
        # everything.
        return True
开发者ID:kilikkuo,项目名称:gecko-dev,代码行数:47,代码来源:fastermake.py

示例14: add_manifest

 def add_manifest(self, entry):
     if isinstance(entry, ManifestBinaryComponent):
         formatter, base = super(OmniJarFormatter, self), ''
     else:
         formatter, base, path = self._get_formatter(entry.base,
                                                     is_resource=True)
     entry = entry.move(mozpath.relpath(entry.base, base))
     formatter.add_manifest(entry)
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:8,代码来源:formats.py

示例15: contains

 def contains(self, path):
     assert '*' not in path
     if self.copier.contains(path):
         return True
     for base, copier in self.omnijars.iteritems():
         if copier.contains(mozpath.relpath(path, base)):
             return True
     return False
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:8,代码来源:formats.py


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