~ubuntu-branches/ubuntu/trusty/enigmail/trusty-security

« back to all changes in this revision

Viewing changes to toolkit/mozapps/installer/windows/nsis/preprocess-locale.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-12 16:36:01 UTC
  • mfrom: (0.12.15)
  • Revision ID: package-import@ubuntu.com-20121112163601-q983hiwz8s1bp10x
Tags: 2:1.4.6-0ubuntu1
* New upstream release v1.4.6
* Drop unneeded patches
  - remove debian/patches/correct-version-number.diff
  - remove debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Support building in an objdir
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
        name, value = line.split("=", 1)
47
47
        value = value.strip() # trim whitespace from the start and end
48
 
        if value[-1] == "\"" and value[0] == "\"":
 
48
        if value and value[-1] == "\"" and value[0] == "\"":
49
49
            value = value[1:-1] # remove " from the start and end
50
50
 
51
51
        if add_cr:
67
67
            return join(d, path)
68
68
    return join(l10ndirs[-1], path)
69
69
 
70
 
def preprocess_locale_files(moz_dir, ab_cd, config_dir, l10ndirs):
 
70
def preprocess_locale_files(config_dir, l10ndirs):
71
71
    """
72
72
    Preprocesses the installer localized properties files into the format
73
73
    required by NSIS and creates a basic NSIS nlf file.
74
74
 
75
75
    Parameters:
 
76
    config_dir - the path to the destination directory
 
77
    l10ndirs   - list of paths to search for installer locale files
 
78
    """
 
79
 
 
80
    # Create the main NSIS language file
 
81
    fp = open_utf16le_file(join(config_dir, "overrideLocale.nsh"))
 
82
    locale_strings = get_locale_strings(lookup("override.properties",
 
83
                                               l10ndirs),
 
84
                                        "LangString ^",
 
85
                                        " 0 ",
 
86
                                        False)
 
87
    fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
 
88
    fp.close()
 
89
 
 
90
    # Create the Modern User Interface language file
 
91
    fp = open_utf16le_file(join(config_dir, "baseLocale.nsh"))
 
92
    fp.write((u""";NSIS Modern User Interface - Language File
 
93
;Compatible with Modern UI 1.68
 
94
;Language: baseLocale (0)
 
95
!insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"
 
96
!define MUI_LANGNAME \"baseLocale\"
 
97
""").encode("utf-16-le"))
 
98
    locale_strings = get_locale_strings(lookup("mui.properties", l10ndirs),
 
99
                                        "!define ", " ", True)
 
100
    fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
 
101
    fp.write(u"!insertmacro MOZ_MUI_LANGUAGEFILE_END\n".encode("utf-16-le"))
 
102
    fp.close()
 
103
 
 
104
    # Create the custom language file for our custom strings
 
105
    fp = open_utf16le_file(join(config_dir, "customLocale.nsh"))
 
106
    locale_strings = get_locale_strings(lookup("custom.properties",
 
107
                                               l10ndirs),
 
108
                                        "LangString ",
 
109
                                        " 0 ",
 
110
                                        True)
 
111
    fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
 
112
    fp.close()
 
113
 
 
114
def create_nlf_file(moz_dir, ab_cd, config_dir):
 
115
    """
 
116
    Create a basic NSIS nlf file.
 
117
 
 
118
    Parameters:
76
119
    moz_dir    - the path to top source directory for the toolkit source
77
120
    ab_cd      - the locale code
78
121
    config_dir - the path to the destination directory
79
 
    l10ndirs  - list of paths to search for installer locale files
80
122
    """
81
 
 
82
 
    # Set the language ID to 0 to make this locale the default locale. An
83
 
    # actual ID will need to be used to create a multi-language installer
84
 
    # (e.g. for CD distributions, etc.).
85
 
    lang_id = "0"
86
123
    rtl = "-"
87
124
 
88
125
    # Check whether the locale is right to left from locales.nsi.
89
 
    fp = open(join(moz_dir, "toolkit/mozapps/installer/windows/nsis/locales.nsi"), "r")
 
126
    fp = open(join(moz_dir,
 
127
                   "toolkit/mozapps/installer/windows/nsis/locales.nsi"),
 
128
              "r")
90
129
    for line in fp:
91
130
        line = line.strip()
92
131
        if line == "!define " + ab_cd + "_rtl":
103
142
NLF v6
104
143
# Start editing here
105
144
# Language ID
106
 
%s
 
145
0
107
146
# Font and size - dash (-) means default
108
147
-
109
148
-
111
150
-
112
151
# RTL - anything else than RTL means LTR
113
152
%s
114
 
""" % (lang_id, rtl)).encode("utf-16-le"))
115
 
    fp.close()
116
 
 
117
 
    # Create the main NSIS language file
118
 
    fp = open_utf16le_file(join(config_dir, "overrideLocale.nsh"))
119
 
    locale_strings = get_locale_strings(lookup("override.properties", l10ndirs),
120
 
                                        "LangString ^", " " + lang_id + " ", False)
121
 
    fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
122
 
    fp.close()
123
 
 
124
 
    # Create the Modern User Interface language file
125
 
    fp = open_utf16le_file(join(config_dir, "baseLocale.nsh"))
126
 
    fp.write((u""";NSIS Modern User Interface - Language File
