Merge lp:~miroslavr256/widelands/buildcat-fixes into lp:widelands

Proposed by Miroslav Remák
Status: Merged
Merged at revision: 7872
Proposed branch: lp:~miroslavr256/widelands/buildcat-fixes
Merge into: lp:widelands
Diff against target: 198 lines (+47/-67)
1 file modified
utils/buildcat.py (+47/-67)
To merge this branch: bzr merge lp:~miroslavr256/widelands/buildcat-fixes
Reviewer Review Type Date Requested Status
GunChleoc Pending
Review via email: mp+288135@code.launchpad.net

Description of the change

Lua files that fall under "widelands" or "widelands_console" POTs were handled differently than the rest, being parsed with xgettext options meant for C++ files. As a result, comments for translators and ngettext/pgettext/... weren't detected properly in those files.

This merge request unites 'do_compile' and 'do_compile_src' functions and also improves error handling a bit - in case something unexpected happens, merge_and_push_translations.sh shouldn't proceed with the push.

Note that as a side effect of these changes, widelands.pot and widelands_console.pot will have different headers (consistent with others). Please let me know if that's a problem.

To post a comment you must log in.
Revision history for this message
Miroslav Remák (miroslavr256) wrote :

Also, are merge commits acceptable in merge requests? I am not very experienced in working with bazaar.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I don't know what you ean by merge commits - we merge trunk into branches all the time if that is what you mean.

Changing the headers is not a problem. I'll try to have a look at the code next week :)

Revision history for this message
Miroslav Remák (miroslavr256) wrote :

> I don't know what you ean by merge commits - we merge trunk into branches all
> the time if that is what you mean.

Yes, that's exactly what I mean. No problem then.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

Running 'git pull' failed. Output:

fatal: object not found: cf1471b01c8dcf30925cc7beaa6697fd8349247e
fast-import: dumping crash report to .git/fast_import_crash_12690
fatal: Error while running fast-import

Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

Running 'git fetch bzr_origin' failed. Output:

