3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 from optparse
import OptionParser
12 from subprocess
import Popen
, PIPE
13 from shutil
import copy2
17 for root
, dirs
, files
in os
.walk(base
):
22 yield (os
.path
.normpath(root
[len(base
)+1:]), files
)
24 def createLocalization(source
, dest
, apps
, exceptions
= {}):
26 Creates a new localization.
29 @param source: path to the mozilla sources to use
32 @param dest: path to the localization to create or update
34 @type apps: array of strings
35 @param apps: the applications for which to create or update the
38 @type exceptions: mapping
39 @param exceptions: stuff to ignore
42 assert os
.path
.isdir(source
), "source directory is not a directory"
43 clientmk
= os
.path
.join(source
,'client.mk')
44 assert os
.path
.isfile(clientmk
), "client.mk missing"
46 if not apps
or not len(apps
):
49 if not os
.path
.isdir(dest
):
52 assert os
.path
.isdir(dest
), "target should be a directory"
54 # get the directories to iterate over
56 cmd
= ['make', '-f', clientmk
] + \
57 ['echo-variable-LOCALES_' + app
for app
in apps
]
58 p
= Popen(cmd
, stdout
= PIPE
)
59 for ln
in p
.stdout
.readlines():
60 dirs
.update(ln
.strip().split())
61 dirs
= sorted(list(dirs
))
64 assert os
.path
.isdir(os
.path
.join(source
, d
)), \
65 "expecting source directory %s" % d
68 logging
.debug('processing %s' % d
)
69 if d
in exceptions
and exceptions
[d
] == 'all':
72 basepath
= os
.path
.join(source
, d
, 'locales', 'en-US')
76 ign_mod
= exceptions
[d
]
77 logging
.debug('using exceptions: %s' % str(ign_mod
))
79 l10nbase
= os
.path
.join(dest
, d
)
80 if not os
.path
.isdir(l10nbase
):
83 for root
, files
in walk(basepath
):
86 if ign_mod
[root
] == '.':
88 ignore
= re
.compile(ign_mod
[root
])
89 l10npath
= os
.path
.join(l10nbase
, root
)
90 if not os
.path
.isdir(l10npath
):
94 if ignore
and ignore
.search(f
):
97 if not os
.path
.exists(os
.path
.join(l10npath
,f
)):
98 copy2(os
.path
.join(basepath
, root
, f
), l10npath
)
100 if __name__
== '__main__':
102 p
.add_option('--source', default
= '.',
103 help='Mozilla sources')
104 p
.add_option('--dest', default
= '../l10n',
105 help='Localization target directory')
106 p
.add_option('--app', action
="append",
107 help='Create localization for this application ' + \
108 '(multiple applications allowed, default: browser)')
109 p
.add_option('-v', '--verbose', action
="store_true", default
=False,
110 help='report debugging information')
111 (opts
, args
) = p
.parse_args()
113 logging
.basicConfig(level
=logging
.DEBUG
)
114 assert len(args
) == 1, "language code expected"
116 # hardcoding exceptions, work for both trunk and 1.8 branch
117 exceptions
= {'browser':
118 {'searchplugins': '\\.xml$'},
119 'extensions/spellcheck': 'all'}
120 createLocalization(opts
.source
, os
.path
.join(opts
.dest
, args
[0]),
121 opts
.app
, exceptions
=exceptions
)