--- a/compare_locales/commands.py
+++ b/compare_locales/commands.py
@@ -8,21 +8,23 @@ import logging
from argparse import ArgumentParser
import os
from compare_locales import version
from compare_locales.paths import EnumerateApp, TOMLParser, ConfigNotFound
from compare_locales.compare import compareProjects, Observer
-class BaseCommand(object):
- """Base class for compare-locales commands.
- This handles command line parsing, and general sugar for setuptools
- entry_points.
- """
+class CompareLocales(object):
+ """Check the localization status of gecko applications.
+The first arguments are paths to the l10n.ini or toml files for the
+applications, followed by the base directory of the localization repositories.
+Then you pass in the list of locale codes you want to compare. If there are
+not locales given, the list of locales will be taken from the l10n.toml file
+or the all-locales file referenced by the application\'s l10n.ini."""
def __init__(self):
self.parser = None
def get_parser(self):
"""Get an ArgumentParser, with class docstring as description.
"""
parser = ArgumentParser(description=self.__doc__)
@@ -30,27 +32,46 @@ class BaseCommand(object):
version='%(prog)s ' + version)
parser.add_argument('-v', '--verbose', action='count', dest='v',
default=0, help='Make more noise')
parser.add_argument('-q', '--quiet', action='count', dest='q',
default=0, help='Make less noise')
parser.add_argument('-m', '--merge',
help='''Use this directory to stage merged files,
use {ab_CD} to specify a different directory for each locale''')
- return parser
-
- def add_data_argument(self, parser):
+ parser.add_argument('config', metavar='l10n.toml', nargs='+',
+ help='TOML or INI file for the project')
+ parser.add_argument('l10n_base_dir', metavar='l10n-base-dir',
+ help='Parent directory of localizations')
+ parser.add_argument('locales', nargs='*', metavar='locale-code',
+ help='Locale code and top-level directory of '
+ 'each localization')
+ parser.add_argument('-D', action='append', metavar='var=value',
+ default=[],
+ help='Overwrite variables in TOML files')
+ parser.add_argument('--unified', action="store_true",
+ help="Show output for all projects unified")
+ parser.add_argument('--full', action="store_true",
+ help="Compare projects that are disabled")
+ parser.add_argument('--clobber-merge', action="store_true",
+ default=False, dest='clobber',
+ help="""WARNING: DATALOSS.
+Use this option with care. If specified, the merge directory will
+be clobbered for each module. That means, the subdirectory will
+be completely removed, any files that were there are lost.
+Be careful to specify the right merge directory when using this option.""")
parser.add_argument('--data', choices=['text', 'exhibit', 'json'],
default='text',
help='''Choose data and format (one of text,
exhibit, json); text: (default) Show which files miss which strings, together
with warnings and errors. Also prints a summary; json: Serialize the internal
tree, useful for tools. Also always succeeds; exhibit: Serialize the summary
data in a json useful for Exhibit
''')
+ return parser
@classmethod
def call(cls):
"""Entry_point for setuptools.
The actual command handling is done in the handle() method of the
subclasses.
"""
cmd = cls()
@@ -76,57 +97,16 @@ data in a json useful for Exhibit
if summary.get('errors', 0) > 0:
rv = 1
# no need to check further summaries, but
# continue to run through observers
break
return rv
def handle(self, args):
- """Subclasses need to implement this method for the actual
- command handling.
- """
- raise NotImplementedError
-
-
-class CompareLocales(BaseCommand):
- """Check the localization status of gecko applications.
-The first arguments are paths to the l10n.ini or toml files for the
-applications, followed by the base directory of the localization repositories.
-Then you pass in the list of locale codes you want to compare. If there are
-not locales given, the list of locales will be taken from the l10n.toml file
-or the all-locales file referenced by the application\'s l10n.ini."""
-
- def get_parser(self):
- parser = super(CompareLocales, self).get_parser()
- parser.add_argument('config', metavar='l10n.toml', nargs='+',
- help='TOML or INI file for the project')
- parser.add_argument('l10n_base_dir', metavar='l10n-base-dir',
- help='Parent directory of localizations')
- parser.add_argument('locales', nargs='*', metavar='locale-code',
- help='Locale code and top-level directory of '
- 'each localization')
- parser.add_argument('-D', action='append', metavar='var=value',
- default=[],
- help='Overwrite variables in TOML files')
- parser.add_argument('--unified', action="store_true",
- help="Show output for all projects unified")
- parser.add_argument('--full', action="store_true",
- help="Compare projects that are disabled")
- parser.add_argument('--clobber-merge', action="store_true",
- default=False, dest='clobber',
- help="""WARNING: DATALOSS.
-Use this option with care. If specified, the merge directory will
-be clobbered for each module. That means, the subdirectory will
-be completely removed, any files that were there are lost.
-Be careful to specify the right merge directory when using this option.""")
- self.add_data_argument(parser)
- return parser
-
- def handle(self, args):
# 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 = args.config + [args.l10n_base_dir] + args.locales
del args.config[:]
del args.locales[:]
while all_args and not os.path.isdir(all_args[0]):