• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python path.basedir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: is_read_allowed

def is_read_allowed(path, config):
    """Whether we are allowed to load a mozbuild file at the specified path.

    This is used as cheap security to ensure the build is isolated to known
    source directories.

    We are allowed to read from the main source directory and any defined
    external source directories. The latter is to allow 3rd party applications
    to hook into our build system.
    """
    assert os.path.isabs(path)
    assert os.path.isabs(config.topsrcdir)

    path = mozpath.normpath(path)
    topsrcdir = mozpath.normpath(config.topsrcdir)

    if mozpath.basedir(path, [topsrcdir]):
        return True

    if config.external_source_dir:
        external_dir = os.path.normcase(config.external_source_dir)
        norm_path = os.path.normcase(path)
        if mozpath.basedir(norm_path, [external_dir]):
            return True

    return False
开发者ID:c0mmandCS,项目名称:Waterfox,代码行数:26,代码来源:reader.py


示例2: test_basedir

 def test_basedir(self):
     foobarbaz = os.path.join("foo", "bar", "baz")
     self.assertEqual(basedir(foobarbaz, ["foo", "bar", "baz"]), "foo")
     self.assertEqual(basedir(foobarbaz, ["foo", "foo/bar", "baz"]), "foo/bar")
     self.assertEqual(basedir(foobarbaz, ["foo/bar", "foo", "baz"]), "foo/bar")
     self.assertEqual(basedir(foobarbaz, ["foo", "bar", ""]), "foo")
     self.assertEqual(basedir(foobarbaz, ["bar", "baz", ""]), "")
开发者ID:hibrium,项目名称:Pale-Moon,代码行数:7,代码来源:test_path.py


示例3: test_basedir

 def test_basedir(self):
     foobarbaz = os.path.join('foo', 'bar', 'baz')
     self.assertEqual(basedir(foobarbaz, ['foo', 'bar', 'baz']), 'foo')
     self.assertEqual(basedir(foobarbaz, ['foo', 'foo/bar', 'baz']),
                      'foo/bar')
     self.assertEqual(basedir(foobarbaz, ['foo/bar', 'foo', 'baz']),
                      'foo/bar')
     self.assertEqual(basedir(foobarbaz, ['foo', 'bar', '']), 'foo')
     self.assertEqual(basedir(foobarbaz, ['bar', 'baz', '']), '')
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:9,代码来源:test_path.py


示例4: test_basedir

 def test_basedir(self):
     foobarbaz = self.SEP.join(('foo', 'bar', 'baz'))
     self.assertEqual(basedir(foobarbaz, ['foo', 'bar', 'baz']), 'foo')
     self.assertEqual(basedir(foobarbaz, ['foo', 'foo/bar', 'baz']),
                      'foo/bar')
     self.assertEqual(basedir(foobarbaz, ['foo/bar', 'foo', 'baz']),
                      'foo/bar')
     self.assertEqual(basedir(foobarbaz, ['foo', 'bar', '']), 'foo')
     self.assertEqual(basedir(foobarbaz, ['bar', 'baz', '']), '')
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:9,代码来源:test_path.py


示例5: _chromepath

 def _chromepath(self, path):
     '''
     Return the chrome base directory under which the given path is. Used to
     detect under which .jar (if any) the path should go.
     '''
     self._frozen_chrome = True
     return mozpath.basedir(path, self._chrome)
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:7,代码来源:formats.py


示例6: _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


