~suutari-olli/openlp/escape-fixes-1294111-1497637

« back to all changes in this revision

Viewing changes to scripts/translation_utils.py

  • Committer: suutari-olli
  • Date: 2016-01-07 02:53:59 UTC
  • mfrom: (2557.2.31 openlp)
  • Revision ID: suutari.olli@gmail.com-20160107025359-q2feybbwxaoihqxr
Merge to trunk on 1/7/2015.

I noticed this branch also seems to be fixing this bug:
https://bugs.launchpad.net/openlp/+bug/1531691

However, escape item still remains buggy with problems related to resuming
video and presentations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
###############################################################################
6
6
# OpenLP - Open Source Lyrics Projection                                      #
7
7
# --------------------------------------------------------------------------- #
8
 
# Copyright (c) 2008-2015 OpenLP Developers                                   #
 
8
# Copyright (c) 2008-2016 OpenLP Developers                                   #
9
9
# --------------------------------------------------------------------------- #
10
10
# This program is free software; you can redistribute it and/or modify it     #
11
11
# under the terms of the GNU General Public License as published by the Free  #
45
45
    @:~$ ./translation_utils.py -dpu
46
46
 
47
47
"""
 
48
from argparse import ArgumentParser
 
49
from getpass import getpass
 
50
import base64
 
51
import glob
 
52
import json
48
53
import os
49
 
import urllib.request
 
54
import sys
50
55
import urllib.error
51
56
import urllib.parse
52
 
from getpass import getpass
53
 
import base64
54
 
import json
 
57
import urllib.request
55
58
import webbrowser
56
 
import glob
57
59
 
 
60
from PyQt5 import QtCore
58
61
from lxml import etree, objectify
59
 
from optparse import OptionParser
60
 
from PyQt4 import QtCore
61
62
 
62
 
SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-22x/'
 
63
SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-24x/'
63
64
IGNORED_PATHS = ['scripts']
64
65
IGNORED_FILES = ['setup.py']
65
66
 
300
301
    This method runs through the ts-files and looks for mismatches between format strings in the original text
301
302
    and in the translations.
302
303
    """
 
304
    is_ok = True
303
305
    path = os.path.join(os.path.abspath('..'), 'resources', 'i18n', '*.ts')
304
306
    file_list = glob.glob(path)
305
307
    for filename in file_list:
317
319
                    print_verbose('parsed numerusform: location: %s, source: %s, translation: %s' % (
318
320
                                  location, org_text, num.text))
319
321
                    if num and org_text.count('%') != num.text.count('%'):
 
322
                        is_ok = False
320
323
                        print_quiet(
321
324
                            'ERROR: Translation from %s at line %s has a mismatch of format input:\n%s\n%s\n' % (
322
325
                                location, line, org_text, num.text))
323
326
            else:
324
327
                print_verbose('parsed: location: %s, source: %s, translation: %s' % (location, org_text, translation))
325
328
                if org_text.count('%') != translation.count('%'):
 
329
                    is_ok = False
326
330
                    print_quiet('ERROR: Translation from %s at line %s has a mismatch of format input:\n%s\n%s\n' % (
327
331
                                location, line, org_text, translation))
 
332
    return is_ok
328
333
 
329
334
 
330
335
def process_stack(command_stack):
335
340
    ``command_stack``
336
341
        The command stack to process.
