def test_parse_arguments__invalid(self): parser = scripts_utils.create_arguments_parser("Test script") with test_utils.capture('stdout', 'stderr') as (stdout, stderr): with self.assertRaises(SystemExit): scripts_utils.parse_arguments(parser, [ path.join(self.tempdir, 'test.import'), path.join(self.tempdir, 'Non-existent'), ])
def test_parse_arguments__insufficient(self): # Test with insufficient arguments. parser = scripts_utils.create_arguments_parser("Test script") with test_utils.capture('stdout', 'stderr') as (stdout, stderr): with self.assertRaises(SystemExit): scripts_utils.parse_arguments(parser, argv=[]) with test_utils.capture('stdout', 'stderr') as (stdout, stderr): with self.assertRaises(SystemExit): scripts_utils.parse_arguments( parser, argv=[path.join(self.tempdir, 'test.import')])
def main(): parser = scripts_utils.create_arguments_parser("Extract transactions from downloads") parser.add_argument('-e', '-f', '--existing', '--previous', metavar='BEANCOUNT_FILE', default=None, help=('Beancount file or existing entries for de-duplication ' '(optional)')) parser.add_argument('-r', '--reverse', '--descending', action='store_const', dest='ascending', default=True, const=False, help='Write out the entries in descending order') args, config, downloads_directories = scripts_utils.parse_arguments(parser) # Load the ledger, if one is specified. if args.existing: entries, _, options_map = loader.load_file(args.existing) else: entries = None options_map = None extract(config, downloads_directories, sys.stdout, entries=entries, options_map=options_map, mindate=None, ascending=args.ascending) return 0
def test_parse_arguments__sufficient(self): parser = scripts_utils.create_arguments_parser("Test script") with test_utils.capture('stdout', 'stderr') as (stdout, stderr): args, config, dirs = scripts_utils.parse_arguments(parser, [ path.join(self.tempdir, 'test.import'), path.join(self.tempdir, 'Downloads'), ]) self.assertIsInstance(args, argparse.Namespace) self.assertEqual(2, len(config)) self.assertEqual([path.join(self.tempdir, 'Downloads')], dirs)
def test_parse_arguments__multiple(self): parser = scripts_utils.create_arguments_parser("Test script") with test_utils.capture('stdout', 'stderr') as (stdout, stderr): args, config, dirs = scripts_utils.parse_arguments(parser, [ path.join(self.tempdir, 'test.import'), path.join(self.tempdir, 'Downloads/ofxdownload.ofx'), # File path.join(self.tempdir, 'Downloads/Subdir'), # Directory ]) self.assertIsInstance(args, argparse.Namespace) self.assertEqual(2, len(config)) self.assertEqual(2, len(dirs))
def main(): parser = scripts_utils.create_arguments_parser( "Move and rename downloaded files to a documents tree " "mirrorring the chart of accounts") parser.add_argument( '-o', '--output', '--output-dir', '--destination', dest='output_dir', action='store', help="The root of the documents tree to move the files to.") parser.add_argument('-n', '--dry-run', action='store_true', help=("Just print where the files would be moved; " "don't actually move them.")) parser.add_argument( '--no-overwrite', dest='overwrite', action='store_false', default=True, help="Don't overwrite destination files with the same name.") args, config, downloads_directories = scripts_utils.parse_arguments(parser) # If the output directory is not specified, move the files at the root of # the configuration file. (Providing this default seems better than using a # required option.) if args.output_dir is None: args.output_dir = path.dirname(path.abspath(args.config)) # Make sure the output directory exists. if not path.exists(args.output_dir): parser.error('Output directory "{}" does not exist.'.format( args.output_dir)) file(config, downloads_directories, args.output_dir, dry_run=args.dry_run, mkdirs=True, overwrite=args.overwrite, idify=True, logfile=sys.stdout) return 0
def main(): parser = scripts_utils.create_arguments_parser("Identify files for import") _, config, downloads_directories = scripts_utils.parse_arguments(parser) identify(config, downloads_directories) return 0