示例7: _add_manifest_file

 def _add_manifest_file(self, path, file):
     '''
     Add the given BaseFile with manifest file contents with the given path.
     '''
     self._manifests.add(path)
     base = ''
     if hasattr(file, 'path'):
         # Find the directory the given path is relative to.
         b = mozpath.normsep(file.path)
         if b.endswith('/' + path) or b == path:
             base = os.path.normpath(b[:-len(path)])
     for e in parse_manifest(base, path, file.open()):
         # ManifestResources need to be given after ManifestChrome, so just
         # put all ManifestChrome in a separate queue to make them first.
         if isinstance(e, ManifestChrome):
             # e.move(e.base) just returns a clone of the entry.
             self._chrome_queue.append(self.formatter.add_manifest,
                                       e.move(e.base))
         elif not isinstance(e, (Manifest, ManifestInterfaces)):
             self._queue.append(self.formatter.add_manifest, e.move(e.base))
         # If a binary component is added to an addon, prevent the addon
         # from being packed.
         if isinstance(e, ManifestBinaryComponent):
             addon = mozpath.basedir(e.base, self._addons)
             if addon:
                 self._addons[addon] = 'unpacked'
         if isinstance(e, Manifest):
             if e.flags:
                 errors.fatal('Flags are not supported on ' +
                              '"manifest" entries')
             self._included_manifests[e.path] = path
开发者ID:MekliCZ,项目名称:positron,代码行数:31,代码来源:__init__.py


示例8: include_file

    def include_file(self, path):
        '''Include one file in the sandbox. Users of this class probably want

        Note: this will execute all template invocations, as well as @depends
        functions that depend on '--help', but nothing else.
        '''

        if self._paths:
            path = mozpath.join(mozpath.dirname(self._paths[-1]), path)
            path = mozpath.normpath(path)
            if not mozpath.basedir(path, (mozpath.dirname(self._paths[0]),)):
                raise ConfigureError(
                    'Cannot include `%s` because it is not in a subdirectory '
                    'of `%s`' % (path, mozpath.dirname(self._paths[0])))
        else:
            path = mozpath.realpath(mozpath.abspath(path))
        if path in self._all_paths:
            raise ConfigureError(
                'Cannot include `%s` because it was included already.' % path)
        self._paths.append(path)
        self._all_paths.add(path)

        source = open(path, 'rb').read()

        code = compile(source, path, 'exec')

        exec_(code, self)

        self._paths.pop(-1)
开发者ID:lazyparser,项目名称:gecko-dev,代码行数:29,代码来源:__init__.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: isfile

 def isfile(self, path):
     path = mozpath.abspath(path)
     if path in self._paths:
         return True
     if mozpath.basedir(path, [topsrcdir, topobjdir]):
         return os.path.isfile(path)
     return False
开发者ID:mozilla,项目名称:positron-spidernode,代码行数:7,代码来源:common.py


示例11: _get_base

 def _get_base(self, path):
     '''
     Return the deepest base directory containing the given path.
     '''
     self._frozen_bases = True
     base = mozpath.basedir(path, self._sub_formatter.keys())
     relpath = mozpath.relpath(path, base) if base else path
     return base, relpath
开发者ID:mykmelez,项目名称:spidernode,代码行数:8,代码来源:formats.py


示例12: consume_finished

    def consume_finished(self):
        mk = Makefile()
        # Add the default rule at the very beginning.
        mk.create_rule(['default'])
        mk.add_statement('TOPSRCDIR = %s' % self.environment.topsrcdir)
        mk.add_statement('TOPOBJDIR = %s' % self.environment.topobjdir)
        mk.add_statement('BACKEND = %s' % self._backend_output_list_file)
        if not self._has_xpidl:
            mk.add_statement('NO_XPIDL = 1')

        # Add a few necessary variables inherited from configure
        for var in (
            'PYTHON',
            'ACDEFINES',
            'MOZ_BUILD_APP',
            'MOZ_WIDGET_TOOLKIT',
        ):
            mk.add_statement('%s = %s' % (var, self.environment.substs[var]))

        install_manifests_bases = self._install_manifests.keys()

        # Add information for chrome manifest generation
        manifest_targets = []

        for target, entries in self._manifest_entries.iteritems():
            manifest_targets.append(target)
            install_target = mozpath.basedir(target, install_manifests_bases)
            self._install_manifests[install_target].add_content(
                ''.join('%s\n' % e for e in sorted(entries)),
                mozpath.relpath(target, install_target))

        # Add information for install manifests.
        mk.add_statement('INSTALL_MANIFESTS = %s'
                         % ' '.join(self._install_manifests.keys()))

        # Add dependencies we infered:
        for target, deps in self._dependencies.iteritems():
            mk.create_rule([target]).add_dependencies(
                '$(TOPOBJDIR)/%s' % d for d in deps)

        # Add backend dependencies:
        mk.create_rule([self._backend_output_list_file]).add_dependencies(
            self.backend_input_files)

        mk.add_statement('include $(TOPSRCDIR)/config/faster/rules.mk')

        for base, install_manifest in self._install_manifests.iteritems():
            with self._write_file(
                    mozpath.join(self.environment.topobjdir, 'faster',
                                 'install_%s' % base.replace('/', '_'))) as fh:
                install_manifest.write(fileobj=fh)

        with self._write_file(
                mozpath.join(self.environment.topobjdir, 'faster',
                             'Makefile')) as fh:
            mk.dump(fh, removal_guard=False)
