Revision | 29419 (tree) |
---|---|
Time | 2022-06-15 06:11:12 |
Author | ![]() |
Make Python3 compatible
@@ -26,6 +26,8 @@ | ||
26 | 26 | email address. |
27 | 27 | """ |
28 | 28 | |
29 | +from __future__ import print_function | |
30 | + | |
29 | 31 | import sys |
30 | 32 | import getopt |
31 | 33 | import os |
@@ -55,9 +57,9 @@ | ||
55 | 57 | stream = sys.stdout |
56 | 58 | else: |
57 | 59 | stream = sys.stderr |
58 | - print >> stream, __doc__ | |
60 | + print(__doc__, file=stream) | |
59 | 61 | if errmsg: |
60 | - print >> stream, '\nError: %s' % (errmsg) | |
62 | + print('\nError: %s' % (errmsg), file=stream) | |
61 | 63 | sys.exit(2) |
62 | 64 | sys.exit(0) |
63 | 65 |
@@ -73,10 +75,13 @@ | ||
73 | 75 | self.from_email_id = '<dev@tortoisesvn.tigris.org>' |
74 | 76 | |
75 | 77 | def safe_command(self, cmd_and_args, cmd_in=''): |
78 | + cmd_in = cmd_in.encode(sys.stdin.encoding) | |
76 | 79 | [stdout, stderr] = subprocess.Popen(cmd_and_args, |
77 | 80 | stdin=subprocess.PIPE, |
78 | 81 | stdout=subprocess.PIPE, |
79 | 82 | stderr=subprocess.PIPE).communicate(input=cmd_in) |
83 | + stdout = stdout.decode(sys.stdout.encoding) | |
84 | + stderr = stderr.decode(sys.stdout.encoding) | |
80 | 85 | return stdout, stderr |
81 | 86 | |
82 | 87 | def match(self, pattern, string): |
@@ -192,6 +197,7 @@ | ||
192 | 197 | percent = 99 |
193 | 198 | else: |
194 | 199 | percent = 100 * (trans) / total |
200 | + percent = round(percent, 1) | |
195 | 201 | |
196 | 202 | if checkAccel: |
197 | 203 | # return '%2s%% (%s/%s/%s)' % (percent, untrans, fuzzy, accel) |
@@ -201,7 +207,7 @@ | ||
201 | 207 | return '%2s%% (%s)' % (percent, untrans) |
202 | 208 | |
203 | 209 | def printStatLine(self, Lang, Gui, Doc): |
204 | - print '%-33s: %-19s: %-19s' % (Lang, Gui, Doc) | |
210 | + print('%-33s: %-19s: %-19s' % (Lang, Gui, Doc)) | |
205 | 211 | |
206 | 212 | def checkTranslation(self, wrkDir): |
207 | 213 |
@@ -209,13 +215,13 @@ | ||
209 | 215 | [totDoc, tsDoc] = self.getTotal(wrkDir, fileDoc) |
210 | 216 | |
211 | 217 | firstline = '==== Translation of %s %s' % (urlTrunk, Sep75) |
212 | - print '' | |
213 | - print firstline[0:75] | |
218 | + print('') | |
219 | + print(firstline[0:75]) | |
214 | 220 | self.printStatLine('', 'User interface', 'Manuals') |
215 | 221 | self.printStatLine('Total strings', totGui, totDoc) |
216 | 222 | # self.printStatLine('Language', 'Status (un/fu/ma)', 'Status (un/fu)') |
217 | 223 | self.printStatLine('Language', 'Status (un/ma)', 'Status (un)') |
218 | - print Sep75 | |
224 | + print(Sep75) | |
219 | 225 | |
220 | 226 | csvReader = csv.DictReader( |
221 | 227 | open(langList), langFields, delimiter=';', quotechar='"') |
@@ -232,7 +238,7 @@ | ||
232 | 238 | statusDoc = self.checkStatus( |
233 | 239 | wrkDir, langCC, fileDoc, totDoc, False) |
234 | 240 | |
235 | - if statusGui != 'NONE' or statusDoc != 'NONE': | |
241 | + if statusGui != '---' or statusDoc != '----': | |
236 | 242 | langName = row['LangName'].strip() |
237 | 243 | langName = langName + ' (' + langCC + ')' |
238 | 244 | self.printStatLine(langName, statusGui, statusDoc) |
@@ -242,7 +248,7 @@ | ||
242 | 248 | def createReport(self): |
243 | 249 | [info_out, info_err] = self.safe_command(['svn', 'info']) |
244 | 250 | if info_err: |
245 | - print >> sys.stderr, '\nError: %s' % (info_err) | |
251 | + print('\nError: %s' % (info_err), file=sys.stderr) | |
246 | 252 | sys.exit(0) |
247 | 253 | |
248 | 254 | # Try different matches for older and newer svn clients |
@@ -257,10 +263,10 @@ | ||
257 | 263 | |
258 | 264 | self.checkTranslation(wrkDir) |
259 | 265 | |
260 | - print Sep75 | |
261 | -# print 'Status: fu=fuzzy - un=untranslated - ma=missing accelerator keys' | |
262 | - print 'Status: un=untranslated - ma=missing accelerator keys' | |
263 | - print Sep75 | |
266 | + print(Sep75) | |
267 | +# print('Status: fu=fuzzy - un=untranslated - ma=missing accelerator keys') | |
268 | + print('Status: un=untranslated - ma=missing accelerator keys') | |
269 | + print(Sep75) | |
264 | 270 | |
265 | 271 | # Clean up the tmp folder |
266 | 272 | for root, dirs, files in os.walk('tmp', topdown=False): |
@@ -279,7 +285,7 @@ | ||
279 | 285 | ['help', |
280 | 286 | 'to-email-id=', |
281 | 287 | ]) |
282 | - except getopt.GetoptError, msg: | |
288 | + except getopt.GetoptError as msg: | |
283 | 289 | usage_and_exit(msg) |
284 | 290 | |
285 | 291 | to_email_id = None |
@@ -293,13 +299,13 @@ | ||
293 | 299 | |
294 | 300 | [info_out, info_err] = report.safe_command(['svnversion', wrkDir]) |
295 | 301 | if info_err: |
296 | - print >> sys.stderr, '\nError: %s' % (info_err) | |
302 | + print('\nError: %s' % (info_err), file=sys.stderr) | |
297 | 303 | sys.exit(0) |
298 | 304 | |
299 | 305 | wcrev = re.sub('[MS]', '', info_out).strip() |
300 | 306 | |
301 | 307 | subject = 'TortoiseSVN translation status report for r%s' % (wcrev) |
302 | - print subject | |
308 | + print(subject) | |
303 | 309 | |
304 | 310 | report.createReport() |
305 | 311 |