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
=== modified file 'utils/buildcat.py'
--- utils/buildcat.py 2016-03-01 09:33:26 +0000
+++ utils/buildcat.py 2016-03-04 17:15:24 +0000
@@ -140,7 +140,7 @@
140LUAXGETTEXTOPTS+=" --language=Lua --from-code=UTF-8 -F -c\" TRANSLATORS:\""140LUAXGETTEXTOPTS+=" --language=Lua --from-code=UTF-8 -F -c\" TRANSLATORS:\""
141141
142time_now = gmtime()142time_now = gmtime()
143# This is the header used for Lua+conf potfiles.143# This is the header used for POT files.
144# Set it to something sensible, as much as is possible here.144# Set it to something sensible, as much as is possible here.
145HEAD = "# Widelands PATH/TO/FILE.PO\n"145HEAD = "# Widelands PATH/TO/FILE.PO\n"
146HEAD += "# Copyright (C) 2005-" + strftime("%Y", time_now) + " Widelands Development Team\n"146HEAD += "# Copyright (C) 2005-" + strftime("%Y", time_now) + " Widelands Development Team\n"
@@ -159,6 +159,9 @@
159HEAD += "\"Content-Transfer-Encoding: 8bit\\n\"\n"159HEAD += "\"Content-Transfer-Encoding: 8bit\\n\"\n"
160HEAD += "\n"160HEAD += "\n"
161161
162class BuildcatError(Exception):
163 pass
164
162def are_we_in_root_directory():165def are_we_in_root_directory():
163 """Make sure we are called in the root directory"""166 """Make sure we are called in the root directory"""
164 if (not os.path.isdir("po")):167 if (not os.path.isdir("po")):
@@ -169,14 +172,14 @@
169 sys.exit(1)172 sys.exit(1)
170173
171174
172def do_makedirs( dirs ):175def do_makedirs(dirs):
173 """Create subdirectories. Ignore errors"""176 """Create subdirectories. Ignore errors"""
174 try:177 try:
175 os.makedirs( dirs )178 os.makedirs( dirs )
176 except:179 except:
177 pass180 pass
178181
179def pot_modify_header( potfile_in, potfile_out, header ):182def pot_modify_header(potfile_in, potfile_out, header):
180 """183 """
181 Modify the header of a translation catalog read from potfile_in to184 Modify the header of a translation catalog read from potfile_in to
182 the given header and write out the modified catalog to potfile_out.185 the given header and write out the modified catalog to potfile_out.
@@ -224,17 +227,29 @@
224 potout.writelines(potin)227 potout.writelines(potin)
225228
226 return True229 return True
230
231def run_xgettext(infiles, outfile, opts):
232 xgettext = subprocess.Popen("xgettext %s --files-from=- --output=\"%s\"" % \
233 (opts, outfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)
234 try:
235 for fname in infiles:
236 xgettext.stdin.write(os.path.normpath(fname) + "\n")
237 xgettext.stdin.close()
238 except IOError as err_msg:
239 raise BuildcatError("Failed to call xgettext: %s" % err_msg)
240
241 xgettext_status = xgettext.wait()
242 if (xgettext_status != 0):
243 raise BuildcatError("xgettext exited with errorcode %i" % xgettext_status)
227244
228def run_msguniq(potfile):245def run_msguniq(potfile):
229 msguniq_rv = os.system("msguniq \"%s\" -F --output-file=\"%s\"" % (potfile, potfile))246 msguniq_rv = os.system("msguniq \"%s\" -F --output-file=\"%s\"" % (potfile, potfile))
230 if (msguniq_rv):247 if (msguniq_rv):
231 sys.stderr.write("msguniq exited with errorcode %i\n" % msguniq_rv)248 raise BuildcatError("msguniq exited with errorcode %i" % msguniq_rv)
232 return False
233 return True
234249
235def do_compile( potfile, srcfiles ):250def do_compile(potfile, srcfiles):
236 """251 """
237 Search Lua and conf files given in srcfiles for translatable strings.252 Search C++, Lua and conf files given in srcfiles for translatable strings.
238 Merge the results and write out the corresponding pot file.253 Merge the results and write out the corresponding pot file.
239 """254 """
240 files = []255 files = []
@@ -242,29 +257,24 @@
242 files += glob(i)257 files += glob(i)
243 files = set(files)258 files = set(files)
244259
260 cpp_files = set([ f for f in files if
261 os.path.splitext(f)[-1].lower() == '.cc' or os.path.splitext(f)[-1].lower() == '.h'])
245 lua_files = set([ f for f in files if262 lua_files = set([ f for f in files if
246 os.path.splitext(f)[-1].lower() == '.lua' ])263 os.path.splitext(f)[-1].lower() == '.lua' ])
247 conf_files = files - lua_files264 conf_files = files - cpp_files - lua_files
248265
249 temp_potfile = potfile + ".tmp"266 temp_potfile = potfile + ".tmp"
250267 if (os.path.exists(temp_potfile)):
251 if (os.path.exists(temp_potfile)): os.remove(temp_potfile)268 os.remove(temp_potfile)
252269
253 # Find translatable strings in Lua files using xgettext270 # Find translatable strings in C++ and Lua files using xgettext
254 xgettext = subprocess.Popen("xgettext %s --files-from=- --output=\"%s\"" % \271 if len(cpp_files) > 0:
255 (LUAXGETTEXTOPTS, temp_potfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)272 run_xgettext(cpp_files, temp_potfile, XGETTEXTOPTS)
256 try:273 if len(lua_files) > 0:
257 for fname in lua_files:274 if os.path.exists(temp_potfile):
258 xgettext.stdin.write(os.path.normpath(fname) + "\n")275 run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS + " --join-existing")
259 xgettext.stdin.close()276 else:
260 except IOError as err_msg:277 run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS)
261 sys.stderr.write("Failed to call xgettext: %s\n" % err_msg)
262 return False
263
264 xgettext_status = xgettext.wait()
265 if (xgettext_status != 0):
266 sys.stderr.write("xgettext exited with errorcode %i\n" % xgettext_status)
267 return False
268278
269 xgettext_found_something_to_translate = os.path.exists(temp_potfile)279 xgettext_found_something_to_translate = os.path.exists(temp_potfile)
270280
@@ -281,50 +291,20 @@
281 os.remove(temp_potfile)291 os.remove(temp_potfile)
282292
283 if not header_fixed:293 if not header_fixed:
284 return False294 raise BuildcatError("Failed to fix header.")
285295
286 if (conf.found_something_to_translate):296 if (conf.found_something_to_translate):
287 # Merge the conf POT with Lua POT297 # Merge the conf POT with C++/Lua POT
288 with open(potfile, "at") as p:298 with open(potfile, "at") as p:
289 p.write("\n" + conf.toString())299 p.write("\n" + conf.toString())
290300
291 if not run_msguniq(potfile):301 run_msguniq(potfile)
292 return False
293 elif (conf.found_something_to_translate):302 elif (conf.found_something_to_translate):
294 with open(potfile, "wt") as p:303 with open(potfile, "wt") as p:
295 p.write(HEAD + conf.toString())304 p.write(HEAD + conf.toString())
296305
297 # Msguniq is run here only to sort POT entries by file306 # Msguniq is run here only to sort POT entries by file
298 if not run_msguniq(potfile):307 run_msguniq(potfile)
299 return False
300
301 return True
302
303
304
305def do_compile_src( potfile, srcfiles ):
306 """
307 Use xgettext for parse the given C++ files in srcfiles. Merge the results
308 and write out the given potfile
309 """
310 # call xgettext and supply source filenames via stdin
311 xgettext = subprocess.Popen("xgettext %s --files-from=- --output=%s" % \
312 (XGETTEXTOPTS, potfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)
313 try:
314 for one_pattern in srcfiles:
315 # 'normpath' is necessary for windows ('/' vs. '\')
316 # 'glob' handles filename wildcards
317 for one_file in glob(os.path.normpath(one_pattern)):
318 xgettext.stdin.write(one_file + "\n")
319 xgettext.stdin.close()
320 except IOError as err_msg:
321 sys.stderr.write("Failed to call xgettext: %s\n" % err_msg)
322 return False
323
324 xgettext_status = xgettext.wait()
325 if (xgettext_status != 0):
326 sys.stderr.write("xgettext exited with errorcode %i\n" % xgettext_status)
327 return False
328308
329 return True309 return True
330310
@@ -375,11 +355,7 @@
375 oldcwd = os.getcwd()355 oldcwd = os.getcwd()
376 os.chdir(path)356 os.chdir(path)
377 potfile = os.path.basename(pot) + '.pot'357 potfile = os.path.basename(pot) + '.pot'
378 if pot.startswith('widelands'):358 succ = do_compile(potfile, srcfiles)
379 # This catalogs can be built with xgettext
380 succ = do_compile_src(potfile , srcfiles )
381 else:
382 succ = do_compile(potfile, srcfiles)
383359
384 os.chdir(oldcwd)360 os.chdir(oldcwd)
385361
@@ -480,6 +456,10 @@
480 are_we_in_root_directory()456 are_we_in_root_directory()
481457
482 # Make sure .pot files are up to date.458 # Make sure .pot files are up to date.
483 do_update_potfiles()459 try:
460 do_update_potfiles()
461 except BuildcatError as err_msg:
462 sys.stderr.write("Error: %s\n" % err_msg);
463 sys.exit(1)
484464
485 print("")465 print("")

Subscribers

People subscribed via source and target branches

to status/vote changes: