def test_includes(self):
        parser = MockTOMLParser({
            "root.toml": """
basepath = "."
[env]
  o = "toolkit"
[[includes]]
  path = "{o}/other.toml"
[[includes]]
  path = "dom/more.toml"
""",
            "other.toml": """
basepath = "."
""",
            "more.toml": """
basepath = "."
"""
        })
        config = parser.parse("root.toml")
        self.assertIsInstance(config, ProjectConfig)
        configs = list(config.configs)
        self.assertEqual(configs[0], config)
        self.assertListEqual(
            [c.path for c in configs],
            [
                "root.toml",
                mozpath.abspath("toolkit/other.toml"),
                mozpath.abspath("dom/more.toml"),
            ]
        )
Beispiel #2
0
    def extract_positionals(
        self,
        validate=False,
        config_paths=[], l10n_base_dir=None, locales=[],
    ):
        # using nargs multiple times in argparser totally screws things
        # up, repair that.
        # First files are configs, then the base dir, everything else is
        # locales
        all_args = config_paths + [l10n_base_dir] + locales
        config_paths = []
        # The first directory is our l10n base, split there.
        while all_args and not os.path.isdir(all_args[0]):
            config_paths.append(all_args.pop(0))
        if not config_paths:
            self.parser.error('no configuration file given')
        for cf in config_paths:
            if not os.path.isfile(cf):
                self.parser.error('config file %s not found' % cf)
        if not all_args:
            self.parser.error('l10n-base-dir not found')
        l10n_base_dir = mozpath.abspath(all_args.pop(0))
        if validate:
            # signal validation mode by setting locale list to [None]
            locales = [None]
        else:
            locales = all_args

        return config_paths, l10n_base_dir, locales
 def load(self):
     p = configparser.TOMLParser()
     del self.configs[:]
     for path in self.config_paths:
         cfg = p.parse(path, env={"l10n_base": mozpath.abspath(".")})
         cfg.set_locales(["en-US"], True)
         self.configs.append(cfg)
Beispiel #4
0
 def set_root(self, basepath):
     if self.path is None:
         self.root = None
         return
     self.root = mozpath.abspath(
         mozpath.join(mozpath.dirname(self.path), basepath)
     )
Beispiel #5
0
    def extract_positionals(
        self,
        validate=False,
        config_paths=[],
        l10n_base_dir=None,
        locales=[],
    ):
        # using nargs multiple times in argparser totally screws things
        # up, repair that.
        # First files are configs, then the base dir, everything else is
        # locales
        all_args = config_paths + [l10n_base_dir] + locales
        config_paths = []
        # The first directory is our l10n base, split there.
        while all_args and not os.path.isdir(all_args[0]):
            config_paths.append(all_args.pop(0))
        if not config_paths:
            self.parser.error('no configuration file given')
        for cf in config_paths:
            if not os.path.isfile(cf):
                self.parser.error('config file %s not found' % cf)
        if not all_args:
            self.parser.error('l10n-base-dir not found')
        l10n_base_dir = mozpath.abspath(all_args.pop(0))
        if validate:
            # signal validation mode by setting locale list to [None]
            locales = [None]
        else:
            locales = all_args

        return config_paths, l10n_base_dir, locales
Beispiel #6
0
 def set_root(self, basepath):
     if self.path is None:
         self.root = None
         return
     self.root = mozpath.abspath(
         mozpath.join(mozpath.dirname(self.path), basepath)
     )
Beispiel #7
0
 def __init__(self, pattern_or_other, env={}, root=None, encoding=None):
     '''Create regular expression similar to mozpath.match().
     '''
     parser = PatternParser()
     real_env = {k: parser.parse(v) for k, v in env.items()}
     self._cached_re = None
     if root is not None:
         # make sure that our root is fully expanded and ends with /
         root = mozpath.abspath(root) + '/'
     # allow constructing Matchers from Matchers
     if isinstance(pattern_or_other, Matcher):
         other = pattern_or_other
         self.pattern = Pattern(other.pattern)
         self.env = other.env.copy()
         self.env.update(real_env)
         if root is not None:
             self.pattern.root = root
         self.encoding = other.encoding
         return
     self.env = real_env
     pattern = pattern_or_other
     self.pattern = parser.parse(pattern)
     if root is not None:
         self.pattern.root = root
     self.encoding = encoding