337
342
    """
 
343
    is_success = True
338
344
    if command_stack:
339
345
        print_quiet('Processing %d commands...' % len(command_stack))
340
346
        for command in command_stack:
351
357
            elif command == Command.Create:
352
358
                create_translation()
353
359
            elif command == Command.Check:
354
 
                check_format_strings()
 
360
                is_success = check_format_strings()
355
361
        print_quiet('Finished processing commands.')
356
362
    else:
357
363
        print_quiet('No commands to process.')
 
364
    return is_success
358
365
 
359
366
 
360
367
def main():
361
368
    global verbose_mode, quiet_mode, username, password
362
369
    # Set up command line options.
363
 
    usage = '%prog [options]\nOptions are parsed in the order they are ' + \
 
370
    usage = '%(prog)s [options]\nOptions are parsed in the order they are ' + \
364
371
        'listed below. If no options are given, "-dpug" will be used.\n\n' + \
365
372
        'This script is used to manage OpenLP\'s translation files.'
366
 
    parser = OptionParser(usage=usage)
367
 
    parser.add_option('-U', '--username', dest='username', metavar='USERNAME',
368
 
                      help='Transifex username, used for authentication')
369
 
    parser.add_option('-P', '--password', dest='password', metavar='PASSWORD',
370
 
                      help='Transifex password, used for authentication')
371
 
    parser.add_option('-d', '--download-ts', dest='download',
372
 
                      action='store_true', help='download language files from Transifex')
373
 
    parser.add_option('-c', '--create', dest='create', action='store_true',
374
 
                      help='go to Transifex to request a new translation file')
375
 
    parser.add_option('-p', '--prepare', dest='prepare', action='store_true',
376
 
                      help='generate a project file, used to update the translations')
377
 
    parser.add_option('-u', '--update', action='store_true', dest='update',
378
 
                      help='update translation files (needs a project file)')
379
 
    parser.add_option('-g', '--generate', dest='generate', action='store_true',
380
 
                      help='compile .ts files into .qm files')
381
 
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
382
 
                      help='show extra information while processing translations')
383
 
    parser.add_option('-q', '--quiet', dest='quiet', action='store_true',
384
 
                      help='suppress all output other than errors')
385
 
    parser.add_option('-f', '--check-format-strings', dest='check', action='store_true',
386
 
                      help='check that format strings are matching in translations')
387
 
    (options, args) = parser.parse_args()
 
373
    parser = ArgumentParser(usage=usage)
 
374
    parser.add_argument('-U', '--username', dest='username', metavar='USERNAME',
 
375
                        help='Transifex username, used for authentication')
 
376
    parser.add_argument('-P', '--password', dest='password', metavar='PASSWORD',
 
377
                        help='Transifex password, used for authentication')
 
378
    parser.add_argument('-d', '--download-ts', dest='download',
 
379
                        action='store_true', help='download language files from Transifex')
 
380
    parser.add_argument('-c', '--create', dest='create', action='store_true',
 
381
                        help='go to Transifex to request a new translation file')
 
382
    parser.add_argument('-p', '--prepare', dest='prepare', action='store_true',
 
383
                        help='generate a project file, used to update the translations')
 
384
    parser.add_argument('-u', '--update', action='store_true', dest='update',
 
385
                        help='update translation files (needs a project file)')
 
386
    parser.add_argument('-g', '--generate', dest='generate', action='store_true',
 
387
                        help='compile .ts files into .qm files')
 
388
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
 
389
                        help='show extra information while processing translations')
 
390
    parser.add_argument('-q', '--quiet', dest='quiet', action='store_true',
 
391
                        help='suppress all output other than errors')
 
392
    parser.add_argument('-f', '--check-format-strings', dest='check', action='store_true',
 
393
                        help='check that format strings are matching in translations')
 
394
    args = parser.parse_args()
388
395
    # Create and populate the command stack
389
396
    command_stack = CommandStack()
390
 
    if options.download:
 
397
    if args.download:
391
398
        command_stack.append(Command.Download)
392
 
    if options.create:
393
 
        command_stack.append(Command.Create, arguments=[options.create])
394
 
    if options.prepare:
 
399
    if args.create:
 
400
        command_stack.append(Command.Create, arguments=[args.create])
 
401
    if args.prepare:
395
402
        command_stack.append(Command.Prepare)
396
 
    if options.update:
 
403
    if args.update:
397
404
        command_stack.append(Command.Update)
398
 
    if options.generate:
 
405
    if args.generate:
399
406
        command_stack.append(Command.Generate)
400
 
    if options.check:
 
407
    if args.check:
401
408
        command_stack.append(Command.Check)
402
 
    verbose_mode = options.verbose
403
 
    quiet_mode = options.quiet
404
 
    if options.username:
405
 
        username = options.username
406
 
    if options.password:
407
 
        password = options.password
 
409
    verbose_mode = args.verbose
 
410
    quiet_mode = args.quiet
 
411
    if args.username:
 
412
        username = args.username
 
413
    if args.password:
 
414
        password = args.password
408
415
    if not command_stack:
409
416
        command_stack.append(Command.Download)
410
417
        command_stack.append(Command.Prepare)
411
418
        command_stack.append(Command.Update)
412
419
        command_stack.append(Command.Generate)
413
420
    # Process the commands
414
 
    process_stack(command_stack)
 
421
    return process_stack(command_stack)
 
422
 
415
423
 
416
424
if __name__ == '__main__':
417
425
    if os.path.split(os.path.abspath('.'))[1] != 'scripts':
418
426
        print('You need to run this script from the scripts directory.')
419
427
    else:
420
 
        main()
 
428
        if not main():
 
429
            sys.exit(1)