bug 1361037, part 3: remove ini-specific code that is now unused, r=flod, stas
authorAxel Hecht <axel@pike.org>
Fri, 12 May 2017 19:31:37 +0200
changeset 234 1a9277b5b40cf434d6b85ccd546b7fbb91fcad05
parent 233 8ed0fa3e420b5417e0ddb926b5193d3854c32c4e
child 235 bb991de43bbaeca50e4ced3c42d69a059c6b3d0d
push id48
push useraxel@mozilla.com
push dateFri, 26 May 2017 11:10:47 +0000
reviewersflod, stas
bugs1361037
bug 1361037, part 3: remove ini-specific code that is now unused, r=flod, stas MozReview-Commit-ID: 5bBerC6h9SW
compare_locales/compare.py
compare_locales/paths.py
--- a/compare_locales/compare.py
+++ b/compare_locales/compare.py
@@ -143,46 +143,16 @@ class AddRemove(SequenceMatcher):
             else:
                 # tag == 'replace'
                 for item in self.a[i1:i2]:
                     yield ('delete', item)
                 for item in self.b[j1:j2]:
                     yield ('add', item)
 
 
-class DirectoryCompare(SequenceMatcher):
-    def __init__(self, reference):
-        SequenceMatcher.__init__(self, None, [i for i in reference],
-                                 [])
-        self.watcher = None
-
-    def setWatcher(self, watcher):
-        self.watcher = watcher
-
-    def compareWith(self, other):
-        if not self.watcher:
-            return
-        self.set_seq2([i for i in other])
-        for tag, i1, i2, j1, j2 in self.get_opcodes():
-            if tag == 'equal':
-                for i, j in zip(xrange(i1, i2), xrange(j1, j2)):
-                    self.watcher.compare(self.a[i], self.b[j])
-            elif tag == 'delete':
-                for i in xrange(i1, i2):
-                    self.watcher.add(self.a[i], other.cloneFile(self.a[i]))
-            elif tag == 'insert':
-                for j in xrange(j1, j2):
-                    self.watcher.remove(self.b[j])
-            else:
-                for j in xrange(j1, j2):
-                    self.watcher.remove(self.b[j])
-                for i in xrange(i1, i2):
-                    self.watcher.add(self.a[i], other.cloneFile(self.a[i]))
-
-
 class Observer(object):
     stat_cats = ['missing', 'obsolete', 'missingInFiles', 'report',
                  'changed', 'unchanged', 'keys']
 
     def __init__(self):
         class intdict(defaultdict):
             def __init__(self):
                 defaultdict.__init__(self, int)
@@ -571,49 +541,16 @@ class ContentComparer:
         # overload this if needed
         pass
 
     def doChanged(self, file, ref_entity, l10n_entity):
         # overload this if needed
         pass
 
 
-def compareApp(app, other_observer=None, merge_stage=None, clobber=False):
-    '''Compare locales set in app.
-
-    Optional arguments are:
-    - other_observer. A object implementing
-        notify(category, _file, data)
-      The return values of that callback are ignored.
-    - merge_stage. A directory to be used for staging the output of
-      l10n-merge.
-    - clobber. Clobber the module subdirectories of the merge dir as we go.
-      Use wisely, as it might cause data loss.
-    '''
-    comparer = ContentComparer()
-    if other_observer is not None:
-        comparer.add_observer(other_observer)
-    comparer.observer.filter = app.filter
-    for module, reference, locales in app:
-        dir_comp = DirectoryCompare(reference)
-        dir_comp.setWatcher(comparer)
-        for _, localization in locales:
-            if merge_stage is not None:
-                locale_merge = merge_stage.format(ab_CD=localization.locale)
-                comparer.set_merge_stage(locale_merge)
-                if clobber:
-                    # if clobber, remove the stage for the module if it exists
-                    clobberdir = mozpath.join(locale_merge, module)
-                    if os.path.exists(clobberdir):
-                        shutil.rmtree(clobberdir)
-                        print "clobbered " + clobberdir
-            dir_comp.compareWith(localization)
-    return comparer.observer
-
-
 def compareProjects(project_configs, other_observer=None,
                     merge_stage=None, clobber_merge=False):
     assert len(project_configs) == 1  # we're not there yet for multiple
     comparer = ContentComparer()
     if other_observer is not None:
         comparer.add_observer(other_observer)
     project = project_configs[0]
     comparer.observer.filter = project.filter
--- a/compare_locales/paths.py
+++ b/compare_locales/paths.py
@@ -428,73 +428,16 @@ class File(object):
         if not isinstance(other, File):
             raise NotImplementedError
         rv = cmp(self.module, other.module)
         if rv != 0:
             return rv
         return cmp(self.file, other.file)
 
 
