예제 #1
0
 def __init__(self, locale, projects, mergebase=None):
     self.locale = locale
     self.matchers = []
     self.mergebase = mergebase
     configs = []
     for project in projects:
         configs.extend(project.configs)
     for pc in configs:
         if locale not in pc.locales:
             continue
         for paths in pc.paths:
             if 'locales' in paths and locale not in paths['locales']:
                 continue
             m = {
                 'l10n': paths['l10n']({
                     "locale": locale
                 }),
                 'module': paths.get('module'),
             }
             if 'reference' in paths:
                 m['reference'] = paths['reference']
             if self.mergebase is not None:
                 m['merge'] = paths['l10n']({
                     "locale": locale,
                     "l10n_base": self.mergebase
                 })
             m['test'] = set(paths.get('test', []))
             if 'locales' in paths:
                 m['locales'] = paths['locales'][:]
             self.matchers.append(m)
     self.matchers.reverse()  # we always iterate last first
     # Remove duplicate patterns, comparing each matcher
     # against all other matchers.
     # Avoid n^2 comparisons by only scanning the upper triangle
     # of a n x n matrix of all possible combinations.
     # Using enumerate and keeping track of indexes, as we can't
     # modify the list while iterating over it.
     drops = set()  # duplicate matchers to remove
     for i, m in enumerate(self.matchers[:-1]):
         if i in drops:
             continue  # we're dropping this anyway, don't search again
         for i_, m_ in enumerate(self.matchers[(i + 1):]):
             if (mozpath.realpath(m['l10n'].prefix) != mozpath.realpath(
                     m_['l10n'].prefix)):
                 # ok, not the same thing, continue
                 continue
             # check that we're comparing the same thing
             if 'reference' in m:
                 if (mozpath.realpath(m['reference'].prefix) !=
                         mozpath.realpath(m_.get('reference').prefix)):
                     raise RuntimeError('Mismatch in reference for ' +
                                        mozpath.realpath(m['l10n'].prefix))
             drops.add(i_ + i + 1)
             m['test'] |= m_['test']
     drops = sorted(drops, reverse=True)
     for i in drops:
         del self.matchers[i]
예제 #2
0
 def __init__(self, locale, projects, mergebase=None):
     self.locale = locale
     self.matchers = []
     self.exclude = None
     self.mergebase = mergebase
     configs = ConfigList()
     excludes = ConfigList()
     for project in projects:
         # Only add this project if we're not in validation mode,
         # and the given locale is enabled for the project.
         if locale is not None and locale not in project.all_locales:
             continue
         configs.maybe_extend(project.configs)
         excludes.maybe_extend(project.excludes)
     # If an excluded config is explicitly included, drop if from the
     # excludes.
     excludes = [
         exclude for exclude in excludes
         if not any(c.path == exclude.path for c in configs)
     ]
     if excludes:
         self.exclude = ProjectFiles(locale, excludes)
     for pc in configs:
         if locale and pc.locales is not None and locale not in pc.locales:
             continue
         for paths in pc.paths:
             if (locale and 'locales' in paths
                     and locale not in paths['locales']):
                 continue
             m = {
                 'l10n':
                 paths['l10n'].with_env(
                     {"locale": locale or REFERENCE_LOCALE}),
                 'module':
                 paths.get('module'),
             }
             if 'reference' in paths:
                 m['reference'] = paths['reference']
             if self.mergebase is not None:
                 m['merge'] = paths['l10n'].with_env({
                     "locale":
                     locale,
                     "l10n_base":
                     self.mergebase
                 })
             m['test'] = set(paths.get('test', []))
             if 'locales' in paths:
                 m['locales'] = paths['locales'][:]
             self.matchers.append(m)
     self.matchers.reverse()  # we always iterate last first
     # Remove duplicate patterns, comparing each matcher
     # against all other matchers.
     # Avoid n^2 comparisons by only scanning the upper triangle
     # of a n x n matrix of all possible combinations.
     # Using enumerate and keeping track of indexes, as we can't
     # modify the list while iterating over it.
     drops = set()  # duplicate matchers to remove
     for i, m in enumerate(self.matchers[:-1]):
         if i in drops:
             continue  # we're dropping this anyway, don't search again
         for i_, m_ in enumerate(self.matchers[(i + 1):]):
             if (mozpath.realpath(m['l10n'].prefix) != mozpath.realpath(
                     m_['l10n'].prefix)):
                 # ok, not the same thing, continue
                 continue
             # check that we're comparing the same thing
             if 'reference' in m:
                 if (mozpath.realpath(m['reference'].prefix) !=
                         mozpath.realpath(m_.get('reference').prefix)):
                     raise RuntimeError('Mismatch in reference for ' +
                                        mozpath.realpath(m['l10n'].prefix))
             drops.add(i_ + i + 1)
             m['test'] |= m_['test']
     drops = sorted(drops, reverse=True)
     for i in drops:
         del self.matchers[i]