开发者ID:psvramaraju,项目名称:gecko-dev,代码行数:56,代码来源:fastermake.py


示例13: close

    def close(self):
        '''
        Push all instructions to the formatter.
        '''
        self._closed = True

        bases = self.get_bases()
        broken_bases = sorted(
            m for m, includer in self._included_manifests.iteritems()
            if mozpath.basedir(m, bases) != mozpath.basedir(includer, bases))
        for m in broken_bases:
            errors.fatal('"%s" is included from "%s", which is outside "%s"' %
                         (m, self._included_manifests[m],
                          mozpath.basedir(m, bases)))
        for base in sorted(bases):
            self.formatter.add_base(base, self._addons.get(base, False))
        self._chrome_queue.execute()
        self._queue.execute()
        self._file_queue.execute()
开发者ID:MekliCZ,项目名称:positron,代码行数:19,代码来源:__init__.py


示例14: add

    def add(self, t, flavor, topsrcdir):
        t = dict(t)
        t['flavor'] = flavor

        path = mozpath.normpath(t['path'])
        assert mozpath.basedir(path, [topsrcdir])

        key = path[len(topsrcdir)+1:]
        t['file_relpath'] = key
        t['dir_relpath'] = mozpath.dirname(key)

        self.tests_by_path[key].append(t)
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:12,代码来源:test_manifest.py


示例15: _get_files_info

    def _get_files_info(self, paths, rev=None):
        from mozbuild.frontend.reader import default_finder
        from mozpack.files import FileFinder, MercurialRevisionFinder

        # 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))

        repo = None
        if rev:
            hg_path = os.path.join(self.topsrcdir, '.hg')
            if not os.path.exists(hg_path):
                raise InvalidPathException('a Mercurial repo is required '
                        'when specifying a revision')

            repo = self.topsrcdir

        # We need two finders because the reader's finder operates on
        # absolute paths.
        finder = FileFinder(self.topsrcdir)
        if repo:
            reader_finder = MercurialRevisionFinder(repo, rev=rev,
                                                    recognize_repo_paths=True)
        else:
            reader_finder = default_finder

        # Expand wildcards.
        # One variable is for ordering. The other for membership tests.
        # (Membership testing on a list can be slow.)
        allpaths = []
        all_paths_set = set()
        for p in relpaths:
            if '*' not in p:
                if p not in all_paths_set:
                    all_paths_set.add(p)
                    allpaths.append(p)
                continue

            if repo:
                raise InvalidPathException('cannot use wildcard in version control mode')

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

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


示例16: match

 def match(self, pattern):
     '''
     Return the list of paths, stored in the container, matching the
     given pattern. See the mozpack.path.match documentation for a
     description of the handled patterns.
     '''
     if '*' in pattern:
         return [p for p in self.paths()
                 if mozpath.match(p, pattern)]
     if pattern == '':
         return self.paths()
     if pattern in self._files:
         return [pattern]
     return [p for p in self.paths()
             if mozpath.basedir(p, [pattern]) == pattern]
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:15,代码来源:copier.py


