Exemplo n.º 1
0
 def test_update_config(self):
     dest = os.path.join(tempfile.mkdtemp(), os.path.basename(CONFIG_FILE))
     shutil.copy2(CONFIG_FILE, dest)
     # Replace 'Sully' match tag from 'Bars' to 'Drink'
     tags.edit('Bars', 'Sully', 'Drink', 'Sully', {'config': dest})
     tags.load(dest)
     self.assertEqual(tags.find_tag_for('Sully')[0], 'Drink')
Exemplo n.º 2
0
def write_config(accounts, cfg_path, dry_run):
    """Update configuration file with extracted accounts names."""
    json_accs = {}
    for account in accounts:
        json_accs[account] = []
    json_accs.update(tags.load(cfg_path))
    if dry_run:
        print((tags.prettify(json_accs)))
    else:
        tags.save(cfg_path, json_accs)
    return json_accs
Exemplo n.º 3
0
def main(argv=None):
    """Main function: Parse, process, print"""
    if argv is None:
        argv = sys.argv
    args = parse_args(argv)
    if not args:
        exit(1)
    original_tags = copy.deepcopy(tags.load(args['config']))
    with io.open(args['src'], 'r', encoding='utf-8', errors='ignore') as fin:
        lines = fin.readlines()
        transacs_orig = parse_file(lines, options=args)
    try:
        transacs = process_file(transacs_orig, options=args)
    except EOFError:  # exit on Ctrl + D: restore original tags
        tags.save(args['config'], original_tags)
        return 1
    res = dump_to_buffer(transacs + transacs_orig[len(transacs):])
    if not args.get('dry-run', False):
        with io.open(args['dest'], 'w', encoding='utf-8') as f:
            f.write(res)
    print(res)
    return 0 if len(transacs) == len(transacs_orig) else 1
Exemplo n.º 4
0
def main(argv=None):
    """Main function: Parse, process, print"""
    if argv is None:
        argv = sys.argv
    args = parse_args(argv)
    if not args:
        exit(1)
    original_tags = copy.deepcopy(tags.load(args['config']))
    with io.open(args['src'], 'r', encoding='utf-8', errors='ignore') as fin:
        lines = fin.readlines()
        transacs_orig = parse_file(lines, options=args)
    try:
        transacs = process_file(transacs_orig, options=args)
    except EOFError:  # exit on Ctrl + D: restore original tags
        tags.save(args['config'], original_tags)
        return 1
    res = dump_to_buffer(transacs + transacs_orig[len(transacs):])
    if not args.get('dry-run', False):
        with io.open(args['dest'], 'w', encoding='utf-8') as f:
            f.write(res)
    print(res)
    return 0 if len(transacs) == len(transacs_orig) else 1
Exemplo n.º 5
0
def main(argv=None):
    """Main function: Parse, process, print"""
    if argv is None:
        argv = sys.argv
    args = parse_args(argv)
    if not args:
        exit(1)
    original_tags = copy.deepcopy(tags.load(args["config"]))
    with io.open(args["src"], "r", encoding="utf-8", errors="ignore") as fin:
        lines = fin.readlines()
        transacs_orig = qifile.parse_lines(lines, options=args)
    try:
        transacs = process_transactions(transacs_orig, options=args)
    except EOFError:  # exit on Ctrl + D: restore original tags
        tags.save(args["config"], original_tags)
        return 1
    res = qifile.dump_to_buffer(transacs + transacs_orig[len(transacs) :])
    if not args.get("dry-run"):
        with io.open(args["dest"], "w", encoding="utf-8") as dest:
            dest.write(res)
    if args["batch"] or args["dry-run"]:
        print("\n" + res)
    return 0 if len(transacs) == len(transacs_orig) else 1
Exemplo n.º 6
0
 def setUp(self):
     tags.load(CONFIG_FILE)
     self.transactions = qifqif.parse_file(TEST_DATA['t02']['raw'],
                                           {'batch': True})
     shutil.copyfile(CONFIG_FILE, CONFIG_TEST_FILE)
     shutil.copyfile(QIF_FILE, QIF_TEST_FILE)
Exemplo n.º 7
0
 def setUp(self):
     tags.load(CONFIG_FILE)
     self.transaction = qifqif.parse_file(TEST_DATA['t01_notag']['raw'])