LP#1922975: update i18n scripts for Python 3
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 7 Apr 2021 22:33:04 +0000 (15:33 -0700)
committerBill Erickson <berickxx@gmail.com>
Wed, 16 Mar 2022 19:18:16 +0000 (15:18 -0400)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
build/i18n/scripts/db-seed-i18n.py
build/i18n/scripts/dojo_resource.py
build/i18n/scripts/fieldmapper.py
build/i18n/scripts/ils_events.py
build/i18n/scripts/marc_tooltip_maker.py
build/i18n/scripts/merge_ils_events.py

index 0528982..7c59374 100755 (executable)
@@ -96,8 +96,8 @@ class SQL(basel10n.BaseL10N):
                     poe.occurrences = [(os.path.basename(source), num)]
                     poe.msgid = msgid
                     serts[msgid] = poe
-        except Exception, exc:
-            print "Error in oils_i18n_gettext line %d of SQL source file: %s" % (num, exc)
+        except Exception as exc:
+            print("Error in oils_i18n_gettext line %d of SQL source file: %s" % (num, exc))
 
         for poe in serts.values():
             self.pot.append(poe)
index 4956091..64ece4b 100755 (executable)
@@ -59,10 +59,10 @@ class DojoResource (basel10n.BaseL10N):
         # Avoid generating duplicate entries by keeping track of msgids
         msgids = dict()
 
-       try:
+        try:
             bundle = simplejson.load(codecs.open(source, encoding='utf-8', mode='r'))
-       except ValueError:
-           print("Reading Dojo resource file %s" % (source))
+        except ValueError:
+            print("Reading Dojo resource file %s" % (source))
             raise
 
         for key, value in bundle.iteritems():
index 51e5ba5..99a5802 100755 (executable)
@@ -107,7 +107,7 @@ class IDLHandler(xml.sax.handler.ContentHandler):
         lineno = self.locator.getLineNumber()
         if name == 'class':
             self.classid = attributes['id']
-        if attributes.has_key('reporter:label'):
+        if 'reporter:label' in attributes:
             if name == 'class':
                 entity = "%s.%s.label" % (name, self.classid)
             elif name == 'field':
@@ -117,7 +117,7 @@ class IDLHandler(xml.sax.handler.ContentHandler):
                 entity = "%s.%s.%s.label" % (name, self.classid, \
                     attributes['field'])
             label = attributes['reporter:label']
-            if not self.entities.has_key(label):
+            if label not in self.entities:
                 self.entities[label] = [(str(entity), lineno)]
             else:
                 self.entities[label].append((str(entity), lineno))
index 0afcc4c..9e359c4 100755 (executable)
@@ -151,7 +151,7 @@ class ILSEventHandler(xml.sax.handler.ContentHandler):
         if name == 'desc' and self.en_us_flag is True:
             lineno = self.locator.getLineNumber()
             event = "%d.%s" % (int(self.numcode), self.textcode)
-            if self.events.has_key(self.desc):
+            if self.desc in self.events:
                 self.events[self.desc].append([str(event), lineno])
             else:
                 self.events[self.desc] = [[str(event), lineno]]
index 90b6068..f563166 100755 (executable)
@@ -179,7 +179,7 @@ def process_indicator(field, position, raw_ind):
     if (re.compile(r'indicateur\s*-\s*Non').search(raw_ind.contents[0])):
         return None
     if (not raw_ind.ul):
-        print "No %d indicator for %s, although not not defined either..." % (position, field.tag)
+        print("No %d indicator for %s, although not not defined either..." % (position, field.tag))
         return None
     ind_values = raw_ind.ul.findAll('li')
     for value in ind_values:
@@ -208,12 +208,12 @@ def process_subfield(field, subfield):
             repeatable = 'false'
         subfield.small.extract()
     else:
-        print "%s has no small or span tags?" % (field.tag)
+        print("%s has no small or span tags?" % (field.tag))
 
     subfield_text = re.compile(r'\n').sub(' ', ''.join(subfield.findAll(text=True)))
     matches = re.compile(r'^\$(\w)\s*-\s*(.+)$', re.S).search(subfield_text)
     if (not matches):
-        print "No subfield match for field: " + field.tag
+        print("No subfield match for field: " + field.tag)
         return None
     field.subfields.append(Subfield(matches.group(1).replace('\n', ' ').rstrip(), repeatable, matches.group(2).replace('\n', ' ').rstrip()))
 
@@ -242,14 +242,14 @@ def process_tag(tag):
     # Get description
     desc = tag.parent.findNextSibling('p')
     if (not desc):
-        print "No description for %s" % (tag_num)
+        print("No description for %s" % (tag_num))
     else:
         if (str(desc.__class__) == 'BeautifulSoup.Tag'):
             try:
                 description += u''.join(desc.findAll(text=True))
             except:
-                print "Bad description for: " + tag_num
-                print u' '.join(desc.findAll(text=True))
+                print("Bad description for: " + tag_num)
+                print(u' '.join(desc.findAll(text=True)))
         else:
             description += desc.string
     description = description.replace('\n', ' ').rstrip()
@@ -292,7 +292,7 @@ if __name__ == '__main__':
 
         if (not re.compile(r'^040010-1\d\d\d-f.html').search(filename)):
             continue
-        print filename
+        print(filename)
         devnull = codecs.open('/dev/null', encoding='utf-8', mode='w')
         file = subprocess.Popen(
             ('tidy', '-asxml', '-n', '-q', '-utf8', filename),
index 0e88455..57491e3 100755 (executable)
@@ -76,16 +76,16 @@ def main():
         merged = merge_events(options.master, options.localization)
 
     if options.outfile:
-        outfile = open(options.outfile, 'w')
+        outfile = open(options.outfile, 'wb')
         if options.pretty:
             outfile.write(merged.toprettyxml(encoding='utf-8'))
         else:
             outfile.write(merged.toxml(encoding='utf-8'))
     else:
         if options.pretty:
-            print merged.toprettyxml(encoding='utf-8')
+            print(merged.toprettyxml(encoding='utf-8'))
         else:
-            print merged.toxml(encoding='utf-8')
+            print(merged.toxml(encoding='utf-8'))
 
 if __name__ == '__main__':
     main()