comparison roundup/cgi/TAL/talgettext.py @ 5376:64b05e24dbd8

Python 3 preparation: convert print to a function. Tool-assisted patch. It is possible that some "from __future__ import print_function" are not in fact needed, if a file only uses print() with a single string as an argument and so would work fine in Python 2 without that import.
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 09:54:52 +0000
parents 198b6e810c67
children 6fbb7d52e38f
comparison
equal deleted inserted replaced
5375:1ad46057ae4a 5376:64b05e24dbd8
31 -u / --update <file> 31 -u / --update <file>
32 Update the existing translation <file> with any new translation strings 32 Update the existing translation <file> with any new translation strings
33 found. 33 found.
34 """ 34 """
35 35
36 from __future__ import print_function
36 import sys 37 import sys
37 import time 38 import time
38 import getopt 39 import getopt
39 import traceback 40 import traceback
40 41
71 True=1 72 True=1
72 False=0 73 False=0
73 74
74 def usage(code, msg=''): 75 def usage(code, msg=''):
75 # Python 2.1 required 76 # Python 2.1 required
76 print >> sys.stderr, __doc__ 77 print(__doc__, file=sys.stderr)
77 if msg: 78 if msg:
78 print >> sys.stderr, msg 79 print(msg, file=sys.stderr)
79 sys.exit(code) 80 sys.exit(code)
80 81
81 82
82 class POTALInterpreter(TALInterpreter): 83 class POTALInterpreter(TALInterpreter):
83 def translate(self, msgid, default, i18ndict=None, obj=None): 84 def translate(self, msgid, default, i18ndict=None, obj=None):
161 STR = 2 162 STR = 2
162 163
163 try: 164 try:
164 lines = open(self._filename).readlines() 165 lines = open(self._filename).readlines()
165 except IOError as msg: 166 except IOError as msg:
166 print >> sys.stderr, msg 167 print(msg, file=sys.stderr)
167 sys.exit(1) 168 sys.exit(1)
168 169
169 section = None 170 section = None
170 fuzzy = False 171 fuzzy = False
171 172
203 if section == ID: 204 if section == ID:
204 msgid += l 205 msgid += l
205 elif section == STR: 206 elif section == STR:
206 msgstr += '%s\n' % l 207 msgstr += '%s\n' % l
207 else: 208 else:
208 print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \ 209 print('Syntax error on %s:%d' % (infile, lno),
209 'before:' 210 'before:', file=sys.stderr)
210 print >> sys.stderr, l 211 print(l, file=sys.stderr)
211 sys.exit(1) 212 sys.exit(1)
212 # Add last entry 213 # Add last entry
213 if section == STR: 214 if section == STR:
214 self.__add(msgid, msgstr, fuzzy) 215 self.__add(msgid, msgstr, fuzzy)
215 216
251 if outfile is None: 252 if outfile is None:
252 outfile = arg 253 outfile = arg
253 engine = UpdatePOEngine(filename=arg) 254 engine = UpdatePOEngine(filename=arg)
254 255
255 if not args: 256 if not args:
256 print 'nothing to do' 257 print('nothing to do')
257 return 258 return
258 259
259 # We don't care about the rendered output of the .pt file 260 # We don't care about the rendered output of the .pt file
260 class Devnull: 261 class Devnull:
261 def write(self, s): 262 def write(self, s):
274 p.parseFile(filename) 275 p.parseFile(filename)
275 program, macros = p.getCode() 276 program, macros = p.getCode()
276 POTALInterpreter(program, macros, engine, stream=Devnull(), 277 POTALInterpreter(program, macros, engine, stream=Devnull(),
277 metal=False)() 278 metal=False)()
278 except: # Hee hee, I love bare excepts! 279 except: # Hee hee, I love bare excepts!
279 print 'There was an error processing', filename 280 print('There was an error processing', filename)
280 traceback.print_exc() 281 traceback.print_exc()
281 282
282 # Now output the keys in the engine. Write them to a file if --output or 283 # Now output the keys in the engine. Write them to a file if --output or
283 # --update was specified; otherwise use standard out. 284 # --update was specified; otherwise use standard out.
284 if (outfile is None): 285 if (outfile is None):
294 try: 295 try:
295 messages.update(engine.base) 296 messages.update(engine.base)
296 except AttributeError: 297 except AttributeError:
297 pass 298 pass
298 if '' not in messages: 299 if '' not in messages:
299 print >> outfile, pot_header % {'time': time.ctime(), 300 print(pot_header % {'time': time.ctime(),
300 'version': __version__} 301 'version': __version__}, file=outfile)
301 302
302 msgids = catalog.keys() 303 msgids = catalog.keys()
303 # XXX: You should not sort by msgid, but by filename and position. (SR) 304 # XXX: You should not sort by msgid, but by filename and position. (SR)
304 msgids.sort() 305 msgids.sort()
305 for msgid in msgids: 306 for msgid in msgids:

Roundup Issue Tracker: http://roundup-tracker.org/