Beispiel #8
0
 def __init__(self, repo, rev, projects):
     self.repo = repo
     self.ctx = repo[rev]
     self.root = repo.root()
     self.manifest = None
     self.configs_map = {}
     # get paths for our TOML files
     for p in projects:
         all_configpaths = {
             mozpath.abspath(c.path).encode("utf-8")
             for c in p.configs
         }
         for refpath in all_configpaths:
             local_path = mozpath.relpath(refpath, self.root)
             if local_path not in self.ctx:
                 print("ignoring", refpath)
                 continue
             targetpath = b"/".join((
                 expand(None, "{l10n_base}", p.environ).encode("utf-8"),
                 b"en-US",
                 generate_filename(local_path),
             ))
             self.configs_map[refpath] = targetpath
     super(HGFiles, self).__init__("en-US", projects)
     for m in self.matchers:
         m["l10n"].encoding = "utf-8"
         if "reference" in m:
             m["reference"].encoding = "utf-8"
     if self.exclude:
         for m in self.exclude.matchers:
             m["l10n"].encoding = "utf-8"
             if "reference" in m:
                 m["reference"].encoding = "utf-8"
Beispiel #9
0
 def __init__(self, inipath, l10nbase, locales=None):
     self.setupConfigParser(inipath)
     self.modules = defaultdict(dict)
     self.l10nbase = mozpath.abspath(l10nbase)
     self.filters = []
     self.addFilters(*self.config.getFilters())
     self.locales = locales or self.config.allLocales()
     self.locales.sort()
    def test_excludes(self):
        parser = MockTOMLParser({
            "root.toml": """
basepath = "."
[[excludes]]
  path = "exclude.toml"
[[excludes]]
  path = "other-exclude.toml"
  """,
            "exclude.toml": """
basepath = "."
""",
            "other-exclude.toml": """
basepath = "."
""",
            "grandparent.toml": """
basepath = "."
[[includes]]
  path = "root.toml"
""",
            "wrapped.toml": """
basepath = "."
[[excludes]]
  path = "root.toml"
 """
        })
        config = parser.parse("root.toml")
        self.assertIsInstance(config, ProjectConfig)
        configs = list(config.configs)
        self.assertListEqual(configs, [config])
        self.assertEqual(
            [c.path for c in config.excludes],
            [
                mozpath.abspath("exclude.toml"),
                mozpath.abspath("other-exclude.toml"),
            ]
        )
        with six.assertRaisesRegex(self, ExcludeError, 'Included configs'):
            parser.parse("grandparent.toml")
        with six.assertRaisesRegex(self, ExcludeError, 'Excluded configs'):
            parser.parse("wrapped.toml")
 def gather(self):
     fls = files.ProjectFiles("en-US", self.configs)
     results = [{} for cfg in self.configs]
     for l10n_path, f, _, tests in fls:
         if "android-dtd" in tests:
             # ignore Android native strings
             continue
         try:
             p = parser.getParser(f)
         except UserWarning:
             continue
         p.readFile(f)
         string_count = len(list(p))
         for i, cfg in enumerate(self.configs):
             l10n_file = paths.File(l10n_path,
                                    mozpath.relpath(l10n_path,
                                                    mozpath.abspath(".")),
                                    locale='en-US')
             if cfg.filter(l10n_file) != "ignore":
                 results[i][l10n_file.file] = string_count
     return results
    def test_imports(self):
        parser = MockTOMLParser({
            "root.toml": """
basepath = "."
[env]
  o = "toolkit"
[[includes]]
  path = "{o}/other.toml"
""",
            "other.toml": """
basepath = "."
"""
        })
        config = parser.parse("root.toml")
        self.assertIsInstance(config, ProjectConfig)
        configs = list(config.configs)
        self.assertEqual(configs[0], config)
        self.assertListEqual(
            [c.path for c in configs],
            ["root.toml", mozpath.abspath("toolkit/other.toml")]
        )
Beispiel #13
0
 def __init__(self, pattern_or_other, env={}, root=None):
     '''Create regular expression similar to mozpath.match().
     '''
     parser = PatternParser()
     real_env = {k: parser.parse(v) for k, v in env.items()}
     self._cached_re = None
     if root is not None:
         # make sure that our root is fully expanded and ends with /
         root = mozpath.abspath(root) + '/'
     # allow constructing Matchers from Matchers
     if isinstance(pattern_or_other, Matcher):
         other = pattern_or_other
         self.pattern = Pattern(other.pattern)
         self.env = other.env.copy()
         self.env.update(real_env)
         if root is not None:
             self.pattern.root = root
         return
     self.env = real_env
     pattern = pattern_or_other
     self.pattern = parser.parse(pattern)
     if root is not None:
         self.pattern.root = root
Beispiel #14
0
 def __init__(self, inipath, l10nbase):
     self.setupConfigParser(inipath)
     self.modules = defaultdict(dict)
     self.l10nbase = mozpath.abspath(l10nbase)
     self.filters = []
     self.addFilters(*self.config.getFilters())