~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to release/scripts/modules/bl_i18n_utils/update_mo.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
 
3
 
# ***** BEGIN GPL LICENSE BLOCK *****
4
 
#
5
 
# This program is free software; you can redistribute it and/or
6
 
# modify it under the terms of the GNU General Public License
7
 
# as published by the Free Software Foundation; either version 2
8
 
# of the License, or (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software Foundation,
17
 
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
#
19
 
# ***** END GPL LICENSE BLOCK *****
20
 
 
21
 
# <pep8 compliant>
22
 
 
23
 
# Create or update mo’s under /trunk/locale/…
24
 
 
25
 
import subprocess
26
 
import os
27
 
import sys
28
 
 
29
 
try:
30
 
    import settings
31
 
    import utils
32
 
except:
33
 
    from . import (settings, utils)
34
 
 
35
 
 
36
 
GETTEXT_MSGFMT_EXECUTABLE = settings.GETTEXT_MSGFMT_EXECUTABLE
37
 
 
38
 
SOURCE_DIR = settings.SOURCE_DIR
39
 
TRUNK_MO_DIR = settings.TRUNK_MO_DIR
40
 
TRUNK_PO_DIR = settings.TRUNK_PO_DIR
41
 
 
42
 
DOMAIN = settings.DOMAIN
43
 
 
44
 
 
45
 
def process_po(po, lang, mo=None):
46
 
    if not mo:
47
 
        mo_dir = os.path.join(TRUNK_MO_DIR, lang, "LC_MESSAGES")
48
 
        # Create dirs if not existing!
49
 
        if not os.path.isdir(mo_dir):
50
 
            os.makedirs(mo_dir, exist_ok=True)
51
 
 
52
 
    # show stats
53
 
    cmd = (GETTEXT_MSGFMT_EXECUTABLE,
54
 
           "--statistics",
55
 
           po,
56
 
           "-o",
57
 
           mo or os.path.join(mo_dir, ".".join((DOMAIN, "mo"))),
58
 
          )
59
 
 
60
 
    print("Running ", " ".join(cmd))
61
 
    ret = subprocess.call(cmd)
62
 
    print("Finished.")
63
 
    return ret
64
 
 
65
 
 
66
 
def main():
67
 
    import argparse
68
 
    parser = argparse.ArgumentParser(description="Create or update mo’s " \
69
 
                                                 "under {}.".format(TRUNK_MO_DIR))
70
 
    parser.add_argument('langs', metavar='ISO_code', nargs='*',
71
 
                        help="Restrict processed languages to those.")
72
 
    parser.add_argument('--po', help="Only process that po file (implies --mo).",
73
 
                        nargs='?')
74
 
    parser.add_argument('--mo', help="Mo file to generate (implies --po).",
75
 
                        nargs='?')
76
 
    args = parser.parse_args()
77
 
 
78
 
    ret = 0
79
 
 
80
 
    if args.po and args.mo:
81
 
        if os.path.exists(args.po):
82
 
            t = process_po(args.po, None, args.mo)
83
 
            if t:
84
 
                ret = t
85
 
    elif args.langs:
86
 
        for lang in args.langs:
87
 
            po = os.path.join(TRUNK_PO_DIR, ".".join((lang, "po")))
88
 
            if os.path.exists(po):
89
 
                t = process_po(po, lang)
90
 
                if t:
91
 
                    ret = t
92
 
    else:
93
 
        for po in os.listdir(TRUNK_PO_DIR):
94
 
            if po.endswith(".po") and not po.endswith("_raw.po"):
95
 
                lang = os.path.basename(po)[:-3]
96
 
                po = os.path.join(TRUNK_PO_DIR, po)
97
 
                t = process_po(po, lang)
98
 
                if t:
99
 
                    ret = t
100
 
 
101
 
    return ret
102
 
 
103
 
 
104
 
if __name__ == "__main__":
105
 
    print("\n\n *** Running {} *** \n".format(__file__))
106
 
    sys.exit(main())