3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is l10n test automation.
18 # The Initial Developer of the Original Code is
20 # Portions created by the Initial Developer are Copyright (C) 2007
21 # the Initial Developer. All Rights Reserved.
24 # Axel Hecht <l10n@mozilla.com>
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
41 from optparse
import OptionParser
45 from subprocess
import Popen
, PIPE
46 from shutil
import copy2
50 for root
, dirs
, files
in os
.walk(base
):
55 yield (os
.path
.normpath(root
[len(base
)+1:]), files
)
57 def createLocalization(source
, dest
, apps
, exceptions
= {}):
59 Creates a new localization.
62 @param source: path to the mozilla sources to use
65 @param dest: path to the localization to create or update
67 @type apps: array of strings
68 @param apps: the applications for which to create or update the
71 @type exceptions: mapping
72 @param exceptions: stuff to ignore
75 assert os
.path
.isdir(source
), "source directory is not a directory"
76 clientmk
= os
.path
.join(source
,'client.mk')
77 assert os
.path
.isfile(clientmk
), "client.mk missing"
79 if not apps
or not len(apps
):
82 if not os
.path
.isdir(dest
):
85 assert os
.path
.isdir(dest
), "target should be a directory"
87 # get the directories to iterate over
89 cmd
= ['make', '-f', clientmk
] + \
90 ['echo-variable-LOCALES_' + app
for app
in apps
]
91 p
= Popen(cmd
, stdout
= PIPE
)
92 for ln
in p
.stdout
.readlines():
93 dirs
.update(ln
.strip().split())
94 dirs
= sorted(list(dirs
))
97 assert os
.path
.isdir(os
.path
.join(source
, d
)), \
98 "expecting source directory %s" % d
101 logging
.debug('processing %s' % d
)
102 if d
in exceptions
and exceptions
[d
] == 'all':
105 basepath
= os
.path
.join(source
, d
, 'locales', 'en-US')
109 ign_mod
= exceptions
[d
]
110 logging
.debug('using exceptions: %s' % str(ign_mod
))
112 l10nbase
= os
.path
.join(dest
, d
)
113 if not os
.path
.isdir(l10nbase
):
114 os
.makedirs(l10nbase
)
116 for root
, files
in walk(basepath
):
119 if ign_mod
[root
] == '.':
121 ignore
= re
.compile(ign_mod
[root
])
122 l10npath
= os
.path
.join(l10nbase
, root
)
123 if not os
.path
.isdir(l10npath
):
127 if ignore
and ignore
.search(f
):
128 # ignoring some files
130 if not os
.path
.exists(os
.path
.join(l10npath
,f
)):
131 copy2(os
.path
.join(basepath
, root
, f
), l10npath
)
133 if __name__
== '__main__':
135 p
.add_option('--source', default
= '.',
136 help='Mozilla sources')
137 p
.add_option('--dest', default
= '../l10n',
138 help='Localization target directory')
139 p
.add_option('--app', action
="append",
140 help='Create localization for this application ' + \
141 '(multiple applications allowed, default: browser)')
142 p
.add_option('-v', '--verbose', action
="store_true", default
=False,
143 help='report debugging information')
144 (opts
, args
) = p
.parse_args()
146 logging
.basicConfig(level
=logging
.DEBUG
)
147 assert len(args
) == 1, "language code expected"
149 # hardcoding exceptions, work for both trunk and 1.8 branch
150 exceptions
= {'browser':
151 {'searchplugins': '\\.xml$'},
152 'extensions/spellcheck': 'all'}
153 createLocalization(opts
.source
, os
.path
.join(opts
.dest
, args
[0]),
154 opts
.app
, exceptions
=exceptions
)