127
 
;Compatible with Modern UI 1.68
128
 
;Language: baseLocale (%s)
129
 
!insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"
130
 
!define MUI_LANGNAME \"baseLocale\"
131
 
""" % (lang_id)).encode("utf-16-le"))
132
 
    locale_strings = get_locale_strings(lookup("mui.properties", l10ndirs),
133
 
                                        "!define ", " ", True)
134
 
    fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
135
 
    fp.write(u"!insertmacro MOZ_MUI_LANGUAGEFILE_END\n".encode("utf-16-le"))
136
 
    fp.close()
 
153
""" % rtl).encode("utf-16-le"))
 
154
    fp.close()
 
155
 
 
156
def preprocess_locale_file(config_dir,
 
157
                           l10ndirs,
 
158
                           properties_filename,
 
159
                           output_filename):
 
160
    """
 
161
    Preprocesses a single localized properties file into the format
 
162
    required by NSIS and creates a basic NSIS nlf file.
 
163
 
 
164
    Parameters:
 
165
    config_dir            - the path to the destination directory
 
166
    l10ndirs              - list of paths to search for installer locale files
 
167
    properties_filename   - the name of the properties file to search for
 
168
    output_filename       - the output filename to write
 
169
    """
137
170
 
138
171
    # Create the custom language file for our custom strings
139
 
    fp = open_utf16le_file(join(config_dir, "customLocale.nsh"))
140
 
    locale_strings = get_locale_strings(lookup("custom.properties", l10ndirs),
141
 
                        "LangString ", " " + lang_id + " ", True)
 
172
    fp = open_utf16le_file(join(config_dir, output_filename))
 
173
    locale_strings = get_locale_strings(lookup(properties_filename,
 
174
                                               l10ndirs),
 
175
                                        "LangString ",
 
176
                                        " 0 ",
 
177
                                        True)
142
178
    fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
143
179
    fp.close()
144
180
 
 
181
 
145
182
def convert_utf8_utf16le(in_file_path, out_file_path):
146
183
    """
147
184
    Converts a UTF-8 file to a new UTF-16LE file
160
197
    usage = """usage: %prog command <args>
161
198
 
162
199
Commands:
163
 
 --convert-utf8-utf16le - preprocesses installer locale properties files and
164
 
                          creates a basic NSIS nlf file
165
 
 --preprocess-locale    - Preprocesses the installer localized properties files
166
 
                          into the format required by NSIS and creates a basic
167
 
                          NSIS nlf file.
 
200
 --convert-utf8-utf16le     - Preprocesses installer locale properties files
 
201
 --preprocess-locale        - Preprocesses the installer localized properties
 
202
                              files into the format required by NSIS and
 
203
                              creates a basic NSIS nlf file.
 
204
 --preprocess-single-file   - Preprocesses a single properties file into the
 
205
                              format required by NSIS
 
206
 --create-nlf-file          - Creates a basic NSIS nlf file
168
207
 
169
208
preprocess-locale.py --preprocess-locale <src> <locale> <code> <dest>
170
209
 
175
214
 <dest>  \tthe path to the destination directory
176
215
 
177
216
 
 
217
preprocess-locale.py --preprocess-single-file <src>
 
218
                                              <locale>
 
219
                                              <dest>
 
220
                                              <infile>
 
221
                                              <outfile>
 
222
 
 
223
Arguments:
 
224
 <src>    \tthe path to top source directory for the toolkit source
 
225
 <locale> \tthe path to the installer's locale files
 
226
 <dest>   \tthe path to the destination directory
 
227
 <infile> \tthe properties file to process
 
228
 <outfile>\tthe nsh file to write
 
229
 
 
230
 
 
231
preprocess-locale.py --create-nlf-file <src>
 
232
                                       <code>
 
233
                                       <dest>
 
234
 
 
235
Arguments:
 
236
 <src>    \tthe path to top source directory for the toolkit source
 
237
 <code>   \tthe locale code
 
238
 <dest>   \tthe path to the destination directory
 
239
 
 
240
 
178
241
preprocess-locale.py --convert-utf8-utf16le <src> <dest>
179
242
 
180
243
Arguments:
181
244
 <src> \tthe path to the UTF-8 source file to convert
182
245
 <dest>\tthe path to the UTF-16LE destination file to create
183
246
"""
 
247
 
 
248
    preprocess_locale_args_help_string = """\
 
249
Arguments to --preprocess-locale should be:
 
250
   <src> <locale> <code> <dest>
 
251
or
 
252
   <src> <code> <dest> --l10n-dir <dir> [--l10n-dir <dir> ...]"""
 
253
 
 
254
    preprocess_single_file_args_help_string = """\
 
255
Arguments to --preprocess-single_file should be:
 
