本文整理汇总了Python中mozpack.path.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了match函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: _find_glob
def _find_glob(self, base, pattern):
"""
Actual implementation of FileFinder.find() when the given pattern
contains globbing patterns ('*' or '**'). This is meant to be an
equivalent of:
for p, f in self:
if mozpath.match(p, pattern):
yield p, f
but avoids scanning the entire tree.
"""
if not pattern:
for p, f in self._find(base):
yield p, f
elif pattern[0] == "**":
for p, f in self._find(base):
if mozpath.match(p, mozpath.join(*pattern)):
yield p, f
elif "*" in pattern[0]:
if not os.path.exists(os.path.join(self.base, base)):
return
for p in self.ignore:
if mozpath.match(base, p):
return
# See above comment w.r.t. sorted() and idempotent behavior.
for p in sorted(os.listdir(os.path.join(self.base, base))):
if p.startswith(".") and not pattern[0].startswith("."):
continue
if mozpath.match(p, pattern[0]):
for p_, f in self._find_glob(mozpath.join(base, p), pattern[1:]):
yield p_, f
else:
for p, f in self._find_glob(mozpath.join(base, pattern[0]), pattern[1:]):
yield p, f
开发者ID:c0mmandCS,项目名称:Waterfox,代码行数:35,代码来源:files.py
示例3: 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
示例4: 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
示例5: match
def match(self, patterns):
a = mozpath.normsep(self.path)
for p in patterns:
if isinstance(p, FilterPath):
p = p.path
p = mozpath.normsep(p)
if mozpath.match(a, p):
return True
return False
开发者ID:luke-chang,项目名称:gecko-1,代码行数:9,代码来源:pathutils.py
示例6: get
def get(self, path):
srcpath = os.path.join(self.base, path)
if not os.path.lexists(srcpath):
return None
for p in self.ignore:
if mozpath.match(path, p):
return None
if self.find_executables and is_executable(srcpath):
return ExecutableFile(srcpath)
else:
return File(srcpath)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:13,代码来源:files.py
示例7: unify_file
def unify_file(self, path, file1, file2):
'''
Given two BaseFiles and the path they were found at, check whether
their content match and return the first BaseFile if they do.
'''
content1 = file1.open().readlines()
content2 = file2.open().readlines()
if content1 == content2:
return file1
for pattern in self._sorted:
if mozpath.match(path, pattern):
if sorted(content1) == sorted(content2):
return file1
break
return None
开发者ID:lazyparser,项目名称:gecko-dev,代码行数:15,代码来源:unify.py
示例8: 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
示例9: make_archive
def make_archive(archive_name, base, exclude, include, compress):
finder = FileFinder(base, ignore=exclude)
if not include:
include = ['*']
if not compress:
compress = ['**/*.sym']
archive_basename = os.path.basename(archive_name)
with open(archive_name, 'wb') as fh:
with JarWriter(fileobj=fh, optimize=False, compress_level=5) as writer:
for pat in include:
for p, f in finder.find(pat):
print(' Adding to "%s":\n\t"%s"' % (archive_basename, p))
should_compress = any(mozpath.match(p, pat) for pat in compress)
writer.add(p.encode('utf-8'), f, mode=f.mode,
compress=should_compress, skip_duplicates=True)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:15,代码来源:symbols_archive.py
示例10: _find_file
def _find_file(self, path):
'''
Actual implementation of FileFinder.find() when the given pattern
corresponds to an existing file under the base directory.
'''
srcpath = os.path.join(self.base, path)
if not os.path.exists(srcpath):
return
for p in self.ignore:
if mozpath.match(path, p):
return
if self.find_executables and is_executable(srcpath):
yield path, ExecutableFile(srcpath)
else:
yield path, File(srcpath)
开发者ID:html-shell,项目名称:mozbuild,代码行数:17,代码来源:files.py
示例11: 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:
for f in JarReader(filename):
if not any(mozpath.match(f.filename, p) for p in self.package_artifact_patterns):
continue
basename = mozpath.basename(f.filename)
self.log(logging.INFO, "artifact", {"basename": basename}, "Adding {basename} to processed archive")
writer.add(basename.encode("utf-8"), f)
added_entry = True
if not added_entry:
raise ValueError(
'Archive format changed! No pattern from "{patterns}"'
"matched an archive path.".format(patterns=self.artifact_patterns)
)
开发者ID:rlr,项目名称:gecko-dev,代码行数:17,代码来源:artifacts.py
示例12: process_artifact
def process_artifact(self, filename, processed_filename):
# Extract all .so files into the root, which will get copied into dist/bin.
with JarWriter(file=processed_filename, optimize=False, compress_level=5) as writer:
for p, f in UnpackFinder(JarFinder(filename, JarReader(filename))):
if not any(mozpath.match(p, pat) for pat in self.package_artifact_patterns):
continue
dirname, basename = os.path.split(p)
self.log(logging.INFO, 'artifact',
{'basename': basename},
'Adding {basename} to processed archive')
basedir = 'bin'
if not basename.endswith('.so'):
basedir = mozpath.join('bin', dirname.lstrip('assets/'))
basename = mozpath.join(basedir, basename)
writer.add(basename.encode('utf-8'), f.open())
开发者ID:subsevenx2001,项目名称:gecko-dev,代码行数:17,代码来源:artifacts.py
示例13: do_finder_test
def do_finder_test(self, finder):
self.assertTrue(finder.contains('foo/.foo'))
self.assertTrue(finder.contains('foo/.bar'))
self.assertTrue('foo/.foo' in [f for f, c in
finder.find('foo/.foo')])
self.assertTrue('foo/.bar/foo' in [f for f, c in
finder.find('foo/.bar')])
self.assertEqual(sorted([f for f, c in finder.find('foo/.*')]),
['foo/.bar/foo', 'foo/.foo'])
for pattern in ['foo', '**', '**/*', '**/foo', 'foo/*']:
self.assertFalse('foo/.foo' in [f for f, c in
finder.find(pattern)])
self.assertFalse('foo/.bar/foo' in [f for f, c in
finder.find(pattern)])
self.assertEqual(sorted([f for f, c in finder.find(pattern)]),
sorted([f for f, c in finder
if mozpath.match(f, pattern)]))
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:17,代码来源:test_files.py
示例14: _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
示例15: 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:
for f in JarReader(filename):
if not any(mozpath.match(f.filename, p) for p in self.package_artifact_patterns):
continue
# strip off the relative "firefox/" bit from the path:
basename = mozpath.relpath(f.filename, "firefox")
self.log(logging.INFO, 'artifact',
{'basename': basename},
'Adding {basename} to processed archive')
writer.add(basename.encode('utf-8'), f)
added_entry = True
if not added_entry:
raise ValueError('Archive format changed! No pattern from "{patterns}"'
'matched an archive path.'.format(
patterns=self.artifact_patterns))
开发者ID:LongyunZhang,项目名称:gecko-dev,代码行数:19,代码来源:artifacts.py
示例16: _find_dir
def _find_dir(self, path):
'''
Actual implementation of FileFinder.find() when the given pattern
corresponds to an existing directory under the base directory.
Ignores file names starting with a '.' under the given path. If the
path itself has leafs starting with a '.', they are not ignored.
'''
for p in self.ignore:
if mozpath.match(path, p):
return
# The sorted makes the output idempotent. Otherwise, we are
# likely dependent on filesystem implementation details, such as
# inode ordering.
for p in sorted(os.listdir(os.path.join(self.base, path))):
if p.startswith('.'):
continue
for p_, f in self._find(mozpath.join(path, p)):
yield p_, f
开发者ID:DINKIN,项目名称:Waterfox,代码行数:19,代码来源:files.py
示例17: files_info
def files_info(self, paths):
"""Obtain aggregate data from Files for a set of files.
Given a set of input paths, determine which moz.build files may
define metadata for them, evaluate those moz.build files, and
apply file metadata rules defined within to determine metadata
values for each file requested.
Essentially, for each input path:
1. Determine the set of moz.build files relevant to that file by
looking for moz.build files in ancestor directories.
2. Evaluate moz.build files starting with the most distant.
3. Iterate over Files sub-contexts.
4. If the file pattern matches the file we're seeking info on,
apply attribute updates.
5. Return the most recent value of attributes.
"""
paths, _ = self.read_relevant_mozbuilds(paths)
r = {}
for path, ctxs in paths.items():
flags = Files(Context())
for ctx in ctxs:
if not isinstance(ctx, Files):
continue
relpath = mozpath.relpath(path, ctx.relsrcdir)
pattern = ctx.pattern
# Only do wildcard matching if the '*' character is present.
# Otherwise, mozpath.match will match directories, which we've
# arbitrarily chosen to not allow.
if pattern == relpath or \
('*' in pattern and mozpath.match(relpath, pattern)):
flags += ctx
r[path] = flags
return r
开发者ID:LordJZ,项目名称:gecko-dev,代码行数:42,代码来源:reader.py
示例18: process_tests_artifact
def process_tests_artifact(self, filename, processed_filename):
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
if not added_entry:
raise ValueError(
'Archive format changed! No pattern from "{patterns}"'
"matched an archive path.".format(patterns=LinuxArtifactJob.test_artifact_patterns)
)
开发者ID:carriercomm,项目名称:gecko-dev,代码行数:21,代码来源:artifacts.py
示例19: _find_helper
def _find_helper(self, pattern, files, file_getter):
"""Generic implementation of _find.
A few *Finder implementations share logic for returning results.
This function implements the custom logic.
The ``file_getter`` argument is a callable that receives a path
that is known to exist. The callable should return a ``BaseFile``
instance.
"""
if '*' in pattern:
for p in files:
if mozpath.match(p, pattern):
yield p, file_getter(p)
elif pattern == '':
for p in files:
yield p, file_getter(p)
elif pattern in files:
yield pattern, file_getter(pattern)
else:
for p in files:
if mozpath.basedir(p, [pattern]) == pattern:
yield p, file_getter(p)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:23,代码来源:files.py
示例20: main
def main(args):
parser = argparse.ArgumentParser()
parser.add_argument("-C", metavar='DIR', default=".",
help="Change to given directory before considering "
"other paths")
parser.add_argument("--strip", action='store_true',
help="Strip executables")
parser.add_argument("-x", metavar='EXCLUDE', default=[], action='append',
help="Exclude files that match the pattern")
parser.add_argument("zip", help="Path to zip file to write")
parser.add_argument("input", nargs="+",
help="Path to files to add to zip")
args = parser.parse_args(args)
jarrer = Jarrer(optimize=False)
with errors.accumulate():
finder = FileFinder(args.C, find_executables=args.strip)
for path in args.input:
for p, f in finder.find(path):
if not any([match(p, exclude) for exclude in args.x]):
jarrer.add(p, f)
jarrer.copy(mozpath.join(args.C, args.zip))
开发者ID:luke-chang,项目名称:gecko-1,代码行数:23,代码来源:zip.py
注:本文中的mozpack.path.match函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论