OLD | NEW |
1 #!@TARGET_PYTHON@ | 1 #!@TARGET_PYTHON@ |
2 | 2 |
3 # convert-ly.py -- Update old LilyPond input files (fix name?) | 3 # convert-ly.py -- Update old LilyPond input files (fix name?) |
4 # converting rules are found in python/convertrules.py | 4 # converting rules are found in python/convertrules.py |
5 | 5 |
6 # This file is part of LilyPond, the GNU music typesetter. | 6 # This file is part of LilyPond, the GNU music typesetter. |
7 # | 7 # |
8 # Copyright (C) 1998--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> | 8 # Copyright (C) 1998--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> |
9 # Jan Nieuwenhuizen <janneke@gnu.org> | 9 # Jan Nieuwenhuizen <janneke@gnu.org> |
10 # | 10 # |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 def version_cmp (t1, t2): | 168 def version_cmp (t1, t2): |
169 for x in [0, 1, 2]: | 169 for x in [0, 1, 2]: |
170 if t1[x] - t2[x]: | 170 if t1[x] - t2[x]: |
171 return t1[x] - t2[x] | 171 return t1[x] - t2[x] |
172 return 0 | 172 return 0 |
173 | 173 |
174 def get_conversions (from_version, to_version): | 174 def get_conversions (from_version, to_version): |
175 def is_applicable (v, f = from_version, t = to_version): | 175 def is_applicable (v, f = from_version, t = to_version): |
176 return version_cmp (v[0], f) > 0 and version_cmp (v[0], t) <= 0 | 176 return version_cmp (v[0], f) > 0 and version_cmp (v[0], t) <= 0 |
177 return filter (is_applicable, convertrules.conversions) | 177 return list(filter (is_applicable, convertrules.conversions)) |
178 | 178 |
179 def latest_version (): | 179 def latest_version (): |
180 return convertrules.conversions[-1][0] | 180 return convertrules.conversions[-1][0] |
181 | 181 |
182 def show_rules (file, from_version, to_version): | 182 def show_rules (file, from_version, to_version): |
183 for x in convertrules.conversions: | 183 for x in convertrules.conversions: |
184 if (not from_version or x[0] > from_version) \ | 184 if (not from_version or x[0] > from_version) \ |
185 and (not to_version or x[0] <= to_version): | 185 and (not to_version or x[0] <= to_version): |
186 file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2])) | 186 file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2])) |
187 | 187 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 n = n + 1 | 245 n = n + 1 |
246 back_up = file + '.~' + str(n) + '~' | 246 back_up = file + '.~' + str(n) + '~' |
247 if not os.path.exists (back_up): | 247 if not os.path.exists (back_up): |
248 break | 248 break |
249 else: | 249 else: |
250 back_up = file + '~' | 250 back_up = file + '~' |
251 shutil.copy2 (file, back_up) | 251 shutil.copy2 (file, back_up) |
252 return back_up | 252 return back_up |
253 | 253 |
254 def do_one_file (infile_name): | 254 def do_one_file (infile_name): |
255 ly.progress (_ (u"Processing `%s\'... ") % infile_name, True) | 255 ly.progress (_ ("Processing `%s\'... ") % infile_name, True) |
256 | 256 |
257 if infile_name: | 257 if infile_name: |
258 infile = open (infile_name, 'r') | 258 infile = open (infile_name, 'r') |
259 input = infile.read () | 259 input = infile.read () |
260 infile.close () | 260 infile.close () |
261 else: | 261 else: |
262 input = sys.stdin.read () | 262 input = sys.stdin.read () |
263 | 263 |
264 to_version = None | 264 to_version = None |
265 org_version = None | 265 org_version = None |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 sys.exit (0) | 355 sys.exit (0) |
356 | 356 |
357 identify () | 357 identify () |
358 | 358 |
359 errors = 0 | 359 errors = 0 |
360 for f in files: | 360 for f in files: |
361 f = f.decode (sys.stdin.encoding or "utf-8") | 361 f = f.decode (sys.stdin.encoding or "utf-8") |
362 if f == '-': | 362 if f == '-': |
363 f = '' | 363 f = '' |
364 elif not os.path.isfile (f): | 364 elif not os.path.isfile (f): |
365 ly.error (_ (u"%s: Unable to open file") % f) | 365 ly.error (_ ("%s: Unable to open file") % f) |
366 errors += 1 | 366 errors += 1 |
367 continue | 367 continue |
368 try: | 368 try: |
369 errors += do_one_file (f) | 369 errors += do_one_file (f) |
370 except UnknownVersion: | 370 except UnknownVersion: |
371 ly.error (_ (u"%s: Unable to determine version. Skipping") % f) | 371 ly.error (_ ("%s: Unable to determine version. Skipping") % f) |
372 errors += 1 | 372 errors += 1 |
373 except InvalidVersion: | 373 except InvalidVersion: |
374 # Compat code for 2.x and 3.0 syntax ("except .. as v" doesn't· | 374 # Compat code for 2.x and 3.0 syntax ("except .. as v" doesn't· |
375 # work in python 2.4!): | 375 # work in python 2.4!): |
376 t, v, b = sys.exc_info () | 376 t, v, b = sys.exc_info () |
377 ly.error (_ (u"%s: Invalid version string `%s' \n" | 377 ly.error (_ ("%s: Invalid version string `%s' \n" |
378 "Valid version strings consist of three numbers, " | 378 "Valid version strings consist of three numbers, " |
379 "separated by dots, e.g. `2.8.12'") % (f, v.version) ) | 379 "separated by dots, e.g. `2.8.12'") % (f, v.version) ) |
380 errors += 1 | 380 errors += 1 |
381 | 381 |
382 if errors: | 382 if errors: |
383 ly.warning (ly.ungettext ("There was %d error.", | 383 ly.warning (ly.ungettext ("There was %d error.", |
384 "There were %d errors.", errors) % errors) | 384 "There were %d errors.", errors) % errors) |
385 sys.exit (1) | 385 sys.exit (1) |
386 | 386 |
387 main () | 387 main () |
OLD | NEW |