def process(args, ui): # read configuration config = configuration.read(ui) if args.type not in config: raise Abort("No section named %s in config file" % args.type) settings = config[args.type] pname = settings.get('plugin', None) if not pname: raise Abort("Specify 'plugin' setting for section %s" % args.type) # pick and configure plugin try: p = plugin.get_plugin(pname, ui, settings) except plugin.PluginNotRegistered as e: raise Abort("No plugin named '%s' is found" % e) from e # process the input and produce output parser = p.get_parser(args.input) statement = parser.parse() with open(args.output, "w") as out: writer = OfxWriter(statement) out.write(writer.toxml()) ui.status("Conversion completed: %s" % args.input)
def convert(args: argparse.Namespace) -> int: appui = ui.UI() config = configuration.read() if config is None: # No configuration mode settings = {} pname = args.type else: # Configuration is loaded if args.type not in config: log.error("No section '%s' in config file." % args.type) log.error( "Edit configuration using ofxstatement edit-config and " "add section [%s]." % args.type ) return 1 # error settings = dict(config[args.type]) pname = settings.get("plugin", None) if not pname: log.error("Specify 'plugin' setting for section [%s]" % args.type) return 1 # error # pick and configure plugin try: p = plugin.get_plugin(pname, appui, settings) except plugin.PluginNotRegistered: log.error("No plugin named '%s' is found" % pname) return 1 # error # process the input and produce output parser = p.get_parser(args.input) try: statement = parser.parse() except exceptions.ParseError as e: log.error("Parse error on line %s: %s" % (e.lineno, e.message)) return 2 # parse error # Validate the statement try: statement.assert_valid() except exceptions.ValidationError as e: log.error("Statement validation error: %s" % (e.message)) return 2 # Validation error with smart_open(args.output, settings.get("encoding", None)) as out: writer = ofx.OfxWriter(statement) out.write(writer.toxml()) log.info("Conversion completed: %s" % args.input) return 0 # success
def convert(args): appui = ui.UI() config = configuration.read() if config is None: # No configuration mode settings = {} pname = args.type else: # Configuration is loaded if args.type not in config: log.error("No section '%s' in config file." % args.type) log.error("Edit configuration using ofxstatement edit-config and " "add section [%s]." % args.type) return 1 # error settings = dict(config[args.type]) pname = settings.get('plugin', None) if not pname: log.error("Specify 'plugin' setting for section [%s]" % args.type) return 1 # error # pick and configure plugin try: p = plugin.get_plugin(pname, appui, settings) except plugin.PluginNotRegistered: log.error("No plugin named '%s' is found" % pname) return 1 # error # process the input and produce output parser = p.get_parser(args.input) try: statement = parser.parse() statement.assert_valid() except exceptions.ParseError as e: log.error("Parse error on line %s: %s" % (e.lineno, e.message)) return 2 # error with open(args.output, "w") as out: writer = ofx.OfxWriter(statement) out.write(writer.toxml()) log.info("Conversion completed: %s" % args.input) return 0 # success
def load_configuration(self): here = os.path.dirname(__file__) cfname = os.path.join(here, 'samples', 'config.ini') return configuration.read(cfname)
def test_configuration(self) -> None: here = os.path.dirname(__file__) cfname = os.path.join(here, "samples", "config.ini") config = configuration.read(cfname) assert config is not None self.assertEqual(config["swedbank"]["plugin"], "swedbank")
def test_missing_section(self) -> None: here = os.path.dirname(__file__) cfname = os.path.join(here, "samples", "config.ini") config = configuration.read(cfname) with self.assertRaises(Abort): configuration.get_settings(config, "kawabanga")
def test_missing_configuration(self) -> None: config = configuration.read("missing.ini") self.assertIsNone(config)
def test_default_configuration(self) -> None: default_config = configuration.read( configuration.get_default_location()) config = configuration.read() self.assertEqual(config, default_config)
def test_configuration(self): here = os.path.dirname(__file__) cfname = os.path.join(here, 'samples', 'config.ini') config = configuration.read(cfname) self.assertEqual(config['swedbank']['plugin'], 'swedbank')
def test_missing_configuration(self): config = configuration.read("missing.ini") self.assertIsNone(config)
def test_missing_section(self): here = os.path.dirname(__file__) cfname = os.path.join(here, 'samples', 'config.ini') config = configuration.read(cfname) with self.assertRaises(Abort): configuration.get_settings(config, 'kawabanga')
def test_default_configuration(self): default_config = configuration.read(configuration.get_default_location()) config = configuration.read() self.assertEqual(config, default_config)