Exemplo n.º 1
0
def load_ledger(parser, filenames, opts):
    # logging.info("Parsing Ledger source file: %s" % fn)
    ledger = Ledger()
    for fn in filenames:
        if fn == '-':
            f = sys.stdin
        else:
            f = open(fn)
        if opts.encoding:
            Reader = codecs.getreader(opts.encoding)
            f = Reader(f)
        ledger.parse_file(f, fn, opts.encoding)

    run_postprocesses(ledger, opts)

    return ledger
Exemplo n.º 2
0
def reload(ledger, opts):
    """
    Parse the files again and create a new Ledger from them.
    """
    # Note: we ignore the pickling for reload.
    ledger2 = Ledger()

    for fn, encoding in ledger.parsed_files:
        f = open(fn)
        if encoding:
            Reader = codecs.getreader(encoding)
            f = Reader(f)
        ledger2.parse_file(f, fn, encoding)

    run_postprocesses(ledger2, opts)

    return ledger2
Exemplo n.º 3
0
def ledger_str(s, name):
    l = Ledger()
    l.parse_string(s, name=name)
    l.run_directives()
    return l