From b49185fd713b3ea27a023cf30f0b1fc4d1940f71 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Wed, 7 Apr 2021 15:33:04 -0700 Subject: [PATCH] LP#1922975: update i18n scripts for Python 3 Signed-off-by: Jeff Davis Signed-off-by: Jane Sandberg Signed-off-by: Bill Erickson --- build/i18n/scripts/db-seed-i18n.py | 4 ++-- build/i18n/scripts/dojo_resource.py | 6 +++--- build/i18n/scripts/fieldmapper.py | 4 ++-- build/i18n/scripts/ils_events.py | 2 +- build/i18n/scripts/marc_tooltip_maker.py | 14 +++++++------- build/i18n/scripts/merge_ils_events.py | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/build/i18n/scripts/db-seed-i18n.py b/build/i18n/scripts/db-seed-i18n.py index 0528982158..7c59374c50 100755 --- a/build/i18n/scripts/db-seed-i18n.py +++ b/build/i18n/scripts/db-seed-i18n.py @@ -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) diff --git a/build/i18n/scripts/dojo_resource.py b/build/i18n/scripts/dojo_resource.py index 49560910ec..64ece4bdc0 100755 --- a/build/i18n/scripts/dojo_resource.py +++ b/build/i18n/scripts/dojo_resource.py @@ -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(): diff --git a/build/i18n/scripts/fieldmapper.py b/build/i18n/scripts/fieldmapper.py index 51e5ba560f..99a58024ac 100755 --- a/build/i18n/scripts/fieldmapper.py +++ b/build/i18n/scripts/fieldmapper.py @@ -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)) diff --git a/build/i18n/scripts/ils_events.py b/build/i18n/scripts/ils_events.py index 0afcc4cac3..9e359c49c8 100755 --- a/build/i18n/scripts/ils_events.py +++ b/build/i18n/scripts/ils_events.py @@ -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]] diff --git a/build/i18n/scripts/marc_tooltip_maker.py b/build/i18n/scripts/marc_tooltip_maker.py index 90b606842c..f563166fc1 100755 --- a/build/i18n/scripts/marc_tooltip_maker.py +++ b/build/i18n/scripts/marc_tooltip_maker.py @@ -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), diff --git a/build/i18n/scripts/merge_ils_events.py b/build/i18n/scripts/merge_ils_events.py index 0e884551c7..57491e35c2 100755 --- a/build/i18n/scripts/merge_ils_events.py +++ b/build/i18n/scripts/merge_ils_events.py @@ -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() -- 2.11.0