Skip to content

Commit

Permalink
Bug 1147207 - Allow to give extra l10n directories to l10n-repack.py.…
Browse files Browse the repository at this point in the history
… r=gps

This allows to use separate l10n staging directories for e.g. addons.
  • Loading branch information
glandium committed Mar 31, 2015
1 parent 566e06c commit 082f551
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
33 changes: 31 additions & 2 deletions python/mozbuild/mozpack/packager/l10n.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
SimplePackager,
SimpleManifestSink,
)
from mozpack.files import ManifestFile
from mozpack.files import (
ComposedFinder,
ManifestFile,
)
from mozpack.copier import (
FileCopier,
Jarrer,
Expand Down Expand Up @@ -177,9 +180,35 @@ def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
copier[path].preload([l.replace(locale, l10n_locale) for l in log])


def repack(source, l10n, non_resources=[], non_chrome=set()):
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()
if app_finder.kind == 'flat':
formatter = FlatFormatter(copier)
Expand Down
14 changes: 13 additions & 1 deletion toolkit/mozapps/installer/l10n-repack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,32 @@
])


def valid_extra_l10n(arg):
if '=' not in arg:
raise ValueError('Invalid value')
return tuple(arg.split('=', 1))


def main():
parser = ArgumentParser()
parser.add_argument('build',
help='Directory containing the build to repack')
parser.add_argument('l10n',
help='Directory containing the staged langpack')
parser.add_argument('extra_l10n', nargs='*', metavar='BASE=PATH',
type=valid_extra_l10n,
help='Extra directories with staged localized files '
'to be considered under the given base in the '
'repacked build')
parser.add_argument('--non-resource', nargs='+', metavar='PATTERN',
default=[],
help='Extra files not to be considered as resources')
args = parser.parse_args()

buildconfig.substs['USE_ELF_HACK'] = False
buildconfig.substs['PKG_SKIP_STRIP'] = True
l10n.repack(args.build, args.l10n, args.non_resource, NON_CHROME)
l10n.repack(args.build, args.l10n, extra_l10n=dict(args.extra_l10n),
non_resources=args.non_resource, non_chrome=NON_CHROME)


if __name__ == "__main__":
Expand Down

0 comments on commit 082f551

Please sign in to comment.