示例17: add

    def add(self, t, flavor=None, topsrcdir=None):
        t = dict(t)
        t["flavor"] = flavor

        if topsrcdir is None:
            topsrcdir = self.topsrcdir
        else:
            topsrcdir = mozpath.normpath(topsrcdir)

        path = mozpath.normpath(t["path"])
        assert mozpath.basedir(path, [topsrcdir])

        key = path[len(topsrcdir) + 1 :]
        t["file_relpath"] = key
        t["dir_relpath"] = mozpath.dirname(key)

        self.tests_by_path[key].append(t)
开发者ID:ajkerrigan,项目名称:gecko-dev,代码行数:17,代码来源:common.py


示例18: _find_relevant_mozbuilds

    def _find_relevant_mozbuilds(self, paths):
        """Given a set of filesystem paths, find all relevant moz.build files.

        We assume that a moz.build file in the directory ancestry of a given path
        is relevant to that path. Let's say we have the following files on disk::

           moz.build
           foo/moz.build
           foo/baz/moz.build
           foo/baz/file1
           other/moz.build
           other/file2

        If ``foo/baz/file1`` is passed in, the relevant moz.build files are
        ``moz.build``, ``foo/moz.build``, and ``foo/baz/moz.build``. For
        ``other/file2``, the relevant moz.build files are ``moz.build`` and
        ``other/moz.build``.

        Returns a dict of input paths to a list of relevant moz.build files.
        The root moz.build file is first and the leaf-most moz.build is last.
        """
        root = self.config.topsrcdir
        result = {}

        @memoize
        def exists(path):
            return os.path.exists(path)

        def itermozbuild(path):
            subpath = ''
            yield 'moz.build'
            for part in mozpath.split(path):
                subpath = mozpath.join(subpath, part)
                yield mozpath.join(subpath, 'moz.build')

        for path in sorted(paths):
            path = mozpath.normpath(path)
            if os.path.isabs(path):
                if not mozpath.basedir(path, [root]):
                    raise Exception('Path outside topsrcdir: %s' % path)
                path = mozpath.relpath(path, root)

            result[path] = [p for p in itermozbuild(path)
                              if exists(mozpath.join(root, p))]

        return result
开发者ID:LordJZ,项目名称:gecko-dev,代码行数:46,代码来源:reader.py


示例19: _find

 def _find(self, pattern):
     '''
     Actual implementation of JarFinder.find(), dispatching to specialized
     member functions depending on what kind of pattern was given.
     '''
     if '*' in pattern:
         for p in self._files:
             if mozpath.match(p, pattern):
                 yield p, DeflatedFile(self._files[p])
     elif pattern == '':
         for p in self._files:
             yield p, DeflatedFile(self._files[p])
     elif pattern in self._files:
         yield pattern, DeflatedFile(self._files[pattern])
     else:
         for p in self._files:
             if mozpath.basedir(p, [pattern]) == pattern:
                 yield p, DeflatedFile(self._files[p])
开发者ID:html-shell,项目名称:mozbuild,代码行数:18,代码来源:files.py


示例20: _get_files_info

    def _get_files_info(self, paths, rev=None):
        reader = self.mozbuild_reader(config_mode='empty', vcs_revision=rev)

        # 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))

        # Expand wildcards.
        # One variable is for ordering. The other for membership tests.
        # (Membership testing on a list can be slow.)
        allpaths = []
        all_paths_set = set()
        for p in relpaths:
            if '*' not in p:
                if p not in all_paths_set:
                    if not os.path.exists(mozpath.join(self.topsrcdir, p)):
                        print('(%s does not exist; ignoring)' % p,
                              file=sys.stderr)
                        continue

                    all_paths_set.add(p)
                    allpaths.append(p)
                continue

            if rev:
                raise InvalidPathException('cannot use wildcard in version control mode')

            # finder is rooted at / for now.
            # TODO bug 1171069 tracks changing to relative.
            search = mozpath.join(self.topsrcdir, p)[1:]
            for path, f in reader.finder.find(search):
                path = path[len(self.topsrcdir):]
                if path not in all_paths_set:
                    all_paths_set.add(path)
                    allpaths.append(path)

        return reader.files_info(allpaths)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:42,代码来源:mach_commands.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python path.basename函数代码示例发布时间:2022-05-27
下一篇:
Python path.abspath函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap