本文整理汇总了Python中mozpack.files.FileFinder类的典型用法代码示例。如果您正苦于以下问题:Python FileFinder类的具体用法?Python FileFinder怎么用?Python FileFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileFinder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_generated_sources
def get_generated_sources():
'''
Yield tuples of `(objdir-rel-path, file)` for generated source files
in this objdir, where `file` is either an absolute path to the file or
a `mozpack.File` instance.
'''
import buildconfig
# First, get the list of generated sources produced by the build backend.
gen_sources = os.path.join(buildconfig.topobjdir, 'generated-sources.json')
with open(gen_sources, 'rb') as f:
data = json.load(f)
for f in data['sources']:
yield f, mozpath.join(buildconfig.topobjdir, f)
# Next, return all the files in $objdir/ipc/ipdl/_ipdlheaders.
base = 'ipc/ipdl/_ipdlheaders'
finder = FileFinder(mozpath.join(buildconfig.topobjdir, base))
for p, f in finder.find('**/*.h'):
yield mozpath.join(base, p), f
# Next, return any Rust source files that were generated into the Rust
# object directory.
rust_build_kind = 'debug' if buildconfig.substs.get('MOZ_DEBUG_RUST') else 'release'
base = mozpath.join('toolkit/library',
buildconfig.substs['RUST_TARGET'],
rust_build_kind,
'build')
finder = FileFinder(mozpath.join(buildconfig.topobjdir, base))
for p, f in finder.find('**/*.rs'):
yield mozpath.join(base, p), f
开发者ID:luke-chang,项目名称:gecko-1,代码行数:29,代码来源:generated_sources.py
示例2: walk_topsrcdir
def walk_topsrcdir(self):
"""Read all moz.build files in the source tree.
This is different from read_topsrcdir() in that this version performs a
filesystem walk to discover every moz.build file rather than relying on
data from executed moz.build files to drive traversal.
This is a generator of Sandbox instances.
"""
# In the future, we may traverse moz.build files by looking
# for DIRS references in the AST, even if a directory is added behind
# a conditional. For now, just walk the filesystem.
ignore = {
# Ignore fake moz.build files used for testing moz.build.
'python/mozbuild/mozbuild/test',
# Ignore object directories.
'obj*',
}
finder = FileFinder(self.topsrcdir, find_executables=False,
ignore=ignore)
for path, f in finder.find('**/moz.build'):
path = os.path.join(self.topsrcdir, path)
for s in self.read_mozbuild(path, self.config, descend=False,
filesystem_absolute=True, read_tiers=True):
yield s
开发者ID:chenhequn,项目名称:gecko,代码行数:28,代码来源:reader.py
示例3: resolve_files
def resolve_files():
"""Resolve the files that constitute a standalone toolchain.
This is a generator of (dest path, file) where the destination
path is relative and the file instance is a BaseFile from mozpack.
"""
vs_path, sdk_path = find_vs_paths()
for entry in VS_PATTERNS:
finder = FileFinder(vs_path, find_executables=False,
ignore=entry.get('ignore', []))
for p, f in finder.find(entry['pattern']):
assert p.startswith(('VC/', 'DIA SDK/'))
for source, dest in entry.get('rewrite', []):
p = p.replace(source, dest)
yield p.encode('utf-8'), f
for entry in SDK_PATTERNS:
finder = FileFinder(sdk_path, find_executables=False,
ignore=entry.get('ignore', []))
for p, f in finder.find(entry['pattern']):
# We remove the SDK version from the path so we don't have
# to update other configs when we change the SDK version.
p = p.replace('/%s/' % SDK_RELEASE, '/')
relpath = 'SDK/%s' % p
yield relpath.encode('utf-8'), f
开发者ID:Fischer-L,项目名称:gecko-b2g,代码行数:29,代码来源:windows_toolchain.py
示例4: package_geckoview_aar
def package_geckoview_aar(topsrcdir, distdir, appname, output_file):
jarrer = Jarrer(optimize=False)
app_path = os.path.join(distdir, appname)
assets = FileFinder(os.path.join(app_path, 'assets'), ignore=['*.so'])
for p, f in assets.find('omni.ja'):
jarrer.add(os.path.join('assets', p), f)
# The folder that contains Fennec's JAR files and resources.
base_path = os.path.join(distdir, '..', 'mobile', 'android', 'base')
# The resource set is packaged during Fennec's build.
resjar = JarReader(os.path.join(base_path, 'geckoview_resources.zip'))
for p, f in JarFinder(base_path, resjar).find('*'):
jarrer.add(os.path.join('res', p), f)
# Package the contents of all Fennec JAR files into classes.jar.
classes_jar_file = _generate_geckoview_classes_jar(distdir, base_path)
jarrer.add('classes.jar', classes_jar_file)
# Add R.txt.
jarrer.add('R.txt', File(os.path.join(base_path, 'R.txt')))
# Finally add AndroidManifest.xml.
srcdir = os.path.join(topsrcdir, 'mobile', 'android', 'geckoview_library', 'geckoview')
jarrer.add('AndroidManifest.xml', File(os.path.join(srcdir, 'AndroidManifest.xml')))
jarrer.copy(output_file)
return 0
开发者ID:kleopatra999,项目名称:system-addons,代码行数:28,代码来源:package_geckolibs_aar.py
示例5: find_files
def find_files(archive):
for entry in ARCHIVE_FILES[archive]:
source = entry['source']
base = entry.get('base', '')
pattern = entry.get('pattern')
patterns = entry.get('patterns', [])
if pattern:
patterns.append(pattern)
dest = entry.get('dest')
ignore = list(entry.get('ignore', []))
ignore.append('**/.mkdir.done')
ignore.append('**/*.pyc')
common_kwargs = {
'find_executables': False,
'find_dotfiles': True,
'ignore': ignore,
}
finder = FileFinder(os.path.join(source, base), **common_kwargs)
for pattern in patterns:
for p, f in finder.find(pattern):
if dest:
p = mozpath.join(dest, p)
yield p, f
开发者ID:brendandahl,项目名称:positron,代码行数:26,代码来源:test_archive.py
示例6: all_mozbuild_paths
def all_mozbuild_paths(self):
"""Iterator over all available moz.build files.
This method has little to do with the reader. It should arguably belong
elsewhere.
"""
# In the future, we may traverse moz.build files by looking
# for DIRS references in the AST, even if a directory is added behind
# a conditional. For now, just walk the filesystem.
ignore = {
# Ignore fake moz.build files used for testing moz.build.
'python/mozbuild/mozbuild/test',
# Ignore object directories.
'obj*',
}
finder = FileFinder(self.config.topsrcdir, find_executables=False,
ignore=ignore)
# The root doesn't get picked up by FileFinder.
yield 'moz.build'
for path, f in finder.find('**/moz.build'):
yield path
开发者ID:LordJZ,项目名称:gecko-dev,代码行数:25,代码来源:reader.py
示例7: explode
def explode(aar, destdir):
# Take just the support-v4-22.2.1 part.
name, _ = os.path.splitext(os.path.basename(aar))
destdir = mozpath.join(destdir, name)
if os.path.exists(destdir):
# We always want to start fresh.
shutil.rmtree(destdir)
ensureParentDir(destdir)
with zipfile.ZipFile(aar) as zf:
zf.extractall(destdir)
# classes.jar is always present. However, multiple JAR files with the same
# name confuses our staged Proguard process in
# mobile/android/base/Makefile.in, so we make the names unique here.
classes_jar = mozpath.join(destdir, name + '-classes.jar')
os.rename(mozpath.join(destdir, 'classes.jar'), classes_jar)
# Embedded JAR libraries are optional.
finder = FileFinder(mozpath.join(destdir, 'libs'))
for p, _ in finder.find('*.jar'):
jar = mozpath.join(finder.base, name + '-' + p)
os.rename(mozpath.join(finder.base, p), jar)
# Frequently assets/ is present but empty. Protect against meaningless
# changes to the AAR files by deleting empty assets/ directories.
assets = mozpath.join(destdir, 'assets')
try:
os.rmdir(assets)
except OSError, e:
if e.errno in (errno.ENOTEMPTY, errno.ENOENT):
pass
else:
raise
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:34,代码来源:explode_aar.py
示例8: update_uuids
def update_uuids(self, path, interfaces):
import os
import xpidl
from mozpack.files import FileFinder
import mozpack.path
from tempfile import mkdtemp
finder = FileFinder(path, find_executables=False)
# Avoid creating xpidllex and xpidlyacc in the current directory.
tmpdir = mkdtemp()
try:
parser = xpidl.IDLParser(outputdir=tmpdir)
registry = InterfaceRegistry()
for p, f in finder.find('**/*.idl'):
p = mozpack.path.join(path, p)
try:
content = f.open().read()
idl = parser.parse(content, filename=p)
except Exception:
continue
for prod in idl.productions:
if isinstance(prod, xpidl.Interface):
registry.add(Interface(p, prod))
finally:
import shutil
shutil.rmtree(tmpdir)
updates = IDLUpdater(registry)
for interface in interfaces:
updates.add(interface)
updates.update()
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:33,代码来源:mach_commands.py
示例9: _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
示例10: distribution_files
def distribution_files(root):
"""Find all files suitable for distributing.
Given the path to generated Sphinx documentation, returns an iterable
of (path, BaseFile) for files that should be archived, uploaded, etc.
Paths are relative to given root directory.
"""
finder = FileFinder(root, ignore=('_staging', '_venv'))
return finder.find('**')
开发者ID:luke-chang,项目名称:gecko-1,代码行数:9,代码来源:__init__.py
示例11: test_get
def test_get(self):
self.prepare_match_test()
finder = FileFinder(self.tmpdir)
self.assertIsNone(finder.get('does-not-exist'))
res = finder.get('bar')
self.assertIsInstance(res, File)
self.assertEqual(mozpath.normpath(res.path),
mozpath.join(self.tmpdir, 'bar'))
开发者ID:MekliCZ,项目名称:positron,代码行数:9,代码来源:test_files.py
示例12: package_gcno_tree
def package_gcno_tree(root, output_file):
# XXX JarWriter doesn't support unicode strings, see bug 1056859
if isinstance(root, unicode):
root = root.encode('utf-8')
finder = FileFinder(root)
jarrer = Jarrer(optimize=False)
for p, f in finder.find("**/*.gcno"):
jarrer.add(p, f)
jarrer.copy(output_file)
开发者ID:MekliCZ,项目名称:positron,代码行数:10,代码来源:packager.py
示例13: _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
示例14: test_add_from_finder
def test_add_from_finder(self):
s = MockDest()
with JarWriter(fileobj=s, optimize=self.optimize) as jar:
finder = FileFinder(test_data_path)
for p, f in finder.find('test_data'):
jar.add('test_data', f)
jar = JarReader(fileobj=s)
files = [j for j in jar]
self.assertEqual(files[0].filename, 'test_data')
self.assertFalse(files[0].compressed)
self.assertEqual(files[0].read(), 'test_data')
开发者ID:MekliCZ,项目名称:positron,代码行数:13,代码来源:test_mozjar.py
示例15: 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
示例16: _generate_geckoview_classes_jar
def _generate_geckoview_classes_jar(distdir, base_path):
base_folder = FileFinder(base_path, ignore=['gecko-R.jar'])
# Unzip all jar files into $(DISTDIR)/geckoview_aar_classes.
geckoview_aar_classes_path = os.path.join(distdir, 'geckoview_aar_classes')
shutil.rmtree(geckoview_aar_classes_path, ignore_errors=True)
util.ensureParentDir(geckoview_aar_classes_path)
for p, f in base_folder.find('*.jar'):
with zipfile.ZipFile(f.path) as zf:
zf.extractall(geckoview_aar_classes_path)
# Rezip them into a single classes.jar file.
classes_jar_path = os.path.join(distdir, 'classes.jar')
_zipdir(geckoview_aar_classes_path, classes_jar_path)
return File(classes_jar_path)
开发者ID:kleopatra999,项目名称:system-addons,代码行数:16,代码来源:package_geckolibs_aar.py
示例17: __init__
def __init__(self, base1, base2, sorted=[], **kargs):
'''
Initialize a UnifiedFinder. base1 and base2 are the base directories
for the two trees from which files are picked. UnifiedFinder.find()
will act as FileFinder.find() but will error out when matches can only
be found in one of the two trees and not the other. It will also error
out if matches can be found on both ends but their contents are not
identical.
The sorted argument gives a list of mozpack.path.match patterns. File
paths matching one of these patterns will have their contents compared
with their lines sorted.
'''
self._base1 = FileFinder(base1, **kargs)
self._base2 = FileFinder(base2, **kargs)
self._sorted = sorted
开发者ID:multi-sim,项目名称:releases-mozilla-central,代码行数:16,代码来源:unify.py
示例18: _handle_manifest_entry
def _handle_manifest_entry(self, entry, jars):
jarpath = None
if isinstance(entry, ManifestEntryWithRelPath) and \
urlparse(entry.relpath).scheme == 'jar':
jarpath, entry = self._unjarize(entry, entry.relpath)
elif isinstance(entry, ManifestResource) and \
urlparse(entry.target).scheme == 'jar':
jarpath, entry = self._unjarize(entry, entry.target)
if jarpath:
# Don't defer unpacking the jar file. If we already saw
# it, take (and remove) it from the registry. If we
# haven't, try to find it now.
if self.files.contains(jarpath):
jar = self.files[jarpath]
self.files.remove(jarpath)
else:
jar = [f for p, f in FileFinder.find(self, jarpath)]
assert len(jar) == 1
jar = jar[0]
if not jarpath in jars:
base = mozpack.path.splitext(jarpath)[0]
for j in self._open_jar(jarpath, jar):
self.files.add(mozpack.path.join(base,
j.filename),
DeflatedFile(j))
jars.add(jarpath)
self.kind = 'jar'
return entry
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:28,代码来源:unpack.py
示例19: __init__
def __init__(self, *args, **kargs):
FileFinder.__init__(self, *args, **kargs)
self.files = FileRegistry()
self.kind = 'flat'
self.omnijar = None
self.jarlogs = {}
self.optimizedjars = False
self.compressed = True
jars = set()
for p, f in FileFinder.find(self, '*'):
# Skip the precomplete file, which is generated at packaging time.
if p == 'precomplete':
continue
base = mozpath.dirname(p)
# If the file is a zip/jar that is not a .xpi, and contains a
# chrome.manifest, it is an omnijar. All the files it contains
# go in the directory containing the omnijar. Manifests are merged
# if there is a corresponding manifest in the directory.
if not p.endswith('.xpi') and self._maybe_zip(f) and \
(mozpath.basename(p) == self.omnijar or
not self.omnijar):
jar = self._open_jar(p, f)
if 'chrome.manifest' in jar:
self.kind = 'omni'
self.omnijar = mozpath.basename(p)
self._fill_with_jar(base, jar)
continue
# If the file is a manifest, scan its entries for some referencing
# jar: urls. If there are some, the files contained in the jar they
# point to, go under a directory named after the jar.
if is_manifest(p):
m = self.files[p] if self.files.contains(p) \
else ManifestFile(base)
for e in parse_manifest(self.base, p, f.open()):
m.add(self._handle_manifest_entry(e, jars))
if self.files.contains(p):
continue
f = m
# If the file is a packed addon, unpack it under a directory named
# after the xpi.
if p.endswith('.xpi') and self._maybe_zip(f):
self._fill_with_jar(p[:-4], self._open_jar(p, f))
continue
if not p in jars:
self.files.add(p, f)
开发者ID:brendandahl,项目名称:positron,代码行数:47,代码来源:unpack.py
示例20: process_manifest
def process_manifest(
destdir,
paths,
track=None,
remove_unaccounted=True,
remove_all_directory_symlinks=True,
remove_empty_directories=True,
defines={},
):
if track:
if os.path.exists(track):
# We use the same format as install manifests for the tracking
# data.
manifest = InstallManifest(path=track)
remove_unaccounted = FileRegistry()
dummy_file = BaseFile()
finder = FileFinder(destdir, find_executables=False, find_dotfiles=True)
for dest in manifest._dests:
for p, f in finder.find(dest):
remove_unaccounted.add(p, dummy_file)
else:
# If tracking is enabled and there is no file, we don't want to
# be removing anything.
remove_unaccounted = False
remove_empty_directories = False
remove_all_directory_symlinks = False
manifest = InstallManifest()
for path in paths:
manifest |= InstallManifest(path=path)
copier = FileCopier()
manifest.populate_registry(copier, defines_override=defines)
result = copier.copy(
destdir,
remove_unaccounted=remove_unaccounted,
remove_all_directory_symlinks=remove_all_directory_symlinks,
remove_empty_directories=remove_empty_directories,
)
if track:
manifest.write(path=track)
return result
开发者ID:ajkerrigan,项目名称:gecko-dev,代码行数:47,代码来源:process_install_manifest.py
注:本文中的mozpack.files.FileFinder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论