示例#1
0
 def test_error_loop(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             for i in range(3):
                 errors.error("%d" % i)
     self.assertEquals(self.get_output(),
                       ["Error: 0", "Error: 1", "Error: 2"])
示例#2
0
 def _find(self, path):
     '''
     UnifiedFinder.find() implementation.
     '''
     files1 = OrderedDict()
     for p, f in self._finder1.find(path):
         files1[p] = f
     files2 = set()
     for p, f in self._finder2.find(path):
         files2.add(p)
         if p in files1:
             if may_unify_binary(files1[p]) and \
                     may_unify_binary(f):
                 yield p, UnifiedExecutableFile(files1[p], f)
             else:
                 err = errors.count
                 unified = self.unify_file(p, files1[p], f)
                 if unified:
                     yield p, unified
                 elif err == errors.count:
                     self._report_difference(p, files1[p], f)
         else:
             errors.error('File missing in %s: %s' %
                          (self._finder1.base, p))
     for p in [p for p in files1 if not p in files2]:
         errors.error('File missing in %s: %s' % (self._finder2.base, p))
示例#3
0
 def _find(self, path):
     '''
     UnifiedFinder.find() implementation.
     '''
     files1 = OrderedDict()
     for p, f in self._finder1.find(path):
         files1[p] = f
     files2 = set()
     for p, f in self._finder2.find(path):
         files2.add(p)
         if p in files1:
             if may_unify_binary(files1[p]) and \
                     may_unify_binary(f):
                 yield p, UnifiedExecutableFile(files1[p], f)
             else:
                 err = errors.count
                 unified = self.unify_file(p, files1[p], f)
                 if unified:
                     yield p, unified
                 elif err == errors.count:
                     self._report_difference(p, files1[p], f)
         else:
             errors.error('File missing in %s: %s' %
                          (self._finder1.base, p))
     for p in [p for p in files1 if not p in files2]:
         errors.error('File missing in %s: %s' % (self._finder2.base, p))
示例#4
0
 def handle_line(self, str):
     f = str.strip()
     if not f:
         return
     if self.copier.contains(f):
         errors.error('Removal of packaged file(s): %s' % f)
     self.content += f + '\n'
示例#5
0
 def handle_line(self, f):
     f = f.strip()
     if not f:
         return
     if self.copier.contains(f):
         errors.error("Removal of packaged file(s): %s" % f)
     self.content += six.ensure_binary(f) + b"\n"
示例#6
0
 def test_error_loop(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             for i in range(3):
                 errors.error('%d' % i)
     self.assertEquals(self.get_output(),
                       ['Error: 0', 'Error: 1', 'Error: 2'])
示例#7
0
 def handle_line(self, str):
     f = str.strip()
     if not f:
         return
     if self.copier.contains(f):
         errors.error('Removal of packaged file(s): %s' % f)
     self.content += f + '\n'
示例#8
0
 def handle_line(self, f):
     f = f.strip()
     if not f:
         return
     if self.copier.contains(f):
         errors.error('Removal of packaged file(s): %s' % f)
     ensure = six.ensure_binary if 'b' in self._mode else six.ensure_text
     self.content += ensure(f) + ensure('\n')
示例#9
0
 def unify_file(self, path, file1, file2):
     # We expect none of the files to overlap.
     if not file2:
         return file1
     if not file1:
         return file2
     errors.error(
         "{} is in both {} and {}".format(
             path, self._finder1.base, self._finder2.base
         )
     )
示例#10
0
 def add(self, section, pattern):
     '''
     Add files with the given pattern.
     '''
     assert not self._closed
     added = False
     for p, f in self._finder.find(pattern):
         added = True
         if is_manifest(p):
             self._manifests.add(p)
         self.packager.add(SimpleManifestSink.normalize_path(p), f)
     if not added:
         errors.error('Missing file(s): %s' % pattern)
示例#11
0
 def add(self, section, pattern):
     '''
     Add files with the given pattern.
     '''
     assert not self._closed
     added = False
     for p, f in self._finder.find(pattern):
         added = True
         if is_manifest(p):
             self._manifests.add(p)
         self.packager.add(SimpleManifestSink.normalize_path(p), f)
     if not added:
         errors.error('Missing file(s): %s' % pattern)
示例#12
0
 def _report_difference(self, path, file1, file2):
     '''
     Report differences between files in both trees.
     '''
     errors.error("Can't unify %s: file differs between %s and %s" %
                  (path, self._finder1.base, self._finder2.base))
     if not isinstance(file1, ExecutableFile) and \
             not isinstance(file2, ExecutableFile):
         from difflib import unified_diff
         for line in unified_diff(file1.open().readlines(),
                                  file2.open().readlines(),
                                  os.path.join(self._finder1.base, path),
                                  os.path.join(self._finder2.base, path)):
             errors.out.write(line)
示例#13
0
 def add(self, component, pattern):
     '''
     Add files with the given pattern in the given component.
     '''
     assert not self._closed
     added = False
     for p, f in self._finder.find(pattern):
         added = True
         if is_manifest(p):
             self._manifests.add(p)
         dest = mozpack.path.join(component.destdir, SimpleManifestSink.normalize_path(p))
         self.packager.add(dest, f)
     if not added:
         errors.error('Missing file(s): %s' % pattern)
示例#14
0
 def add(self, component, pattern):
     '''
     Add files with the given pattern in the given component.
     '''
     assert not self._closed
     added = False
     for p, f in self._finder.find(pattern):
         added = True
         if is_manifest(p):
             self._manifests.add(p)
         dest = mozpath.join(component.destdir, SimpleManifestSink.normalize_path(p))
         self.packager.add(dest, f)
     if not added:
         errors.error('Missing file(s): %s' % pattern)
示例#15
0
 def add(self, path, content):
     """
     Add a BaseFile instance to the container, under the given path.
     """
     assert isinstance(content, BaseFile)
     if path in self._files:
         return errors.error("%s already added" % path)
     # Check whether any parent of the given path is already stored
     partial_path = path
     while partial_path:
         partial_path = mozpack.path.dirname(partial_path)
         if partial_path in self._files:
             return errors.error("Can't add %s: %s is a file" % (path, partial_path))
     self._files[path] = content
示例#16
0
 def _report_difference(self, path, file1, file2):
     '''
     Report differences between files in both trees.
     '''
     errors.error("Can't unify %s: file differs between %s and %s" %
                  (path, self._finder1.base, self._finder2.base))
     if not isinstance(file1, ExecutableFile) and \
             not isinstance(file2, ExecutableFile):
         from difflib import unified_diff
         for line in unified_diff(file1.open().readlines(),
                                  file2.open().readlines(),
                                  os.path.join(self._finder1.base, path),
                                  os.path.join(self._finder2.base, path)):
             errors.out.write(line)
示例#17
0
 def add(self, path, content):
     '''
     Add a BaseFile instance to the container, under the given path.
     '''
     assert isinstance(content, BaseFile)
     if path in self._files:
         return errors.error("%s already added" % path)
     # Check whether any parent of the given path is already stored
     partial_path = path
     while partial_path:
         partial_path = mozpack.path.dirname(partial_path)
         if partial_path in self._files:
             return errors.error("Can't add %s: %s is a file" %
                                 (path, partial_path))
     self._files[path] = content
示例#18
0
 def add(self, path, content):
     """
     Add a BaseFile instance to the container, under the given path.
     """
     assert isinstance(content, BaseFile)
     if path in self._files:
         return errors.error("%s already added" % path)
     if self._required_directories[path] > 0:
         return errors.error("Can't add %s: it is a required directory" % path)
     # Check whether any parent of the given path is already stored
     partial_paths = self._partial_paths(path)
     for partial_path in partial_paths:
         if partial_path in self._files:
             return errors.error("Can't add %s: %s is a file" % (path, partial_path))
     self._files[path] = content
     self._required_directories.update(partial_paths)
示例#19
0
 def add(self, component, pattern):
     """
     Add files with the given pattern in the given component.
     """
     assert not self._closed
     added = False
     for p, f in self._finder.find(pattern):
         added = True
         if is_manifest(p):
             self._manifests.add(p)
         dest = mozpath.join(component.destdir,
                             SimpleManifestSink.normalize_path(p))
         if isinstance(f, ExecutableFile):
             f.xz_compress = component.xz_compress
         self.packager.add(dest, f)
     if not added:
         errors.error("Missing file(s): %s" % pattern)
示例#20
0
 def add(self, path, content):
     '''
     Add a BaseFile instance to the container, under the given path.
     '''
     assert isinstance(content, BaseFile)
     if path in self._files:
         return errors.error("%s already added" % path)
     if self._required_directories[path] > 0:
         return errors.error("Can't add %s: it is a required directory" %
                             path)
     # Check whether any parent of the given path is already stored
     partial_paths = self._partial_paths(path)
     for partial_path in partial_paths:
         if partial_path in self._files:
             return errors.error("Can't add %s: %s is a file" %
                                 (path, partial_path))
     self._files[path] = content
     self._required_directories.update(partial_paths)
示例#21
0
 def remove(self, pattern):
     """
     Remove paths matching the given pattern from the container. See the
     mozpack.path.match documentation for a description of the handled
     patterns.
     """
     items = self.match(pattern)
     if not items:
         return errors.error("Can't remove %s: %s" % (pattern, "not matching anything previously added"))
     for i in items:
         del self._files[i]
示例#22
0
    def _report_difference(self, path, file1, file2):
        """
        Report differences between files in both trees.
        """
        if not file1:
            errors.error("File missing in %s: %s" % (self._finder1.base, path))
            return
        if not file2:
            errors.error("File missing in %s: %s" % (self._finder2.base, path))
            return

        errors.error("Can't unify %s: file differs between %s and %s" %
                     (path, self._finder1.base, self._finder2.base))
        if not isinstance(file1, ExecutableFile) and not isinstance(
                file2, ExecutableFile):
            from difflib import unified_diff

            try:
                lines1 = [l.decode("utf-8") for l in file1.open().readlines()]
                lines2 = [l.decode("utf-8") for l in file2.open().readlines()]
            except UnicodeDecodeError:
                lines1 = hexdump(file1.open().read())
                lines2 = hexdump(file2.open().read())

            for line in unified_diff(
                    lines1,
                    lines2,
                    os.path.join(self._finder1.base, path),
                    os.path.join(self._finder2.base, path),
            ):
                errors.out.write(line)
示例#23
0
文件: copier.py 项目: jcha1600/Mypal
 def remove(self, pattern):
     '''
     Remove paths matching the given pattern from the container. See the
     mozpack.path.match documentation for a description of the handled
     patterns.
     '''
     items = self.match(pattern)
     if not items:
         return errors.error("Can't remove %s: %s" % (pattern,
                             "not matching anything previously added"))
     for i in items:
         del self._files[i]
         self._required_directories.subtract(self._partial_paths(i))
示例#24
0
 def remove(self, pattern):
     '''
     Remove paths matching the given pattern from the container. See the
     mozpack.path.match documentation for a description of the handled
     patterns.
     '''
     items = self.match(pattern)
     if not items:
         return errors.error("Can't remove %s: %s" % (pattern,
                             "not matching anything previously added"))
     for i in items:
         del self._files[i]
         self._required_directories.subtract(self._partial_paths(i))
示例#25
0
 def copy(self, dest, skip_if_older=True):
     """
     Create a fat executable from the two Mach-O executable given when
     creating the instance.
     skip_if_older is ignored.
     """
     assert isinstance(dest, str)
     tmpfiles = []
     try:
         for e in self._executables:
             fd, f = mkstemp()
             os.close(fd)
             tmpfiles.append(f)
             e.copy(f, skip_if_older=False)
         lipo = buildconfig.substs.get("LIPO") or "lipo"
         subprocess.check_call([lipo, "-create"] + tmpfiles +
                               ["-output", dest])
     except Exception as e:
         errors.error(
             "Failed to unify %s and %s: %s" %
             (self._executables[0].path, self._executables[1].path, str(e)))
     finally:
         for f in tmpfiles:
             os.unlink(f)
示例#26
0
 def test_multiple_errors(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             errors.error('foo')
             for i in range(3):
                 if i == 2:
                     errors.warn('%d' % i)
                 else:
                     errors.error('%d' % i)
             errors.error('bar')
     self.assertEquals(self.get_output(),
                       ['Error: foo', 'Error: 0', 'Error: 1',
                        'Warning: 2', 'Error: bar'])
示例#27
0
 def test_multiple_errors(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             errors.error("foo")
             for i in range(3):
                 if i == 2:
                     errors.warn("%d" % i)
                 else:
                     errors.error("%d" % i)
             errors.error("bar")
     self.assertEquals(
         self.get_output(),
         ["Error: foo", "Error: 0", "Error: 1", "Warning: 2", "Error: bar"],
     )
示例#28
0
 def test_errors_context(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             self.assertEqual(errors.get_context(), None)
             with errors.context('foo', 1):
                 self.assertEqual(errors.get_context(), ('foo', 1))
                 errors.error('a')
                 with errors.context('bar', 2):
                     self.assertEqual(errors.get_context(), ('bar', 2))
                     errors.error('b')
                 self.assertEqual(errors.get_context(), ('foo', 1))
                 errors.error('c')
     self.assertEqual(self.get_output(), [
         'Error: foo:1: a',
         'Error: bar:2: b',
         'Error: foo:1: c',
     ])
示例#29
0
 def test_errors_context(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             self.assertEqual(errors.get_context(), None)
             with errors.context("foo", 1):
                 self.assertEqual(errors.get_context(), ("foo", 1))
                 errors.error("a")
                 with errors.context("bar", 2):
                     self.assertEqual(errors.get_context(), ("bar", 2))
                     errors.error("b")
                 self.assertEqual(errors.get_context(), ("foo", 1))
                 errors.error("c")
     self.assertEqual(
         self.get_output(),
         [
             "Error: foo:1: a",
             "Error: bar:2: b",
             "Error: foo:1: c",
         ],
     )
示例#30
0
def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
    app = LocaleManifestFinder(app_finder)
    l10n = LocaleManifestFinder(l10n_finder)

    # The code further below assumes there's only one locale replaced with
    # another one.
    if len(app.locales) > 1:
        errors.fatal("Multiple app locales aren't supported: " +
                     ",".join(app.locales))
    if len(l10n.locales) > 1:
        errors.fatal("Multiple l10n locales aren't supported: " +
                     ",".join(l10n.locales))
    locale = app.locales[0]
    l10n_locale = l10n.locales[0]

    # For each base directory, store what path a locale chrome package name
    # corresponds to.
    # e.g., for the following entry under app/chrome:
    #     locale foo en-US path/to/files
    # keep track that the locale path for foo in app is
    # app/chrome/path/to/files.
    # As there may be multiple locale entries with the same base, but with
    # different flags, that tracking takes the flags into account when there
    # are some. Example:
    #     locale foo en-US path/to/files/win os=Win
    #     locale foo en-US path/to/files/mac os=Darwin
    def key(entry):
        if entry.flags:
            return '%s %s' % (entry.name, entry.flags)
        return entry.name

    l10n_paths = {}
    for e in l10n.entries:
        if isinstance(e, ManifestChrome):
            base = mozpath.basedir(e.path, app.bases)
            l10n_paths.setdefault(base, {})
            l10n_paths[base][key(e)] = e.path

    # For chrome and non chrome files or directories, store what langpack path
    # corresponds to a package path.
    paths = {}
    for e in app.entries:
        if isinstance(e, ManifestEntryWithRelPath):
            base = mozpath.basedir(e.path, app.bases)
            if base not in l10n_paths:
                errors.fatal("Locale doesn't contain %s/" % base)
                # Allow errors to accumulate
                continue
            if key(e) not in l10n_paths[base]:
                errors.fatal("Locale doesn't have a manifest entry for '%s'" %
                             e.name)
                # Allow errors to accumulate
                continue
            paths[e.path] = l10n_paths[base][key(e)]

    for pattern in non_chrome:
        for base in app.bases:
            path = mozpath.join(base, pattern)
            left = set(p for p, f in app_finder.find(path))
            right = set(p for p, f in l10n_finder.find(path))
            for p in right:
                paths[p] = p
            for p in left - right:
                paths[p] = None

    # Create a new package, with non localized bits coming from the original
    # package, and localized bits coming from the langpack.
    packager = SimplePackager(formatter)
    for p, f in app_finder:
        if is_manifest(p):
            # Remove localized manifest entries.
            for e in [e for e in f if e.localized]:
                f.remove(e)
        # If the path is one that needs a locale replacement, use the
        # corresponding file from the langpack.
        path = None
        if p in paths:
            path = paths[p]
            if not path:
                continue
        else:
            base = mozpath.basedir(p, paths.keys())
            if base:
                subpath = mozpath.relpath(p, base)
                path = mozpath.normpath(mozpath.join(paths[base], subpath))

        if path:
            files = [f for p, f in l10n_finder.find(path)]
            if not len(files):
                if base not in non_chrome:
                    finderBase = ""
                    if hasattr(l10n_finder, 'base'):
                        finderBase = l10n_finder.base
                    errors.error("Missing file: %s" %
                                 os.path.join(finderBase, path))
            else:
                packager.add(path, files[0])
        else:
            packager.add(p, f)

    # Add localized manifest entries from the langpack.
    l10n_manifests = []
    for base in set(e.base for e in l10n.entries):
        m = ManifestFile(base, [e for e in l10n.entries if e.base == base])
        path = mozpath.join(base, 'chrome.%s.manifest' % l10n_locale)
        l10n_manifests.append((path, m))
    bases = packager.get_bases()
    for path, m in l10n_manifests:
        base = mozpath.basedir(path, bases)
        packager.add(path, m)
        # Add a "manifest $path" entry in the top manifest under that base.
        m = ManifestFile(base)
        m.add(Manifest(base, mozpath.relpath(path, base)))
        packager.add(mozpath.join(base, 'chrome.manifest'), m)

    packager.close()

    # Add any remaining non chrome files.
    for pattern in non_chrome:
        for base in bases:
            for p, f in l10n_finder.find(mozpath.join(base, pattern)):
                if not formatter.contains(p):
                    formatter.add(p, f)

    # Resources in `localization` directories are packaged from the source and then
    # if localized versions are present in the l10n dir, we package them as well
    # keeping the source dir resources as a runtime fallback.
    for p, f in l10n_finder.find('**/localization'):
        if not formatter.contains(p):
            formatter.add(p, f)

    # Transplant jar preloading information.
    for path, log in six.iteritems(app_finder.jarlogs):
        assert isinstance(copier[path], Jarrer)
        copier[path].preload([l.replace(locale, l10n_locale) for l in log])
示例#31
0
def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
    app = LocaleManifestFinder(app_finder)
    l10n = LocaleManifestFinder(l10n_finder)

    # The code further below assumes there's only one locale replaced with
    # another one.
    if len(app.locales) > 1 or len(l10n.locales) > 1:
        errors.fatal("Multiple locales aren't supported")
    locale = app.locales[0]
    l10n_locale = l10n.locales[0]

    # For each base directory, store what path a locale chrome package name
    # corresponds to.
    # e.g., for the following entry under app/chrome:
    #     locale foo en-US path/to/files
    # keep track that the locale path for foo in app is
    # app/chrome/path/to/files.
    l10n_paths = {}
    for e in l10n.entries:
        if isinstance(e, ManifestChrome):
            base = mozpath.basedir(e.path, app.bases)
            l10n_paths.setdefault(base, {})
            l10n_paths[base][e.name] = e.path

    # For chrome and non chrome files or directories, store what langpack path
    # corresponds to a package path.
    paths = {}
    for e in app.entries:
        if isinstance(e, ManifestEntryWithRelPath):
            base = mozpath.basedir(e.path, app.bases)
            if base not in l10n_paths:
                errors.fatal("Locale doesn't contain %s/" % base)
                # Allow errors to accumulate
                continue
            if e.name not in l10n_paths[base]:
                errors.fatal("Locale doesn't have a manifest entry for '%s'" %
                    e.name)
                # Allow errors to accumulate
                continue
            paths[e.path] = l10n_paths[base][e.name]

    for pattern in non_chrome:
        for base in app.bases:
            path = mozpath.join(base, pattern)
            left = set(p for p, f in app_finder.find(path))
            right = set(p for p, f in l10n_finder.find(path))
            for p in right:
                paths[p] = p
            for p in left - right:
                paths[p] = None

    # Create a new package, with non localized bits coming from the original
    # package, and localized bits coming from the langpack.
    packager = SimplePackager(formatter)
    for p, f in app_finder:
        if is_manifest(p):
            # Remove localized manifest entries.
            for e in [e for e in f if e.localized]:
                f.remove(e)
        # If the path is one that needs a locale replacement, use the
        # corresponding file from the langpack.
        path = None
        if p in paths:
            path = paths[p]
            if not path:
                continue
        else:
            base = mozpath.basedir(p, paths.keys())
            if base:
                subpath = mozpath.relpath(p, base)
                path = mozpath.normpath(mozpath.join(paths[base],
                                                               subpath))
        if path:
            files = [f for p, f in l10n_finder.find(path)]
            if not len(files):
                if base not in non_chrome:
                    errors.error("Missing file: %s" %
                                 os.path.join(l10n_finder.base, path))
            else:
                packager.add(path, files[0])
        else:
            packager.add(p, f)

    # Add localized manifest entries from the langpack.
    l10n_manifests = []
    for base in set(e.base for e in l10n.entries):
        m = ManifestFile(base, [e for e in l10n.entries if e.base == base])
        path = mozpath.join(base, 'chrome.%s.manifest' % l10n_locale)
        l10n_manifests.append((path, m))
    bases = packager.get_bases()
    for path, m in l10n_manifests:
        base = mozpath.basedir(path, bases)
        packager.add(path, m)
        # Add a "manifest $path" entry in the top manifest under that base.
        m = ManifestFile(base)
        m.add(Manifest(base, mozpath.relpath(path, base)))
        packager.add(mozpath.join(base, 'chrome.manifest'), m)

    packager.close()

    # Add any remaining non chrome files.
    for pattern in non_chrome:
        for base in bases:
            for p, f in l10n_finder.find(mozpath.join(base, pattern)):
                if not formatter.contains(p):
                    formatter.add(p, f)

    # Transplant jar preloading information.
    for path, log in app_finder.jarlogs.iteritems():
        assert isinstance(copier[path], Jarrer)
        copier[path].preload([l.replace(locale, l10n_locale) for l in log])
示例#32
0
def repack(source, l10n):
    finder = UnpackFinder(source)
    l10n_finder = UnpackFinder(l10n)
    copier = FileCopier()
    if finder.kind == 'flat':
        formatter = FlatFormatter(copier)
    elif finder.kind == 'jar':
        formatter = JarFormatter(copier, optimize=finder.optimizedjars)
    elif finder.kind == 'omni':
        formatter = OmniJarFormatter(copier, finder.omnijar,
                                     optimize=finder.optimizedjars)

    # Read all manifest entries from the packaged directory.
    manifests = dict((p, m) for p, m in finder.find('**/*.manifest')
                     if is_manifest(p))
    assert all(isinstance(m, ManifestFile) for m in manifests.itervalues())
    entries = [e for m in manifests.itervalues() for e in m if e.localized]
    # Find unique locales used in these manifest entries.
    locales = list(set(e.id for e in entries if isinstance(e, ManifestLocale)))
    # Find all paths whose manifest are included by no other manifest.
    includes = set(mozpack.path.join(e.base, e.relpath)
                   for m in manifests.itervalues()
                   for e in m if isinstance(e, Manifest))
    bases = [mozpack.path.dirname(p) for p in set(manifests.keys()) - includes]

    # Read all manifest entries from the langpack directory.
    manifests = [m for p, m in l10n_finder.find('**/*.manifest')
                 if is_manifest(p)]
    assert all(isinstance(m, ManifestFile) for m in manifests)
    l10n_entries = [e for m in manifests for e in m if e.localized]
    # Find unique locales used in these manifest entries.
    l10n_locales = list(set(e.id for e in l10n_entries
                            if isinstance(e, ManifestLocale)))

    # The code further below assumes there's only one locale replaced with
    # another one.
    if len(locales) > 1 or len(l10n_locales) > 1:
        errors.fatal("Multiple locales aren't supported")
    locale = locales[0]
    l10n_locale = l10n_locales[0]

    # For each base directory, store what path a locale chrome package name
    # corresponds to.
    # e.g., for the following entry under app/chrome:
    #     locale foo en-US path/to/files
    # keep track that the locale path for foo in app is
    # app/chrome/path/to/files.
    l10n_paths = {}
    for e in l10n_entries:
        if isinstance(e, ManifestChrome):
            base = mozpack.path.basedir(e.path, bases)
            if not base in l10n_paths:
                l10n_paths[base] = {}
            l10n_paths[base][e.name] = e.path

    # For chrome and non chrome files or directories, store what langpack path
    # corresponds to a package path.
    paths = dict((e.path,
                  l10n_paths[mozpack.path.basedir(e.path, bases)][e.name])
                 for e in entries if isinstance(e, ManifestEntryWithRelPath))

    for path in NON_CHROME:
        for p, f in l10n_finder.find(path):
            paths[p] = p

    # Create a new package, with non localized bits coming from the original
    # package, and localized bits coming from the langpack.
    packager = SimplePackager(formatter)
    for p, f in finder:
        if is_manifest(p):
            # Remove localized manifest entries.
            for e in [e for e in f if e.localized]:
                f.remove(e)
        base = mozpack.path.basedir(p, paths.keys())
        if base:
            # If the path is one that needs a locale replacement, use the
            # corresponding file from the langpack.
            subpath = mozpack.path.relpath(p, base)
            path = mozpack.path.normpath(mozpack.path.join(paths[base],
                                                           subpath))
            files = [f for p, f in l10n_finder.find(path)]
            if len(files) == 0 and base in NON_CHROME:
                path = path.replace(locale, l10n_locale)
                files = [f for p, f in l10n_finder.find(path)]
            if len(files) == 0:
                if not base in NON_CHROME:
                    errors.error("Missing file: %s" % os.path.join(l10n, path))
            else:
                packager.add(path, files[0])
        else:
            packager.add(p, f)

    # Add localized manifest entries from the langpack.
    l10n_manifests = []
    for base in set(e.base for e in l10n_entries):
        m = ManifestFile(base)
        for e in l10n_entries:
            if e.base == base:
                m.add(e)
        path = mozpack.path.join(base, 'chrome.%s.manifest' % l10n_locale)
        l10n_manifests.append((path, m))
    bases = packager.get_bases()
    for path, m in l10n_manifests:
        base = mozpack.path.basedir(path, bases)
        packager.add(path, m)
        # Add a "manifest $path" entry in the top manifest under that base.
        m = ManifestFile(base)
        m.add(Manifest(base, mozpack.path.relpath(path, base)))
        packager.add(mozpack.path.join(base, 'chrome.manifest'), m)

    packager.close()

    # Add any remaining non chrome files.
    for base in NON_CHROME:
        for p, f in l10n_finder.find(base):
            if not formatter.contains(p):
                formatter.add(p, f)

    # Transplant jar preloading information.
    for path, log in finder.jarlogs.iteritems():
        assert isinstance(copier[path], Jarrer)
        copier[path].preload([l.replace(locale, l10n_locale) for l in log])

    copier.copy(source)
    generate_precomplete(source)
示例#33
0
 def test_ignore_errors(self):
     errors.ignore_errors()
     errors.warn("foo")
     errors.error("bar")
     self.assertRaises(ErrorMessage, errors.fatal, "foo")
     self.assertEquals(self.get_output(), ["Warning: foo", "Warning: bar"])
示例#34
0
def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
    app = LocaleManifestFinder(app_finder)
    l10n = LocaleManifestFinder(l10n_finder)

    # The code further below assumes there's only one locale replaced with
    # another one.
    if len(app.locales) > 1 or len(l10n.locales) > 1:
        errors.fatal("Multiple locales aren't supported")
    locale = app.locales[0]
    l10n_locale = l10n.locales[0]

    # For each base directory, store what path a locale chrome package name
    # corresponds to.
    # e.g., for the following entry under app/chrome:
    #     locale foo en-US path/to/files
    # keep track that the locale path for foo in app is
    # app/chrome/path/to/files.
    l10n_paths = {}
    for e in l10n.entries:
        if isinstance(e, ManifestChrome):
            base = mozpack.path.basedir(e.path, app.bases)
            l10n_paths.setdefault(base, {})
            l10n_paths[base][e.name] = e.path

    # For chrome and non chrome files or directories, store what langpack path
    # corresponds to a package path.
    paths = dict((e.path,
                  l10n_paths[mozpack.path.basedir(e.path, app.bases)][e.name])
                 for e in app.entries
                 if isinstance(e, ManifestEntryWithRelPath))

    for pattern in non_chrome:
        for base in app.bases:
            path = mozpack.path.join(base, pattern)
            left = set(p for p, f in app_finder.find(path))
            right = set(p for p, f in l10n_finder.find(path))
            for p in right:
                paths[p] = p
            for p in left - right:
                paths[p] = None

    # Create a new package, with non localized bits coming from the original
    # package, and localized bits coming from the langpack.
    packager = SimplePackager(formatter)
    for p, f in app_finder:
        if is_manifest(p):
            # Remove localized manifest entries.
            for e in [e for e in f if e.localized]:
                f.remove(e)
        # If the path is one that needs a locale replacement, use the
        # corresponding file from the langpack.
        path = None
        if p in paths:
            path = paths[p]
            if not path:
                continue
        else:
            base = mozpack.path.basedir(p, paths.keys())
            if base:
                subpath = mozpack.path.relpath(p, base)
                path = mozpack.path.normpath(mozpack.path.join(paths[base],
                                                               subpath))
        if path:
            files = [f for p, f in l10n_finder.find(path)]
            if not len(files):
                if base not in non_chrome:
                    errors.error("Missing file: %s" %
                                 os.path.join(l10n_finder.base, path))
            else:
                packager.add(path, files[0])
        else:
            packager.add(p, f)

    # Add localized manifest entries from the langpack.
    l10n_manifests = []
    for base in set(e.base for e in l10n.entries):
        m = ManifestFile(base, [e for e in l10n.entries if e.base == base])
        path = mozpack.path.join(base, 'chrome.%s.manifest' % l10n_locale)
        l10n_manifests.append((path, m))
    bases = packager.get_bases()
    for path, m in l10n_manifests:
        base = mozpack.path.basedir(path, bases)
        packager.add(path, m)
        # Add a "manifest $path" entry in the top manifest under that base.
        m = ManifestFile(base)
        m.add(Manifest(base, mozpack.path.relpath(path, base)))
        packager.add(mozpack.path.join(base, 'chrome.manifest'), m)

    packager.close()

    # Add any remaining non chrome files.
    for pattern in non_chrome:
        for base in bases:
            for p, f in l10n_finder.find(mozpack.path.join(base, pattern)):
                if not formatter.contains(p):
                    formatter.add(p, f)

    # Transplant jar preloading information.
    for path, log in app_finder.jarlogs.iteritems():
        assert isinstance(copier[path], Jarrer)
        copier[path].preload([l.replace(locale, l10n_locale) for l in log])
示例#35
0
 def test_ignore_errors(self):
     errors.ignore_errors()
     errors.warn('foo')
     errors.error('bar')
     self.assertRaises(ErrorMessage, errors.fatal, 'foo')
     self.assertEquals(self.get_output(), ['Warning: foo', 'Warning: bar'])
示例#36
0
 def test_simple_error(self):
     with self.assertRaises(AccumulatedErrors):
         with errors.accumulate():
             errors.error('1')
     self.assertEquals(self.get_output(), ['Error: 1'])