• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision29422 (tree)
Time2022-06-19 04:29:31
Authordanielsahlberg

Log Message

Migrate xml2po.py scripts to Python3. (*checkpointing* ... so far only tested on Linux)

Change Summary

Incremental Difference

--- trunk/doc/xml2po-modes/docbook.py (revision 29421)
+++ trunk/doc/xml2po-modes/docbook.py (revision 29422)
@@ -33,6 +33,9 @@
3333 # it is also not necessary until we start supporting extracting strings from more
3434 # than one document type at the same time
3535 #
36+
37+from __future__ import print_function
38+
3639 import re
3740 import libxml2
3841 import os
@@ -133,7 +136,7 @@
133136 hash = self._md5_for_file(fullpath)
134137 else:
135138 hash = "THIS FILE DOESN'T EXIST"
136- print >>sys.stderr, "Warning: image file '%s' not found." % fullpath
139+ print("Warning: image file '%s' not found." % fullpath, file=sys.stderr)
137140
138141 msg.outputMessage("@@image: '%s'; md5=%s" % (attr, hash), node.lineNo(),
139142 "When image changes, this message will be marked fuzzy or untranslated for you.\n"+
@@ -201,13 +204,13 @@
201204 # Perform some tests when ran standalone
202205 if __name__ == '__main__':
203206 test = docbookXmlMode()
204- print "Ignored tags : " + repr(test.getIgnoredTags())
205- print "Final tags : " + repr(test.getFinalTags())
206- print "Space-preserve tags: " + repr(test.getSpacePreserveTags())
207+ print("Ignored tags : " + repr(test.getIgnoredTags()))
208+ print("Final tags : " + repr(test.getFinalTags()))
209+ print("Space-preserve tags: " + repr(test.getSpacePreserveTags()))
207210
208- print "Credits from string: '%s'" % test.getStringForTranslators()
209- print "Explanation for credits:\n\t'%s'" % test.getCommentForTranslators()
211+ print("Credits from string: '%s'" % test.getStringForTranslators())
212+ print("Explanation for credits:\n\t'%s'" % test.getCommentForTranslators())
210213
211- print "String for translation: '%s'" % test.getStringForTranslation()
212- print "Explanation for translation:\n\t'%s'" % test.getCommentForTranslation()
214+ print("String for translation: '%s'" % test.getStringForTranslation())
215+ print("Explanation for translation:\n\t'%s'" % test.getCommentForTranslation())
213216
--- trunk/doc/xml2po.py (revision 29421)
+++ trunk/doc/xml2po.py (revision 29422)
@@ -32,6 +32,9 @@
3232 # 2.2 second stable release (release 2), and 2.2.* bugfix releases
3333 # ...
3434 #
35+
36+from __future__ import print_function
37+
3538 import sys
3639 import libxml2
3740 import gettext
@@ -98,7 +101,7 @@
98101
99102 """ % (tstamp)
100103
101- out.write(tmp.encode('utf-8'))
104+ out.write(tmp)
102105
103106 def outputAll(self, out):
104107 self.outputHeader(out)
@@ -159,7 +162,7 @@
159162 tree = ctxt.doc()
160163 newnode = tree.getRootElement()
161164 except:
162- print >> sys.stderr, """Error while normalizing string as XML:\n"%s"\n""" % (text)
165+ print("""Error while normalizing string as XML:\n"%s"\n""" % (text), file=sys.stderr)
163166 return text
164167
165168 normalizeNode(newnode)
@@ -340,7 +343,7 @@
340343 ctxt.parseDocument()
341344 newnode = ctxt.doc()
342345 except:
343- print >> sys.stderr, """Error while parsing translation as XML:\n"%s"\n""" % (text.encode('utf-8'))
346+ print("""Error while parsing translation as XML:\n"%s"\n""" % (text.encode('utf-8')), file=sys.stderr)
344347 return
345348
346349 newelem = newnode.getRootElement()
@@ -448,7 +451,7 @@
448451 if (node and node.type=='entity_ref'):
449452 try:
450453 # it would be nice if debugDumpNode could use StringIO, but it apparently cannot
451- tmp = file(".xml2po-entitychecking","w+")
454+ tmp = open(".xml2po-entitychecking","w+")
452455 node.debugDumpNode(tmp,0)
453456 tmp.seek(0)
454457 tmpstr = tmp.read()
@@ -536,7 +539,7 @@
536539 sys.stderr.write("Error: Option '-o' is not yet supported when updating translations directly.\n")
537540 sys.exit(8)
538541 elif opt in ('-v', '--version'):
539- print VERSION
542+ print(VERSION)
540543 sys.exit(0)
541544 elif opt in ('-h', '--help'):
542545 sys.stderr.write("Error: If you want help, please use `%s --help' without '-u' option.\n" % (allargs[0]))
@@ -590,7 +593,7 @@
590593 global t1
591594 t2 = datetime.now()
592595 tdelta = t2 - t1
593- print >> sys.stderr, messg," (",tdelta.seconds, ",", tdelta.microseconds,")"
596+ print(messg," (",tdelta.seconds, ",", tdelta.microseconds,")", file=sys.stderr)
594597
595598 # timetick( "xml2po started")
596599
@@ -618,9 +621,9 @@
618621 import getopt, fileinput
619622
620623 def usage (with_help = False):
621- print >> sys.stderr, "Usage: %s [OPTIONS] [XMLFILE]..." % (sys.argv[0])
624+ print("Usage: %s [OPTIONS] [XMLFILE]..." % (sys.argv[0]), file=sys.stderr)
622625 if (with_help):
623- print >> sys.stderr, """
626+ print("""
624627 OPTIONS may be some of:
625628 -a --automatic-tags Automatically decides if tags are to be considered
626629 "final" or not
@@ -646,7 +649,7 @@
646649 using -p option for each XML file:
647650 %s -p de.po chapter1.xml > chapter1.de.xml
648651 %s -p de.po chapter2.xml > chapter2.de.xml
649-""" % (sys.argv[0], sys.argv[0], sys.argv[0])
652+""" % (sys.argv[0], sys.argv[0], sys.argv[0]), file=sys.stderr)
650653 sys.exit(0)
651654
652655 if len(sys.argv) < 2: usage()
@@ -683,7 +686,7 @@
683686 elif opt in ('-o', '--output'):
684687 output = arg
685688 elif opt in ('-v', '--version'):
686- print VERSION
689+ print(VERSION)
687690 sys.exit(0)
688691 elif opt in ('-h', '--help'):
689692 usage(True)
@@ -693,7 +696,7 @@
693696 filenames.append(args.pop())
694697
695698 if len(filenames) > 1 and mode=='merge':
696- print >> sys.stderr, "Error: You can merge translations with only one XML file at a time."
699+ print("Error: You can merge translations with only one XML file at a time.", file=sys.stderr)
697700 sys.exit(2)
698701
699702 try:
@@ -700,11 +703,11 @@
700703 CurrentXmlMode = load_mode(default_mode)()
701704 except:
702705 CurrentXmlMode = None
703- print >> sys.stderr, "Warning: cannot load module '%s', using automatic detection (-a)." % (default_mode)
706+ print("Warning: cannot load module '%s', using automatic detection (-a)." % (default_mode), file=sys.stderr)
704707 automatic = 1
705708
706709 if mode=='merge' and mofile=='':
707- print >> sys.stderr, "Error: You must specify MO file when merging translations."
710+ print("Error: You must specify MO file when merging translations.", file=sys.stderr)
708711 sys.exit(3)
709712
710713 ultimate_tags = read_finaltags(ultimate)
@@ -736,7 +739,7 @@
736739 # timetick( "document parsed")
737740 doc = ctxt.doc()
738741 except:
739- print >> sys.stderr, "Error: cannot open file '%s'." % (filename)
742+ print("Error: cannot open file '%s'." % (filename), file=sys.stderr)
740743 sys.exit(1)
741744
742745 msg.setFilename(filename)
@@ -752,9 +755,9 @@
752755 out = sys.stdout
753756 else:
754757 try:
755- out = file(output, 'w')
758+ out = open(output, 'w')
756759 except:
757- print >> sys.stderr, "Error: cannot open file %s for writing." % (output)
760+ print("Error: cannot open file %s for writing." % (output), file=sys.stderr)
758761 sys.exit(5)
759762
760763 if mode != 'merge':
Show on old repository browser