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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

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
# Update po’s in the branches from blender.pot in /trunk/po dir.
 
24
 
 
25
import concurrent.futures
 
26
import os
 
27
import sys
 
28
from codecs import open
 
29
import shutil
 
30
 
 
31
try:
 
32
    import settings
 
33
    import utils
 
34
except:
 
35
    from . import (settings, utils)
 
36
 
 
37
 
 
38
GETTEXT_MSGMERGE_EXECUTABLE = settings.GETTEXT_MSGMERGE_EXECUTABLE
 
39
BRANCHES_DIR = settings.BRANCHES_DIR
 
40
TRUNK_PO_DIR = settings.TRUNK_PO_DIR
 
41
FILE_NAME_POT = settings.FILE_NAME_POT
 
42
 
 
43
 
 
44
def process_po(data):
 
45
    po, lang, pot_msgs = data
 
46
    # update po file
 
47
    msg = utils.I18nMessages(iso=lang, kind='PO', src=po)
 
48
    print("Updating {}...".format(po))
 
49
    msg.update(pot_msgs)
 
50
    msg.write(kind='PO', dest=po)
 
51
    print("Finished updating {}!\n".format(po))
 
52
    return 0
 
53
 
 
54
 
 
55
def main():
 
56
    import argparse
 
57
    parser = argparse.ArgumentParser(description="Write out messages.txt from Blender.")
 
58
    parser.add_argument('-t', '--trunk', action="store_true", help="Update po’s in /trunk/po rather than /branches.")
 
59
    parser.add_argument('-i', '--input', metavar="File", help="Input pot file path.")
 
60
    parser.add_argument('-a', '--add', action="store_true",
 
61
                        help="Add missing po’s (useful only when one or more languages are given!).")
 
62
    parser.add_argument('langs', metavar='ISO_code', nargs='*', help="Restrict processed languages to those.")
 
63
    args = parser.parse_args()
 
64
 
 
65
    if args.input:
 
66
        global FILE_NAME_POT
 
67
        FILE_NAME_POT = args.input
 
68
    ret = 0
 
69
 
 
70
    pot_msgs = utils.I18nMessages(kind='PO', src=FILE_NAME_POT)
 
71
    pool_data = []
 
72
 
 
73
    if args.langs:
 
74
        for lang in args.langs:
 
75
            if args.trunk:
 
76
                dr = TRUNK_PO_DIR
 
77
                po = os.path.join(dr, ".".join((lang, "po")))
 
78
            else:
 
79
                dr = os.path.join(BRANCHES_DIR, lang)
 
80
                po = os.path.join(dr, ".".join((lang, "po")))
 
81
            if args.add:
 
82
                if not os.path.exists(dr):
 
83
                    os.makedirs(dr)
 
84
                if not os.path.exists(po):
 
85
                    shutil.copy(FILE_NAME_POT, po)
 
86
            if args.add or os.path.exists(po):
 
87
                pool_data.append((po, lang, pot_msgs))
 
88
    elif args.trunk:
 
89
        for po in os.listdir(TRUNK_PO_DIR):
 
90
            if po.endswith(".po"):
 
91
                lang = os.path.basename(po)[:-3]
 
92
                po = os.path.join(TRUNK_PO_DIR, po)
 
93
                pool_data.append((po, lang, pot_msgs))
 
94
    else:
 
95
        for lang in os.listdir(BRANCHES_DIR):
 
96
            po = os.path.join(BRANCHES_DIR, lang, ".".join((lang, "po")))
 
97
            if os.path.exists(po):
 
98
                pool_data.append((po, lang, pot_msgs))
 
99
 
 
100
    for r in map(process_po, pool_data):
 
101
        if r != 0:
 
102
            ret = r
 
103
    #with concurrent.futures.ProcessPoolExecutor() as executor:
 
104
        #for r in executor.map(process_po, pool_data, timeout=600):
 
105
            #if r != 0:
 
106
                #ret = r
 
107
 
 
108
    return ret
 
109
 
 
110
 
 
111
if __name__ == "__main__":
 
112
    print("\n\n *** Running {} *** \n".format(__file__))
 
113
    sys.exit(main())
 
 
b'\\ No newline at end of file'