~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
5
6
import _pythonpath
7
import sys
5106.2.47 by Carlos Perello Marin
Removed unneeded code
8
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
9
from optparse import OptionParser
10
from zope.component import getUtility
5106.2.47 by Carlos Perello Marin
Removed unneeded code
11
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
12
from canonical.lp import initZopeless
11882.2.2 by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces.
13
from lp.registry.interfaces.distribution import IDistributionSet
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
14
from canonical.launchpad.scripts import execute_zcml_for_scripts
15
from canonical.launchpad.scripts import logger, logger_options
16
17
18
def parse_options(args):
19
    """Parse a set of command line options.
20
21
    Return an optparse.Values object.
22
    """
23
    parser = OptionParser()
24
    parser.add_option("-d", "--distribution", dest="distro",
25
        default='ubuntu',
26
        help="The distribution we want to check.")
27
    parser.add_option("-r", "--release", dest="release",
5121.2.7 by Stuart Bishop
More required code changes
28
        help="The distroseries that we want to check.")
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
29
30
    logger_options(parser)
31
32
    (options, args) = parser.parse_args(args)
33
34
    return options
35
5121.2.7 by Stuart Bishop
More required code changes
36
def compare_translations(orig_distroseries, dest_distroseries):
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
37
38
    from difflib import unified_diff
39
40
    orig_templates = sorted(
5121.2.7 by Stuart Bishop
More required code changes
41
        orig_distroseries.potemplates,
5084.14.58 by Jeroen Vermeulen
Removed some instances of potemplatename.
42
        key=lambda x: (x.name, x.sourcepackagename.name))
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
43
    dest_templates = sorted(
5121.2.7 by Stuart Bishop
More required code changes
44
        dest_distroseries.potemplates,
5084.14.58 by Jeroen Vermeulen
Removed some instances of potemplatename.
45
        key=lambda x: (x.name, x.sourcepackagename.name))
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
46
47
    for i in range(len(orig_templates)):
48
        old_template = orig_templates[i]
49
        new_template = dest_templates[i]
50
        output = '\n'.join(list(unified_diff(
51
            old_template.export().split('\n'),
52
            new_template.export().split('\n'))))
53
        output = output.decode('UTF-8')
54
        if len(output) > 0:
55
            return u'%s is different than its parent %s:\n%s' % (
56
                new_template.title, old_template.title, output)
57
        for old_pofile in old_template.pofiles:
58
            new_pofile = new_template.getPOFileByLang(
11122.3.4 by Danilo Šegan
Get rid of the remaining variant usage.
59
                old_pofile.language.code)
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
60
            old_pofile_content = old_pofile.uncachedExport(
61
                    included_obsolete=False,
62
                    force_utf8=True).split('\n')
63
            new_pofile_content = new_pofile.uncachedExport(
64
                    included_obsolete=False,
65
                    force_utf8=True).split('\n')
66
            output = '\n'.join(list(unified_diff(
67
                old_pofile_content, new_pofile_content)))
68
            output = output.decode('UTF-8')
69
            if len(output) > 0:
70
                return u'%s is different than its parent %s:\n%s' % (
71
                    new_pofile.title, old_pofile.title, output)
72
    return None
73
74
def main(argv):
75
    options = parse_options(argv[1:])
76
77
    logger_object = logger(options, 'check')
78
79
    # Setup zcml machinery to be able to use getUtility
80
    execute_zcml_for_scripts()
81
    ztm = initZopeless()
82
83
    distribution = getUtility(IDistributionSet)[options.distro]
84
    release = distribution[options.release]
85
86
    logger_object.info('Starting...')
5121.2.11 by Stuart Bishop
Code changes
87
    output = compare_translations(release.parent_series, release)
3617.3.35 by Carlos Perello Marin
Reverted the migration queries to stop using a temporary table. It's more easy to maintain and fixes the bug opening a new distrorelease to translate. Includes a script to check that a distrorelease and its parent have exactly the same entries
88
    if output is not None:
89
        logger_object.error(output)
90
    logger_object.info('Done...')
91
92
93
if __name__ == '__main__':
94
    main(sys.argv)