256
   <src> <locale> <code> <dest> <infile> <outfile>
 
257
or
 
258
   <src> <locale> <code> <dest> <infile> <outfile>
 
259
   --l10n-dir <dir> [--l10n-dir <dir>...]"""
 
260
 
 
261
    create_nlf_args_help_string = """\
 
262
Arguments to --create-nlf-file should be:
 
263
   <src> <code> <dest>"""
 
264
 
184
265
    p = OptionParser(usage=usage)
185
266
    p.add_option("--preprocess-locale", action="store_true", default=False,
186
267
                 dest='preprocess')
 
268
    p.add_option("--preprocess-single-file", action="store_true", default=False,
 
269
                 dest='preprocessSingle')
 
270
    p.add_option("--create-nlf-file", action="store_true", default=False,
 
271
                 dest='createNlf')
187
272
    p.add_option("--l10n-dir", action="append", default=[],
188
273
                 dest="l10n_dirs",
189
274
                 help="Add directory to lookup for locale files")
192
277
 
193
278
    options, args = p.parse_args()
194
279
 
195
 
    if ((not (options.preprocess or options.convert)) or
196
 
        (options.preprocess and options.convert)):
197
 
        p.error("You need to specify either --preprocess-locale or --convert-utf-utf16le")
 
280
    foundOne = False
 
281
    if (options.preprocess):
 
282
        foundOne = True
 
283
    if (options.convert):
 
284
        if(foundOne):
 
285
            p.error("More than one command specified")
 
286
        else:
 
287
            foundOne = True
 
288
    if (options.preprocessSingle):
 
289
        if(foundOne):
 
290
            p.error("More than one command specified")
 
291
        else:
 
292
            foundOne = True
 
293
    if (options.createNlf):
 
294
        if(foundOne):
 
295
            p.error("More than one command specified")
 
296
        else:
 
297
            foundOne = True
 
298
 
 
299
    if (not foundOne):
 
300
      p.error("No command specified")
198
301
 
199
302
    if options.preprocess:
200
303
        if len(args) not in (3,4):
201
 
            p.error("--preprocess-locale needs all of <src> <locale> <code> <dest>")
202
 
        pargs = args[:]
203
 
        if len(args) == 4:
204
 
            l10n_dirs = [args[1]]
205
 
            del pargs[1]
206
 
        else:
207
 
            if not options.l10n_dirs:
208
 
                p.error("--preprocess-locale needs either <locale> or --l10ndir")
209
 
            l10n_dirs = options.l10n_dirs
210
 
 
211
 
        pargs.append(l10n_dirs)
212
 
        preprocess_locale_files(*pargs)
213
 
    else:
 
304
            p.error(preprocess_locale_args_help_string)
 
305
 
 
306
        # Parse args
 
307
        pargs = args[:]
 
308
        moz_dir = pargs[0]
 
309
        if len(pargs) == 4:
 
310
            l10n_dirs = [pargs[1]]
 
311
            del pargs[1]
 
312
        else:
 
313
            if not options.l10n_dirs:
 
314
                p.error(preprocess_locale_args_help_string)
 
315
            l10n_dirs = options.l10n_dirs
 
316
        ab_cd = pargs[1]
 
317
        config_dir = pargs[2]
 
318
 
 
319
        # Create the output files
 
320
        create_nlf_file(moz_dir, ab_cd, config_dir)
 
321
        preprocess_locale_files(config_dir, l10n_dirs)
 
322
    elif options.preprocessSingle:
 
323
        if len(args) not in (4,5):
 
324
            p.error(preprocess_single_file_args_help_string)
 
325
 
 
326
        # Parse args
 
327
        pargs = args[:]
 
328
        moz_dir = pargs[0]
 
329
        if len(pargs) == 5:
 
330
            l10n_dirs = [pargs[1]]
 
331
            del pargs[1]
 
332
        else:
 
333
            if not options.l10n_dirs:
 
334
                p.error(preprocess_single_file_args_help_string)
 
335
            l10n_dirs = options.l10n_dirs
 
336
        config_dir = pargs[1]
 
337
        in_file = pargs[2]
 
338
        out_file = pargs[3]
 
339
 
 
340
        # Create the output files
 
341
        preprocess_locale_file(config_dir,
 
342
                               l10n_dirs,
 
343
                               in_file,
 
344
                               out_file)
 
345
    elif options.createNlf:
 
346
        if len(args) != 3:
 
347
            p.error(create_nlf_args_help_string)
 
348
 
 
349
        # Parse args
 
350
        pargs = args[:]
 
351
        moz_dir = pargs[0]
 
352
        ab_cd = pargs[1]
 
353
        config_dir = pargs[2]
 
354
 
 
355
        # Create the output files
 
356
        create_nlf_file(moz_dir, ab_cd, config_dir)
 
357
    elif options.convert:
214
358
        if len(args) != 2:
215
359
            p.error("--convert-utf8-utf16le needs both of <src> <dest>")
216
360
        convert_utf8_utf16le(*args)