bug 1371601, prep: make variable names for reference entities nicer, r=stas
authorAxel Hecht <axel@pike.org>
Fri, 09 Jun 2017 13:57:04 +0200
changeset 281 a5d2a6476e667c61fbb8c180df14b2f75f9ef2b1
parent 278 868e29f6439c679b15972930e47f90ece2e4cf65
child 282 0dcd32f2781955a4b8f63e680af8de4d901497cc
push id79
push useraxel@mozilla.com
push dateWed, 28 Jun 2017 15:41:46 +0000
reviewersstas
bugs1371601
bug 1371601, prep: make variable names for reference entities nicer, r=stas MozReview-Commit-ID: ffpU9EMOuo
compare_locales/compare.py
--- a/compare_locales/compare.py
+++ b/compare_locales/compare.py
@@ -449,73 +449,74 @@ class ContentComparer:
         except UserWarning:
             # no comparison, XXX report?
             return
         try:
             p.readContents(ref_file.getContents())
         except Exception, e:
             self.notify('error', ref_file, str(e))
             return
-        ref = p.parse()
-        ref_list = sorted(ref[1].keys(), key=lambda k: ref[1][k])
+        ref_entities, ref_map = p.parse()
+        ref_list = sorted(ref_map.keys(), key=lambda k: ref_map[k])
         try:
             p.readContents(l10n.getContents())
             l10n_entities, l10n_map = p.parse()
             l10n_ctx = p.ctx
         except Exception, e:
             self.notify('error', l10n, str(e))
             return
 
         l10n_list = sorted(l10n_map.keys(), key=lambda k: l10n_map[k])
-        ar = AddRemove(key=indexof(ref[1]))
+        ar = AddRemove(key=indexof(ref_map))
         ar.set_left(ref_list)
         ar.set_right(l10n_list)
         report = missing = obsolete = changed = unchanged = keys = 0
         missing_w = changed_w = unchanged_w = 0  # word stats
         missings = []
         skips = []
-        checker = getChecker(l10n, reference=ref[0], extra_tests=extra_tests)
-        for action, entity in ar:
+        checker = getChecker(l10n,
+                             reference=ref_entities, extra_tests=extra_tests)
+        for action, entity_id in ar:
             if action == 'delete':
                 # missing entity
-                if isinstance(ref[0][ref[1][entity]], parser.Junk):
+                if isinstance(ref_entities[ref_map[entity_id]], parser.Junk):
                     self.notify('warning', l10n, 'Parser error in en-US')
                     continue
-                _rv = self.notify('missingEntity', l10n, entity)
+                _rv = self.notify('missingEntity', l10n, entity_id)
                 if _rv == "ignore":
                     continue
                 if _rv == "error":
                     # only add to missing entities for l10n-merge on error,
                     # not report
-                    missings.append(entity)
+                    missings.append(entity_id)
                     missing += 1
-                    refent = ref[0][ref[1][entity]]
+                    refent = ref_entities[ref_map[entity_id]]
                     missing_w += refent.count_words()
                 else:
                     # just report
                     report += 1
             elif action == 'add':
                 # obsolete entity or junk
-                if isinstance(l10n_entities[l10n_map[entity]],
+                if isinstance(l10n_entities[l10n_map[entity_id]],
                               parser.Junk):
-                    junk = l10n_entities[l10n_map[entity]]
+                    junk = l10n_entities[l10n_map[entity_id]]
                     params = (junk.val,) + junk.position() + junk.position(-1)
                     self.notify('error', l10n,
                                 'Unparsed content "%s" from line %d column %d'
                                 ' to line %d column %d' % params)
                     if merge_file is not None:
                         skips.append(junk)
                 elif self.notify('obsoleteEntity', l10n,
-                                 entity) != 'ignore':
+                                 entity_id) != 'ignore':
                     obsolete += 1
             else:
                 # entity found in both ref and l10n, check for changed
-                refent = ref[0][ref[1][entity]]
-                l10nent = l10n_entities[l10n_map[entity]]
-                if self.keyRE.search(entity):
+                refent = ref_entities[ref_map[entity_id]]
+                l10nent = l10n_entities[l10n_map[entity_id]]
+                if self.keyRE.search(entity_id):
                     keys += 1
                 else:
                     if refent.equals(l10nent):
                         self.doUnchanged(l10nent)
                         unchanged += 1
                         unchanged_w += refent.count_words()
                     else:
                         self.doChanged(ref_file, refent, l10nent)
@@ -530,17 +531,17 @@ class ContentComparer:
                             skips.append(l10nent)
                         self.notify(tp, l10n,
                                     u"%s at line %d, column %d for %s" %
                                     (msg, line, col, refent.key))
                 pass
 
         if merge_file is not None:
             self.merge(
-                ref[0], ref[1], ref_file,
+                ref_entities, ref_map, ref_file,
                 l10n, merge_file, missings, skips, l10n_ctx,
                 p.capabilities, p.encoding)
 
         stats = {}
         for cat, value in (
                 ('missing', missing),
                 ('missing_w', missing_w),
                 ('report', report),