Beispiel #1
0
    def test_references_wildcard(self, is_dir, glob_mock):
        parser = TOMLParser()

        def mock_load(ctx):
            ctx.data = {
                "locales": [],
                "paths": [
                    {
                        "reference": "some/**/file.ftl",
                        "l10n": "**/{android_locale}/file.ftl",
                    },
                ],
            }

        parser.load = mock.MagicMock(side_effect=mock_load)
        pc = parser.parse("a/basedir/l10n.toml")
        is_dir.side_effect = lambda p: not p.endswith("fixed/file.ftl")
        glob_mock.return_value = [
            pc.root + f for f in [
                "/some/other/content",
                "/some/other/file.ftl",
                "/some/second/deep/file.ftl",
            ]
        ]
        self.assertListEqual(
            process.references(pc, "a/basedir"),
            ["l10n.toml", "some/other/file.ftl", "some/second/deep/file.ftl"])
Beispiel #2
0
    def test_references_file(self, is_dir, glob_mock):
        parser = TOMLParser()

        def mock_load(ctx):
            ctx.data = {
                "locales": [],
                "paths": [
                    {
                        "reference": "some/fixed/file.ftl",
                        "l10n": "{android_locale}/file.ftl",
                    },
                ],
            }

        parser.load = mock.MagicMock(side_effect=mock_load)
        pc = parser.parse("a/basedir/l10n.toml")
        is_dir.side_effect = lambda p: not p.endswith("fixed/file.ftl")
        glob_mock.side_effect = Exception("not called")
        self.assertListEqual(process.references(pc, "a/basedir"),
                             ["l10n.toml", "some/fixed/file.ftl"])
Beispiel #3
0
    def handle(self,
               config_paths,
               l10n_base_dir,
               locales,
               merge=None,
               defines=None,
               unified=False,
               full=False,
               quiet=0,
               validate=False,
               clobber=False,
               data='text'):
        # 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 = []
        locales = []
        if defines is None:
            defines = []
        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 = all_args.pop(0)
        if validate:
            # signal validation mode by setting locale list to [None]
            locales = [None]
        else:
            locales.extend(all_args)
        # when we compare disabled projects, we set our locales
        # on all subconfigs, so deep is True.
        locales_deep = full
        configs = []
        config_env = {}
        for define in defines:
            var, _, value = define.partition('=')
            config_env[var] = value
        for config_path in config_paths:
            if config_path.endswith('.toml'):
                try:
                    config = TOMLParser.parse(config_path, env=config_env)
                except ConfigNotFound as e:
                    self.parser.exit('config file %s not found' % e.filename)
                config.add_global_environment(l10n_base=l10n_base_dir)
                if locales:
                    config.set_locales(locales, deep=locales_deep)
                configs.append(config)
            else:
                app = EnumerateApp(config_path, l10n_base_dir, locales)
                configs.append(app.asConfig())
        try:
            unified_observer = None
            if unified:
                unified_observer = Observer(quiet=quiet)
            observers = compareProjects(configs,
                                        quiet=quiet,
                                        stat_observer=unified_observer,
                                        merge_stage=merge,
                                        clobber_merge=clobber)
        except (OSError, IOError) as exc:
            print("FAIL: " + str(exc))
            self.parser.exit(2)
        if unified:
            observers = [unified_observer]

        rv = 0
        for observer in observers:
            print(observer.serialize(type=data))
            # summary is a dict of lang-summary dicts
            # find out if any of our results has errors, return 1 if so
            if rv > 0:
                continue  # we already have errors
            for loc, summary in observer.summary.items():
                if summary.get('errors', 0) > 0:
                    rv = 1
                    # no need to check further summaries, but
                    # continue to run through observers
                    break
        return rv
 def read_configs(self):
     parser = TOMLParser()
     self.src_config = parser.parse(self.src_toml)
     self.dest_config = parser.parse(self.dest_toml)
Beispiel #5
0
 def handle(self,
            config_paths,
            l10n_base_dir,
            locales,
            merge=None,
            defines=None,
            unified=False,
            full=False,
            quiet=0,
            clobber=False,
            data='text'):
     # 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 = []
     locales = []
     if defines is None:
         defines = []
     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 = all_args.pop(0)
     locales.extend(all_args)
     # when we compare disabled projects, we set our locales
     # on all subconfigs, so deep is True.
     locales_deep = full
     configs = []
     config_env = {}
     for define in defines:
         var, _, value = define.partition('=')
         config_env[var] = value
     for config_path in config_paths:
         if config_path.endswith('.toml'):
             try:
                 config = TOMLParser.parse(config_path, env=config_env)
             except ConfigNotFound as e:
                 self.parser.exit('config file %s not found' % e.filename)
             config.add_global_environment(l10n_base=l10n_base_dir)
             if locales:
                 config.set_locales(locales, deep=locales_deep)
             configs.append(config)
         else:
             app = EnumerateApp(config_path, l10n_base_dir, locales)
             configs.append(app.asConfig())
     try:
         unified_observer = None
         if unified:
             unified_observer = Observer(quiet=quiet)
         observers = compareProjects(configs,
                                     quiet=quiet,
                                     stat_observer=unified_observer,
                                     merge_stage=merge,
                                     clobber_merge=clobber)
     except (OSError, IOError), exc:
         print "FAIL: " + str(exc)
         self.parser.exit(2)