Пример #1
0
def load_journal_and_settings_for_gui(price_file_mandatory=False,
                                      ledger_file=None,
                                      price_file=None):
    try:
        ledger_file = ledgerhelpers.find_ledger_file(ledger_file)
    except Exception as e:
        cannot_start_dialog(str(e))
        sys.exit(4)
    try:
        price_file = ledgerhelpers.find_ledger_price_file(price_file)
    except ledgerhelpers.LedgerConfigurationError as e:
        if price_file_mandatory:
            cannot_start_dialog(str(e))
            sys.exit(4)
        else:
            price_file = None
    except Exception as e:
        cannot_start_dialog(str(e))
        sys.exit(4)
    try:
        from ledgerhelpers.journal import Journal
        journal = Journal.from_file(ledger_file, price_file)
    except Exception as e:
        cannot_start_dialog("Cannot open ledger file: %s" % e)
        sys.exit(5)
    s = ledgerhelpers.Settings.load_or_defaults(
        os.path.expanduser("~/.ledgerhelpers.ini"))
    return journal, s
Пример #2
0
def find_ledger_file_for_gui():
    try:
        ledger_file = ledgerhelpers.find_ledger_file()
        return ledger_file
    except Exception, e:
        cannot_start_dialog(str(e))
        sys.exit(4)
Пример #3
0
def find_ledger_file_for_gui():
    try:
        ledger_file = ledgerhelpers.find_ledger_file()
        return ledger_file
    except Exception, e:
        cannot_start_dialog(str(e))
        sys.exit(4)
Пример #4
0
def load_journal_and_settings_for_gui(price_file_mandatory=False,
                                      ledger_file=None,
                                      price_file=None):
    try:
        ledger_file = ledgerhelpers.find_ledger_file(ledger_file)
    except Exception, e:
        cannot_start_dialog(str(e))
        sys.exit(4)
Пример #5
0
def main():
    s = common.Settings.load_or_defaults(os.path.expanduser("~/.ledgerhelpers.ini"))
    journal = common.Journal.from_file(common.find_ledger_file(), None)
    accts, commodities = journal.accounts_and_last_commodities()


    when = common.prompt_for_date(
        sys.stdin, sys.stdout,
        "When?",
        s.get("last_date", datetime.date.today())
    )
    if when == datetime.date.today():
        del s["last_date"]
    else:
        s["last_date"] = when

    asset1 = common.prompt_for_account(
        sys.stdin, sys.stdout,
        accts, "From where?",
        s.get("last_withdrawal_account", None)
    )
    assert asset1, "Not an account: %s" % asset1
    s["last_withdrawal_account"] = asset1
    asset1_currency = commodities.get(asset1, ledger.Amount("$ 1"))

    asset2 = common.prompt_for_account(
        sys.stdin, sys.stdout,
        accts, "To where?",
        s.get("last_deposit_account", None)
    )
    assert asset2, "Not an account: %s" % asset2
    s["last_deposit_account"] = asset2
    asset2_currency = commodities.get(asset2, ledger.Amount("$ 1"))

    amount1 = common.prompt_for_amount(
        sys.stdin, sys.stdout,
        "How much?", asset1_currency
    )

    amount2 = common.prompt_for_amount(
        sys.stdin, sys.stdout,
        "What was deposited?", asset2_currency
    )

    lines = journal.generate_record("Withdrawal", when, None, [
        (asset1, [-1 * amount1]),
        (asset2, [amount2]),
    ])
    print "========== Record =========="
    print "\n".join(lines)
    save = common.yesno(
        sys.stdin, sys.stderr,
        "Hit ENTER or y to save it to the file, BACKSPACE or n to skip saving: "
    )
    if save:
        journal.add_lines_to_file(lines)
Пример #6
0
def main():
    s = common.Settings.load_or_defaults(
        os.path.expanduser("~/.ledgerhelpers.ini"))
    j = journal.Journal.from_file(common.find_ledger_file(), None)
    accts, commodities = j.accounts_and_last_commodity_for_account()

    when = common.prompt_for_date(sys.stdin, sys.stdout, "When?",
                                  s.get("last_date", datetime.date.today()))
    if when == datetime.date.today():
        del s["last_date"]
    else:
        s["last_date"] = when

    asset1 = common.prompt_for_account(sys.stdin, sys.stdout, accts,
                                       "From where?",
                                       s.get("last_withdrawal_account", None))
    assert asset1, "Not an account: %s" % asset1
    s["last_withdrawal_account"] = asset1
    asset1_currency = commodities.get(asset1, ledger.Amount("$ 1"))

    asset2 = common.prompt_for_account(sys.stdin, sys.stdout, accts,
                                       "To where?",
                                       s.get("last_deposit_account", None))
    assert asset2, "Not an account: %s" % asset2
    s["last_deposit_account"] = asset2
    asset2_currency = commodities.get(asset2, ledger.Amount("$ 1"))

    amount1 = common.prompt_for_amount(sys.stdin, sys.stdout, "How much?",
                                       asset1_currency)

    amount2 = common.prompt_for_amount(sys.stdin, sys.stdout,
                                       "What was deposited?", asset2_currency)

    lines = j.generate_record("Withdrawal", when, None, "", [
        (asset1, -1 * amount1),
        (asset2, amount2),
    ])
    print "========== Record =========="
    print "\n".join(lines)
    save = common.yesno(
        sys.stdin, sys.stderr,
        "Hit ENTER or y to save it to the file, BACKSPACE or n to skip saving: "
    )
    if save:
        j.add_text_to_file(lines)
Пример #7
0
def load_journal_and_settings_for_gui(price_file_mandatory=False):
    try:
        ledger_file = ledgerhelpers.find_ledger_file()
    except Exception, e:
        cannot_start_dialog(str(e))
        sys.exit(4)