-class EnumerateDir(object):
-    ignore_dirs = ['CVS', '.svn', '.hg', '.git']
-
-    def __init__(self, basepath, module='', locale=None, ignore_subdirs=[]):
-        self.basepath = basepath
-        self.module = module
-        self.locale = locale
-        self.ignore_subdirs = ignore_subdirs
-        pass
-
-    def cloneFile(self, other):
-        '''
-        Return a File object that this enumerator would return, if it had it.
-        '''
-        return File(mozpath.join(self.basepath, other.file), other.file,
-                    self.module, self.locale)
-
-    def __iter__(self):
-        # our local dirs are given as a tuple of path segments, starting off
-        # with an empty sequence for the basepath.
-        dirs = [()]
-        while dirs:
-            dir = dirs.pop(0)
-            fulldir = mozpath.join(self.basepath, *dir)
-            try:
-                entries = os.listdir(fulldir)
-            except OSError:
-                # we probably just started off in a non-existing dir, ignore
-                continue
-            entries.sort()
-            for entry in entries:
-                leaf = mozpath.join(fulldir, entry)
-                if os.path.isdir(leaf):
-                    if entry not in self.ignore_dirs and \
-                        leaf not in [mozpath.join(self.basepath, d)
-                                     for d in self.ignore_subdirs]:
-                        dirs.append(dir + (entry,))
-                    continue
-                yield File(leaf, '/'.join(dir + (entry,)),
-                           self.module, self.locale)
-
-
-class LocalesWrap(object):
-
-    def __init__(self, base, module, locales, ignore_subdirs=[]):
-        self.base = base
-        self.module = module
-        self.locales = locales
-        self.ignore_subdirs = ignore_subdirs
-
-    def __iter__(self):
-        for locale in self.locales:
-            path = mozpath.join(self.base, locale, self.module)
-            yield (locale, EnumerateDir(path, self.module, locale,
-                                        self.ignore_subdirs))
-
-
 class EnumerateApp(object):
     reference = 'en-US'
 
     def __init__(self, inipath, l10nbase, locales=None):
         self.setupConfigParser(inipath)
         self.modules = defaultdict(dict)
         self.l10nbase = mozpath.abspath(l10nbase)
         self.filters = []
@@ -528,60 +471,16 @@ class EnumerateApp(object):
                                          (self.l10nbase, module))
             }
             if module == 'mobile/android/base':
                 paths['test'] = ['android-dtd']
             projectconfig.add_paths(paths)
         for child in aConfig.children:
             self._config_for_ini(projectconfig, child)
 
-    value_map = {None: None, 'error': 0, 'ignore': 1, 'report': 2}
-
-    def filter(self, l10n_file, entity=None):
-        '''Go through all added filters, and,
-        - map "error" -> 0, "ignore" -> 1, "report" -> 2
-        - if filter.test returns a bool, map that to
-            False -> "ignore" (1), True -> "error" (0)
-        - take the max of all reported
-        '''
-        rv = 0
-        for f in reversed(self.filters):
-            try:
-                _r = f(l10n_file.module, l10n_file.file, entity)
-            except:
-                # XXX error handling
-                continue
-            if isinstance(_r, bool):
-                _r = [1, 0][_r]
-            else:
-                # map string return value to int, default to 'error',
-                # None is None
-                _r = self.value_map.get(_r, 0)
-            if _r is not None:
-                rv = max(rv, _r)
-        return ['error', 'ignore', 'report'][rv]
-
-    def __iter__(self):
-        '''
-        Iterate over all modules, return en-US directory enumerator, and an
-        iterator over all locales in each iteration. Per locale, the locale
-        code and an directory enumerator will be given.
-        '''
-        dirmap = dict(self.config.directories())
-        mods = dirmap.keys()
-        mods.sort()
-        for mod in mods:
-            if self.reference == 'en-US':
-                base = mozpath.join(*(dirmap[mod] + ('locales', 'en-US')))
-            else:
-                base = mozpath.join(self.l10nbase, self.reference, mod)
-            yield (mod, EnumerateDir(base, mod, self.reference),
-                   LocalesWrap(self.l10nbase, mod, self.locales,
-                   [m[len(mod)+1:] for m in mods if m.startswith(mod+'/')]))
-
 
 class EnumerateSourceTreeApp(EnumerateApp):
     '''Subclass EnumerateApp to work on side-by-side checked out
     repos, and to no pay attention to how the source would actually
     be checked out for building.
     '''
 
     def __init__(self, inipath, basepath, l10nbase, redirects,