本文整理汇总了Python中mozpack.path.normpath函数的典型用法代码示例。如果您正苦于以下问题:Python normpath函数的具体用法?Python normpath怎么用?Python normpath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normpath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: normalize_path
def normalize_path(self, path, filesystem_absolute=False, srcdir=None):
"""Normalizes paths.
If the path is absolute, behavior is governed by filesystem_absolute.
If filesystem_absolute is True, the path is interpreted as absolute on
the actual filesystem. If it is false, the path is treated as absolute
within the current topsrcdir.
If the path is not absolute, it will be treated as relative to the
currently executing file. If there is no currently executing file, it
will be treated as relative to topsrcdir.
"""
if os.path.isabs(path):
if filesystem_absolute:
return path
for root in [self.topsrcdir] + self.external_source_dirs:
# mozpath.join would ignore the self.topsrcdir argument if we
# passed in the absolute path, so omit the leading /
p = mozpath.normpath(mozpath.join(root, path[1:]))
if os.path.exists(p):
return p
# mozpath.join would ignore the self.topsrcdir argument if we passed
# in the absolute path, so omit the leading /
return mozpath.normpath(mozpath.join(self.topsrcdir, path[1:]))
elif srcdir:
return mozpath.normpath(mozpath.join(srcdir, path))
elif len(self._execution_stack):
return mozpath.normpath(mozpath.join(
mozpath.dirname(self._execution_stack[-1]), path))
else:
return mozpath.normpath(mozpath.join(self.topsrcdir, path))
示例2: handle_manifest_entry
def handle_manifest_entry(self, entry):
format_strings = {
"content": "chrome://%s/content/",
"resource": "resource://%s/",
"locale": "chrome://%s/locale/",
"skin": "chrome://%s/skin/",
}
if isinstance(entry, (ManifestChrome, ManifestResource)):
if isinstance(entry, ManifestResource):
dest = entry.target
url = urlparse.urlparse(dest)
if not url.scheme:
dest = mozpath.normpath(mozpath.join(entry.base, dest))
if url.scheme == 'file':
dest = mozpath.normpath(url.path)
else:
dest = mozpath.normpath(entry.path)
base_uri = format_strings[entry.type] % entry.name
self.chrome_mapping[base_uri].add(dest)
if isinstance(entry, ManifestOverride):
self.overrides[entry.overloaded] = entry.overload
if isinstance(entry, Manifest):
for e in parse_manifest(None, entry.path):
self.handle_manifest_entry(e)
示例3: rewrite_url
def rewrite_url(self, url):
# This applies one-off rules and returns None for urls that we aren't
# going to be able to resolve to a source file ("about:" urls, for
# instance).
if url in self._final_mapping:
return self._final_mapping[url]
if url.endswith('> eval'):
return None
if url.endswith('> Function'):
return None
if ' -> ' in url:
url = url.split(' -> ')[1].rstrip()
if '?' in url:
url = url.split('?')[0]
url_obj = urlparse.urlparse(url)
if url_obj.scheme == 'jar':
app_name = self.MOZ_APP_NAME
omnijar_name = self.OMNIJAR_NAME
if app_name in url:
if omnijar_name in url:
# e.g. file:///home/worker/workspace/build/application/firefox/omni.ja!/components/MainProcessSingleton.js
parts = url_obj.path.split(omnijar_name + '!', 1)
elif '.xpi!' in url:
# e.g. file:///home/worker/workspace/build/application/firefox/browser/features/[email protected]!/bootstrap.js
parts = url_obj.path.split('.xpi!', 1)
else:
# We don't know how to handle this jar: path, so return it to the
# caller to make it print a warning.
return url_obj.path, None
dir_parts = parts[0].rsplit(app_name + '/', 1)
url = mozpath.normpath(mozpath.join(self.topobjdir, 'dist', 'bin', dir_parts[1].lstrip('/'), parts[1].lstrip('/')))
elif '.xpi!' in url:
# e.g. file:///tmp/tmpMdo5gV.mozrunner/extensions/[email protected]!/bootstrap.js
# This matching mechanism is quite brittle and based on examples seen in the wild.
# There's no rule to match the XPI name to the path in dist/xpi-stage.
parts = url_obj.path.split('.xpi!', 1)
addon_name = os.path.basename(parts[0])
if '[email protected]' in addon_name:
addon_name = addon_name[:-len('[email protected]')]
elif addon_name.endswith('@mozilla.org'):
addon_name = addon_name[:-len('@mozilla.org')]
url = mozpath.normpath(mozpath.join(self.topobjdir, 'dist', 'xpi-stage', addon_name, parts[1].lstrip('/')))
elif url_obj.scheme == 'file' and os.path.isabs(url_obj.path):
path = url_obj.path
if not os.path.isfile(path):
# This may have been in a profile directory that no
# longer exists.
return None
if not path.startswith(self.topobjdir):
return path, None
url = url_obj.path
elif url_obj.scheme in ('http', 'https', 'javascript', 'data', 'about'):
return None
result = self.find_files(url)
self._final_mapping[url] = result
return result
示例4: 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
示例5: test_include_failures
def test_include_failures(self):
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('include("../foo.configure")'):
self.get_config()
self.assertEquals(
e.exception.message,
'Cannot include `%s` because it is not in a subdirectory of `%s`'
% (mozpath.normpath(mozpath.join(test_data_path, '..',
'foo.configure')),
mozpath.normsep(test_data_path))
)
with self.assertRaises(ConfigureError) as e:
with self.moz_configure('''
include('extra.configure')
include('extra.configure')
'''):
self.get_config()
self.assertEquals(
e.exception.message,
'Cannot include `%s` because it was included already.'
% mozpath.normpath(mozpath.join(test_data_path,
'extra.configure'))
)
with self.assertRaises(TypeError) as e:
with self.moz_configure('''
include(42)
'''):
self.get_config()
self.assertEquals(e.exception.message, "Unexpected type: 'int'")
示例6: 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 path.startswith(topsrcdir):
return True
external_dirs = config.substs.get('EXTERNAL_SOURCE_DIR', '').split()
for external in external_dirs:
if not os.path.isabs(external):
external = mozpath.join(config.topsrcdir, external)
external = mozpath.normpath(external)
if path.startswith(external):
return True
return False
示例7: __init__
def __init__(self, srcdir, objdir, fix):
self.srcdir = mozpath.normpath(srcdir)
self.objdir = mozpath.normpath(objdir)
self.srcdir_mount = self.getmount(self.srcdir)
self.objdir_mount = self.getmount(self.objdir)
self.path_mounts = [
('srcdir', self.srcdir, self.srcdir_mount),
('objdir', self.objdir, self.objdir_mount)
]
self.fix = fix
self.results = []
示例8: output_to_inputs_tree
def output_to_inputs_tree(self):
'''
Return a dictionary mapping each output path to the set of its
required input paths.
All paths are normalized.
'''
tree = {}
for output, file in self:
output = mozpath.normpath(output)
tree[output] = set(mozpath.normpath(f) for f in file.inputs())
return tree
示例9: test_config_file_substitution
def test_config_file_substitution(self):
reader = self.reader("config-file-substitution")
objs = self.read_topsrcdir(reader)
self.assertEqual(len(objs), 2)
self.assertIsInstance(objs[0], ConfigFileSubstitution)
self.assertIsInstance(objs[1], ConfigFileSubstitution)
topobjdir = mozpath.abspath(reader.config.topobjdir)
self.assertEqual(objs[0].relpath, "foo")
self.assertEqual(mozpath.normpath(objs[0].output_path), mozpath.normpath(mozpath.join(topobjdir, "foo")))
self.assertEqual(mozpath.normpath(objs[1].output_path), mozpath.normpath(mozpath.join(topobjdir, "bar")))
示例10: input_to_outputs_tree
def input_to_outputs_tree(self):
'''
Return a dictionary mapping each input path to the set of
impacted output paths.
All paths are normalized.
'''
tree = defaultdict(set)
for output, file in self:
output = mozpath.normpath(output)
for input in file.inputs():
input = mozpath.normpath(input)
tree[input].add(output)
return dict(tree)
示例11: _get_backend_file
def _get_backend_file(self, relobjdir):
objdir = mozpath.normpath(mozpath.join(self.environment.topobjdir, relobjdir))
if objdir not in self._backend_files:
self._backend_files[objdir] = \
BackendTupfile(objdir, self.environment,
self.environment.topsrcdir, self.environment.topobjdir)
return self._backend_files[objdir]
示例12: add_manifest
def add_manifest(self, entry):
# Store manifest entries in a single manifest per directory, named
# after their parent directory, except for root manifests, all named
# chrome.manifest.
if entry.base:
name = mozpath.basename(entry.base)
else:
name = 'chrome'
path = mozpath.normpath(mozpath.join(entry.base, '%s.manifest' % name))
if not self.copier.contains(path):
# Add a reference to the manifest file in the parent manifest, if
# the manifest file is not a root manifest.
if entry.base:
parent = mozpath.dirname(entry.base)
relbase = mozpath.basename(entry.base)
relpath = mozpath.join(relbase,
mozpath.basename(path))
self.add_manifest(Manifest(parent, relpath))
self.copier.add(path, ManifestFile(entry.base))
if isinstance(entry, ManifestChrome):
data = self._chrome_db.setdefault(entry.name, {})
entries = data.setdefault(entry.type, [])
for e in entries:
# Ideally, we'd actually check whether entry.flags are more
# specific than e.flags, but in practice the following test
# is enough for now.
if not entry.flags or e.flags and entry.flags == e.flags:
errors.fatal('"%s" overrides "%s"' % (entry, e))
entries.append(entry)
self.copier[path].add(entry)
示例13: addDependencies
def addDependencies(self, target, deps):
if not target in self.newDeps:
self.newDeps[target] = set()
for p in deps:
p = mozpath.normpath(p)
self.newDeps[target].add(p)
self.sourceFiles.add(p)
示例14: _process_files
def _process_files(self, obj, files, target, preprocessor = False, marker='#', target_is_file=False, optional=False):
for f in files:
if optional:
full_dest = f
elif target_is_file:
full_dest = target
else:
full_dest = mozpath.join(target, mozpath.basename(f))
install_manifest, dest = self._get_manifest_from_target(full_dest)
source = None if (obj is None) else mozpath.normpath(mozpath.join(obj.srcdir, f))
if preprocessor:
dep_file = mozpath.join(self.dep_path, target, mozpath.basename(f) +'.pp')
exist_defines = self._paths_to_defines.get(obj.srcdir, {})
xul_defines = dict(exist_defines)
for flag in self.XULPPFLAGS:
if flag.startswith('-D'):
define = flag[2:].split('=')
xul_defines[define[0]] = define[1] if len(define) >= 2 else ''
defines = compute_defines(obj.config, defines = xul_defines)
new_marker = marker
if marker == 'jar':
new_marker = '%' if f.endswith('.css') else '#'
install_manifest.add_preprocess(source, dest, dep_file, marker=new_marker, defines=defines)
elif optional:
install_manifest.add_optional_exists(dest)
else:
install_manifest.add_symlink(source, dest)
示例15: _add_entry
def _add_entry(self, dest, entry, normlize_dest=True):
if normlize_dest:
dest = mozpath.normpath(dest)
if dest in self._dests:
raise ValueError("Item already in manifest: %s" % dest)
self._dests[dest] = entry