Beispiel #1
0
 def __run__(self):
     try:
         me.logger.debug("Reparsing internal.")
         res = parser.lex_ledger_file_contents(me.get_unitext())
         me.internal_parsing_cache = res
     finally:
         me.internal_parsing_cache_lock.release()
def main(argv):
    p = get_argparser()
    args = p.parse_args(argv[1:])
    assert not args.assume_yes
    ledgerfile = ledgerhelpers.find_ledger_file_for_gui()
    try:
        leftcontents = codecs.open(ledgerfile, "rb", "utf-8").read()
        items = parser.lex_ledger_file_contents(leftcontents, debug=args.debug)
        rightcontents = u"".join(i.contents for i in sort_transactions(items))
        try:
            diffing.three_way_diff(ledgerfile, leftcontents, rightcontents)
        except subprocess.CalledProcessError, e:
            if args.debug:
                raise
            ledgerhelpers.FatalError("Meld failed",
                       "Meld process failed with return code %s" % e.returncode,
                       outside_mainloop=True)
            return e.returncode
    except Exception, e:
        if args.debug:
            raise
        ledgerhelpers.FatalError("Transaction sort failed",
                   "An unexpected error took place:\n%s" % e,
                   outside_mainloop=True)
        return 9
def main(argv):
    p = get_argparser()
    args = p.parse_args(argv[1:])
    assert not args.assume_yes
    ledgerfile = gui.find_ledger_file_for_gui()
    try:
        leftcontents = codecs.open(ledgerfile, "rb", "utf-8").read()
        items = parser.lex_ledger_file_contents(leftcontents, debug=args.debug)
        rightcontents = u"".join(i.contents for i in sort_transactions(items))
        try:
            diffing.three_way_diff(ledgerfile, leftcontents, rightcontents)
        except subprocess.CalledProcessError, e:
            if args.debug:
                raise
            gui.FatalError("Meld failed",
                           "Meld process failed with return code %s" %
                           e.returncode,
                           outside_mainloop=True)
            return e.returncode
    except Exception, e:
        if args.debug:
            raise
        gui.FatalError("Transaction sort failed",
                       "An unexpected error took place:\n%s" % e,
                       outside_mainloop=True)
        return 9
Beispiel #4
0
    def reread_files(self):
        try:
            files = []
            if self.price_path:
                files.append(self.price_path)
            if self.path:
                files.append(self.path)
            text = "\n".join(file(x).read() for x in files)

            if self.path:
                unitext = "\n".join(
                    codecs.open(x, "rb", "utf-8").read()
                    for x in [self.path]
                )
            else:
                unitext = u""

            session = ledger.Session()
            journal = session.read_journal_from_string(text)
            from ledgerhelpers import parser
            internal_parsing = parser.lex_ledger_file_contents(unitext)

            self.session = session
            self.journal = journal
            self.internal_parsing = internal_parsing
            GObject.idle_add(lambda: self.emit("loaded"))
        except Exception as e:
            GObject.idle_add(lambda: self.emit("load-failed", e))
            raise
Beispiel #5
0
 def __run__(self):
     try:
         me.logger.debug("Reparsing internal.")
         res = parser.lex_ledger_file_contents(me.get_unitext())
         me.internal_parsing_cache = res
     finally:
         me.internal_parsing_cache_lock.release()
Beispiel #6
0
 def test_simple_transaction(self):
     c = base.data("simple_transaction.dat")
     items = parser.lex_ledger_file_contents(c)
     self.assertEqual(len(items), 3)
     for n, tclass in enumerate([
         parser.TokenWhitespace,
         parser.TokenTransaction,
         parser.TokenWhitespace,
     ]):
         self.assertIsInstance(items[n], tclass)
     transaction = items[1]
     self.assertEqual(transaction.date, datetime.date(2015, 3, 12))
     self.assertEqual(transaction.clearing_date, datetime.date(2015, 3, 15))
     self.assertEqual(transaction.payee, "beer")
     for n, (ac, am) in enumerate([
         ("Accounts:Cash", "-6.00 CHF"),
         ("Expenses:Drinking", "6.00 CHF"),
     ]):
         self.assertEqual(transaction.postings[n].account, ac)
         self.assertEqual(transaction.postings[n].amount, am)
Beispiel #7
0
 def test_no_end_value(self):
     c = base.data("no_end_value.dat")
     items = parser.lex_ledger_file_contents(c)
     self.assertEqual(len(items), 5)
     for n, tclass in enumerate([
         parser.TokenWhitespace,
         parser.TokenTransaction,
         parser.TokenWhitespace,
         parser.TokenTransaction,
         parser.TokenWhitespace,
     ]):
         self.assertIsInstance(items[n], tclass)
     for transaction in (items[1], items[3]):
         self.assertEqual(transaction.payee, "beer")
         for n, (ac, am) in enumerate([
             ("Accounts:Cash", "-6.00 CHF"),
             ("Expenses:Drinking", ""),
         ]):
             self.assertEqual(transaction.postings[n].account, ac)
             self.assertEqual(transaction.postings[n].amount, am)
Beispiel #8
0
 def test_with_comments(self):
     c = base.data("with_comments.dat")
     items = parser.lex_ledger_file_contents(c)
     self.assertEqual(len(items), 3)
     for n, tclass in enumerate([
         parser.TokenWhitespace,
         parser.TokenTransaction,
         parser.TokenWhitespace,
     ]):
         self.assertIsInstance(items[n], tclass)
     transaction = items[1]
     self.assertEqual(transaction.date, datetime.date(2011, 12, 25))
     self.assertEqual(transaction.clearing_date, datetime.date(2011, 12, 25))
     self.assertEqual(transaction.payee, "a gift!")
     self.assertEqual(transaction.state, parser.STATE_CLEARED)
     for n, (ac, am) in enumerate([
         ("Assets:Metals", "1 \"silver coin\"    @ $55"),
         ("Income:Gifts", "$        -55"),
     ]):
         self.assertEqual(transaction.postings[n].account, ac)
         self.assertEqual(transaction.postings[n].amount, am)
Beispiel #9
0
 def test_my_data_file(self):
     try:
         c = base.data("/home/user/.ledger")
     except IOError:
         return
     items = parser.lex_ledger_file_contents(c)