class TestComposedFinder(MatchTestTemplate, TestWithTmpDir): def add(self, path, content=None): # Put foo/qux files under $tmp/b. if path.startswith("foo/qux/"): real_path = mozpath.join("b", path[8:]) else: real_path = mozpath.join("a", path) ensureParentDir(self.tmppath(real_path)) if not content: content = six.ensure_binary(path) open(self.tmppath(real_path), "wb").write(content) def do_check(self, pattern, result): if "*" in pattern: return do_check(self, self.finder, pattern, result) def test_composed_finder(self): self.prepare_match_test() # Also add files in $tmp/a/foo/qux because ComposedFinder is # expected to mask foo/qux entirely with content from $tmp/b. ensureParentDir(self.tmppath("a/foo/qux/hoge")) open(self.tmppath("a/foo/qux/hoge"), "wb").write(b"hoge") open(self.tmppath("a/foo/qux/bar"), "wb").write(b"not the right content") self.finder = ComposedFinder({ "": FileFinder(self.tmppath("a")), "foo/qux": FileFinder(self.tmppath("b")), }) self.do_match_test() self.assertIsNone(self.finder.get("does-not-exist")) self.assertIsInstance(self.finder.get("bar"), File)
class TestComposedFinder(MatchTestTemplate, TestWithTmpDir): def add(self, path, content=None): # Put foo/qux files under $tmp/b. if path.startswith('foo/qux/'): real_path = mozpath.join('b', path[8:]) else: real_path = mozpath.join('a', path) ensureParentDir(self.tmppath(real_path)) if not content: content = path open(self.tmppath(real_path), 'wb').write(content) def do_check(self, pattern, result): if '*' in pattern: return do_check(self, self.finder, pattern, result) def test_composed_finder(self): self.prepare_match_test() # Also add files in $tmp/a/foo/qux because ComposedFinder is # expected to mask foo/qux entirely with content from $tmp/b. ensureParentDir(self.tmppath('a/foo/qux/hoge')) open(self.tmppath('a/foo/qux/hoge'), 'wb').write('hoge') open(self.tmppath('a/foo/qux/bar'), 'wb').write('not the right content') self.finder = ComposedFinder({ '': FileFinder(self.tmppath('a')), 'foo/qux': FileFinder(self.tmppath('b')), }) self.do_match_test() self.assertIsNone(self.finder.get('does-not-exist')) self.assertIsInstance(self.finder.get('bar'), File)
def test_composed_finder(self): self.prepare_match_test() # Also add files in $tmp/a/foo/qux because ComposedFinder is # expected to mask foo/qux entirely with content from $tmp/b. ensureParentDir(self.tmppath('a/foo/qux/hoge')) open(self.tmppath('a/foo/qux/hoge'), 'wb').write('hoge') open(self.tmppath('a/foo/qux/bar'), 'wb').write('not the right content') self.finder = ComposedFinder({ '': FileFinder(self.tmppath('a')), 'foo/qux': FileFinder(self.tmppath('b')), }) self.do_match_test() self.assertIsNone(self.finder.get('does-not-exist')) self.assertIsInstance(self.finder.get('bar'), File)
def test_composed_finder(self): self.prepare_match_test() # Also add files in $tmp/a/foo/qux because ComposedFinder is # expected to mask foo/qux entirely with content from $tmp/b. ensureParentDir(self.tmppath("a/foo/qux/hoge")) open(self.tmppath("a/foo/qux/hoge"), "wb").write(b"hoge") open(self.tmppath("a/foo/qux/bar"), "wb").write(b"not the right content") self.finder = ComposedFinder({ "": FileFinder(self.tmppath("a")), "foo/qux": FileFinder(self.tmppath("b")), }) self.do_match_test() self.assertIsNone(self.finder.get("does-not-exist")) self.assertIsInstance(self.finder.get("bar"), File)
def repack(source, l10n, extra_l10n={}, non_resources=[], non_chrome=set()): ''' Replace localized data from the `source` directory with localized data from `l10n` and `extra_l10n`. The `source` argument points to a directory containing a packaged application (in omnijar, jar or flat form). The `l10n` argument points to a directory containing the main localized data (usually in the form of a language pack addon) to use to replace in the packaged application. The `extra_l10n` argument contains a dict associating relative paths in the source to separate directories containing localized data for them. This can be used to point at different language pack addons for different parts of the package application. The `non_resources` argument gives a list of relative paths in the source that should not be added in an omnijar in case the packaged application is in that format. The `non_chrome` argument gives a list of file/directory patterns for localized files that are not listed in a chrome.manifest. ''' app_finder = UnpackFinder(source) l10n_finder = UnpackFinder(l10n) if extra_l10n: finders = { '': l10n_finder, } for base, path in extra_l10n.iteritems(): finders[base] = UnpackFinder(path) l10n_finder = ComposedFinder(finders) copier = FileCopier() compress = min(app_finder.compressed, JAR_DEFLATED) if app_finder.kind == 'flat': formatter = FlatFormatter(copier) elif app_finder.kind == 'jar': formatter = JarFormatter(copier, optimize=app_finder.optimizedjars, compress=compress) elif app_finder.kind == 'omni': formatter = OmniJarFormatter(copier, app_finder.omnijar, optimize=app_finder.optimizedjars, compress=compress, non_resources=non_resources) with errors.accumulate(): _repack(app_finder, l10n_finder, copier, formatter, non_chrome) copier.copy(source, skip_if_older=False) generate_precomplete(source)