fatal: 'bzr_origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Definitely an improvement, thanks!

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utils/buildcat.py'
2--- utils/buildcat.py 2016-03-01 09:33:26 +0000
3+++ utils/buildcat.py 2016-03-04 17:15:24 +0000
4@@ -140,7 +140,7 @@
5 LUAXGETTEXTOPTS+=" --language=Lua --from-code=UTF-8 -F -c\" TRANSLATORS:\""
6
7 time_now = gmtime()
8-# This is the header used for Lua+conf potfiles.
9+# This is the header used for POT files.
10 # Set it to something sensible, as much as is possible here.
11 HEAD = "# Widelands PATH/TO/FILE.PO\n"
12 HEAD += "# Copyright (C) 2005-" + strftime("%Y", time_now) + " Widelands Development Team\n"
13@@ -159,6 +159,9 @@
14 HEAD += "\"Content-Transfer-Encoding: 8bit\\n\"\n"
15 HEAD += "\n"
16
17+class BuildcatError(Exception):
18+ pass
19+
20 def are_we_in_root_directory():
21 """Make sure we are called in the root directory"""
22 if (not os.path.isdir("po")):
23@@ -169,14 +172,14 @@
24 sys.exit(1)
25
26
27-def do_makedirs( dirs ):
28+def do_makedirs(dirs):
29 """Create subdirectories. Ignore errors"""
30 try:
31 os.makedirs( dirs )
32 except:
33 pass
34
35-def pot_modify_header( potfile_in, potfile_out, header ):
36+def pot_modify_header(potfile_in, potfile_out, header):
37 """
38 Modify the header of a translation catalog read from potfile_in to
39 the given header and write out the modified catalog to potfile_out.
40@@ -224,17 +227,29 @@
41 potout.writelines(potin)
42
43 return True
44+
45+def run_xgettext(infiles, outfile, opts):
46+ xgettext = subprocess.Popen("xgettext %s --files-from=- --output=\"%s\"" % \
47+ (opts, outfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)
48+ try:
49+ for fname in infiles:
50+ xgettext.stdin.write(os.path.normpath(fname) + "\n")
51+ xgettext.stdin.close()
52+ except IOError as err_msg:
53+ raise BuildcatError("Failed to call xgettext: %s" % err_msg)
54+
55+ xgettext_status = xgettext.wait()
56+ if (xgettext_status != 0):
57+ raise BuildcatError("xgettext exited with errorcode %i" % xgettext_status)
58
59 def run_msguniq(potfile):
60 msguniq_rv = os.system("msguniq \"%s\" -F --output-file=\"%s\"" % (potfile, potfile))
61 if (msguniq_rv):
62- sys.stderr.write("msguniq exited with errorcode %i\n" % msguniq_rv)
63- return False
64- return True
65+ raise BuildcatError("msguniq exited with errorcode %i" % msguniq_rv)
66
67-def do_compile( potfile, srcfiles ):
68+def do_compile(potfile, srcfiles):
69 """
70- Search Lua and conf files given in srcfiles for translatable strings.
71+ Search C++, Lua and conf files given in srcfiles for translatable strings.
72 Merge the results and write out the corresponding pot file.
73 """
74 files = []
75@@ -242,29 +257,24 @@
76 files += glob(i)
77 files = set(files)
78
79+ cpp_files = set([ f for f in files if
80+ os.path.splitext(f)[-1].lower() == '.cc' or os.path.splitext(f)[-1].lower() == '.h'])
81 lua_files = set([ f for f in files if
82 os.path.splitext(f)[-1].lower() == '.lua' ])
83- conf_files = files - lua_files
84+ conf_files = files - cpp_files - lua_files
85
86 temp_potfile = potfile + ".tmp"
87-
88- if (os.path.exists(temp_potfile)): os.remove(temp_potfile)
89-
90- # Find translatable strings in Lua files using xgettext
91- xgettext = subprocess.Popen("xgettext %s --files-from=- --output=\"%s\"" % \
92- (LUAXGETTEXTOPTS, temp_potfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)
93- try:
94- for fname in lua_files:
95- xgettext.stdin.write(os.path.normpath(fname) + "\n")
96- xgettext.stdin.close()
97- except IOError as err_msg:
98- sys.stderr.write("Failed to call xgettext: %s\n" % err_msg)
99- return False
100-
101- xgettext_status = xgettext.wait()
102- if (xgettext_status != 0):
103- sys.stderr.write("xgettext exited with errorcode %i\n" % xgettext_status)
104- return False
105+ if (os.path.exists(temp_potfile)):
106+ os.remove(temp_potfile)
107+
108+ # Find translatable strings in C++ and Lua files using xgettext
109+ if len(cpp_files) > 0:
110+ run_xgettext(cpp_files, temp_potfile, XGETTEXTOPTS)
111+ if len(lua_files) > 0:
112+ if os.path.exists(temp_potfile):
113+ run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS + " --join-existing")
114+ else:
115+ run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS)
116
117 xgettext_found_something_to_translate = os.path.exists(temp_potfile)
118
119@@ -281,50 +291,20 @@
120 os.remove(temp_potfile)
121
122 if not header_fixed:
123- return False
124+ raise BuildcatError("Failed to fix header.")
125
126 if (conf.found_something_to_translate):
127- # Merge the conf POT with Lua POT
128+ # Merge the conf POT with C++/Lua POT
129 with open(potfile, "at") as p:
130 p.write("\n" + conf.toString())
131
132- if not run_msguniq(potfile):
133- return False
134+ run_msguniq(potfile)
135 elif (conf.found_something_to_translate):
136 with open(potfile, "wt") as p:
137 p.write(HEAD + conf.toString())
138
139 # Msguniq is run here only to sort POT entries by file
140- if not run_msguniq(potfile):
141- return False
142-
143- return True
144-
145-
146-
147-def do_compile_src( potfile, srcfiles ):
148- """
149- Use xgettext for parse the given C++ files in srcfiles. Merge the results
150- and write out the given potfile
151- """
152- # call xgettext and supply source filenames via stdin
153- xgettext = subprocess.Popen("xgettext %s --files-from=- --output=%s" % \
154- (XGETTEXTOPTS, potfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)
155- try:
156- for one_pattern in srcfiles:
157- # 'normpath' is necessary for windows ('/' vs. '\')
158- # 'glob' handles filename wildcards
159- for one_file in glob(os.path.normpath(one_pattern)):
160- xgettext.stdin.write(one_file + "\n")
161- xgettext.stdin.close()
162- except IOError as err_msg:
163- sys.stderr.write("Failed to call xgettext: %s\n" % err_msg)
164- return False
165-
166- xgettext_status = xgettext.wait()
167- if (xgettext_status != 0):
168- sys.stderr.write("xgettext exited with errorcode %i\n" % xgettext_status)
169- return False
170+ run_msguniq(potfile)
171
172 return True
173
174@@ -375,11 +355,7 @@
175 oldcwd = os.getcwd()
176 os.chdir(path)
177 potfile = os.path.basename(pot) + '.pot'
178- if pot.startswith('widelands'):
179- # This catalogs can be built with xgettext
180- succ = do_compile_src(potfile , srcfiles )
181- else:
182- succ = do_compile(potfile, srcfiles)
183+ succ = do_compile(potfile, srcfiles)
184
185 os.chdir(oldcwd)
186
187@@ -480,6 +456,10 @@
188 are_we_in_root_directory()
189
190 # Make sure .pot files are up to date.
191- do_update_potfiles()
192+ try:
193+ do_update_potfiles()
194+ except BuildcatError as err_msg:
195+ sys.stderr.write("Error: %s\n" % err_msg);
196+ sys.exit(1)
197
198 print("")

Subscribers

People subscribed via source and target branches

to status/vote changes: