def __init__(self, flask, config_file='NumberToStringAPI.config'): """ __init__ - NumberToStringAPI constructor 1. Save flask context - self.flask 2. load config file - config values saved to self.config dictionary 3. Set up logging - self.LOGGER 4. load NumberToString module - self.machine """ # 1. Save flask context self.flask = flask # 2. Load Config conf_parser = ConfigParser.SafeConfigParser() conf_parser.read(config_file) self.config = dict(conf_parser.items('NumberToString')) # 3. Set up logger logging.basicConfig(stream=sys.stderr, format='%(levelname) -10s %(asctime)s %(name) -30s %(funcName) -35s %(lineno) -5d: %(message)s') logging.getLogger("NumberToStringAPI").setLevel(logging.INFO) self.LOGGER = logging.getLogger("NumberToStringAPI") try: self.LOGGER.info("START NumberToStringAPI") except Exception as e: sys.stderr.write("Fatal Error: Could not instantiate LOGGER\n") raise # 4. Load a machine for each available locale self.config['locales'] = list_installed_locales() self.machines = {} for locale in self.config['locales']: self.machines[locale] = NumberToString.NumberToStringMachine(locale=locale)
import argparse from NumberToString.tests.NumberToStringTests import NumberToStringTestCase, main, list_installed_locales, locale # Allow user to pass in locale argument parser = argparse.ArgumentParser() parser.add_argument('--locale') parser.add_argument('-v', '--verbosity', action="store_true") args = parser.parse_args() if (args.locale and args.locale != 'all' ): locales = [args.locale] else: locales = list_installed_locales() for l in locales: locale = l main()