예제 #1
0
def config_setup_flow(config_dict):
    """ Interactive setup for changing key-value pairs in config_dict

    :param config_dict: the config dictionary
    :type config_dict: dict
    """
    mod_folder_bool = False
    if "__default_folder_name" in config_dict:
        print("Modify default folder name? (y/N)")
        mod_folder_bool = input.yes_no_input()
    else:
        print("No default folder name found.")
        mod_folder_bool = True
    if mod_folder_bool:
        print("Please type the new default folder name...")
        config_dict["__default_folder_name"] = input.text_input()
    print("Add/modify default payment account? (y/N)")
    if input.yes_no_input():
        print("Please type the new default payment account...")
        config_dict["__default_payment"] = input.text_input().lower()
    print("Add/modify default transfer sending account? (y/N)")
    if input.yes_no_input():
        print("Please type the new default transfer sending account...")
        config_dict["__default_from_account"] = input.text_input().lower()
    print("Add/modify default transfer receiving account? (y/N)")
    if input.yes_no_input():
        print("Please type the new default transfer receiving account...")
        config_dict["__default_to_account"] = input.text_input().lower()
    print("Saving updated config...")
    outstr = ""
    for key in config_dict:
        outstr += key + ":" + config_dict[key] + "\n"
    with open("config.ini","w") as configfile:
        configfile.write(outstr)
예제 #2
0
def modify_section_flow(section):
    print("This section calls the function {}".format(section[0]) +
          "\nWould you like to change that? (y/N)")
    if input.yes_no_input():
        return create_section_flow()
    else:
        while True:
            print("Current arguments:")
            for i, item in enumerate(section[1:]):
                if isinstance(item, list):
                    print("{}: report function '{}'".format(i, item[0]))
                else:
                    print("{}: value '{}'".format(i, item))
            print("Do you wish to modify an argument (y)" +
                  " or stop modifying this section (N)?")
            if input.yes_no_input():
                print("Which index argument do you wish to modify?")
                modify_index = input.int_input()
                while True:
                    try:
                        val_to_change = section[modify_index + 1]
                        break
                    except:
                        print("The index you gave ({})".format(modify_index) +
                              " is not a valid index.")
                        modify_index = input.int_input()
                replace = True
                if isinstance(val_to_change, list):
                    print("This argument is the" +
                          " report function {}".format(val_to_change[0]) +
                          "\nDo you wish to modify this report function (y)" +
                          " or replace it with something else (N)?")
                    if input.yes_no_input():
                        replace = False
                if replace:
                    print("Is argument {} a value (y),".format(modify_index) +
                          "or is it a report function (N)?")
                    if input.yes_no_input():
                        print("What is the value of" +
                              " argument {}?".format(modify_index))
                        section[modify_index + 1] = input.text_input()
                    else:
                        section[modify_index +
                                1] = create_report_func_flow(modify_index)
                        print("Returned to section modification" +
                              " for section {}\n".format(section[0]))
                else:
                    section[modify_index +
                            1] = modify_report_func_flow(val_to_change)
                    print("Returned to section modification" +
                          " for section {}\n".format(section[0]))
            else:
                break
    return section
예제 #3
0
def report_sections_flow(report_json):
    """ Interactive setup for modifying sections of a report

    :param report_json: the loaded json of the report
    :type report_json: dict
    """
    print("\nModifying report sections\n=========================\n")
    while True:
        print("Current sections:")
        for i, item in enumerate(report_json["sections"]):
            print("{}: {}".format(i, item[0]))
        print("\nYou may add, modify or delete a section," +
              " or cancel out of this dialogue.")
        print("Do you want to add a section? (y/N)")
        if input.yes_no_input():
            print("At which index should this section be added?")
            modify_index = input.int_input()
            report_json["sections"].insert(modify_index, create_section_flow())
            continue
        if len(report_json["sections"]) == 0:
            print("No sections left to modify / delete!")
        else:
            print("Do you want to modify a section? (y/N)")
            if input.yes_no_input():
                print("Which number section would you like to modify?")
                modify_index = input.int_input()
                while True:
                    try:
                        sec_to_modify = report_json["sections"][modify_index]
                        break
                    except:
                        print("The index you gave ({})".format(modify_index) +
                              " is not a valid index.")
                        modify_index = input.int_input()
                report_json["sections"] \
                           [modify_index] = modify_section_flow(sec_to_modify)
                continue
            print("Do you want to delete a section? (y/N)")
            if input.yes_no_input():
                print("Which number section would you like to delete?")
                delete_index = input.int_input()
                while True:
                    try:
                        del report_json["sections"][delete_index]
                        break
                    except:
                        print("The index you gave ({})".format(delete_index) +
                              " is not a valid index.")
                        delete_index = input.int_input()
                continue
        print("Do you want to finish editing sections? (y/N)")
        if input.yes_no_input():
            break
예제 #4
0
def modify_report_func_flow(report_func):
    print("Now modifying the report function {}".format(report_func[0]))
    while True:
        print("Current report function arguments:")
        for i, item in enumerate(report_func[1:]):
            if isinstance(item, list):
                print("{}: figure function '{}'".format(i, item[0]))
            else:
                print("{}: value '{}'".format(i, item))
        print("Do you wish to modify an argument (y)" +
              " or stop modifying this report function (N)?")
        if input.yes_no_input():
            print("Which index argument do you wish to modify?")
            modify_index = input.int_input()
            while True:
                try:
                    val_to_change = report_func[modify_index + 1]
                    break
                except:
                    print("The index you gave ({})".format(modify_index) +
                          " is not a valid index.")
                    modify_index = input.int_input()
            replace = True
            if isinstance(val_to_change, list):
                print("This argument is the" +
                      " figure function {}".format(val_to_change[0]) +
                      "\nDo you wish to modify this figure function (y)" +
                      " or replace it with something else (N)?")
                if input.yes_no_input():
                    replace = False
            if replace:
                print("Is argument {} a value (y),".format(modify_index) +
                      "or is it a figure function (N)?")
                if input.yes_no_input():
                    print("What is the value of" +
                          " argument {}?".format(modify_index))
                    report_func[modify_index + 1] = input.text_input()
                else:
                    report_func[modify_index +
                                1] = create_figure_func_flow(modify_index)
                    print("Returned to report function modification" +
                          " for report function {}\n".format(report_func[0]))
            else:
                report_func[modify_index +
                            1] = modify_figure_func_flow(val_to_change)
                print("Returned to report function modification" +
                      " for report function {}\n".format(report_func[0]))
        else:
            break
    return report_func
예제 #5
0
def report_modification_flow(report_name):
    """ Interactive setup for modifying a report

    :param report_name: the name of the report to modify
    :type report_name: str
    """
    with open("report_json/{}.json".format(report_name), "r") as infile:
        report_json = json.load(infile)
    print("Modifying report '{}'\n".format(report_name))
    if "autodo" in report_json:
        print("'autodo' is set to '{}'. Change it to '{}'? (y/N)".format(
            report_json["autodo"], 1 - report_json["autodo"]))
        if input.yes_no_input():
            report_json["autodo"] = 1 - report_json["autodo"]
    else:
        print("No 'autodo' tag found." +
              " Do you want this report to be generated automatically? (y/N)")
        if input.yes_no_input():
            report_json["autodo"] = 1
    if "frequency" in report_json:
        announce_str = (
            "'frequency' is set to '{}'." +
            " This represents the period of the time that the report covers." +
            " Do you wish to change it? (y/N)")
        announce_str = announce_str.format(report_json["frequency"])
        print(announce_str)
        if input.yes_no_input():
            print("What period of time should this report cover?")
            report_json["frequency"] = input.frequency_input()
    else:
        print("No 'frequency' tag found." +
              " What should the frequency tag be?")
        report_json["frequency"] = input.frequency_input()
    if "offset" in report_json:
        announce_str = ("'offset' is set to '{}'." +
                        " Do you wish to change it? (y/N)")
        announce_str = announce_str.format(report_json["offset"])
        print(announce_str)
        if input.yes_no_input():
            print("What should the new offset tag be?")
            report_json["offset"] = input.int_input()
    else:
        print(
            "No 'offset' tag found." +
            " Should this report be offset a certain number of periods from" +
            " the current date? (y/N)")
        if input.yes_no_input():
            print("How many periods in the past should this report be?")
            report_json["offset"] = input.int_input()
    print("Do you wish to modify the sections in this report? (y/N)")
    if input.yes_no_input():
        if "sections" not in report_json:
            report_json["sections"] = []
        report_sections_flow(report_json)
    print("Saving report...")
    with open("report_json/{}.json".format(report_name), "w") as outfile:
        json.dump(report_json, outfile)
    print("Done modifying report '{}'\n".format(report_name))
예제 #6
0
def report_creation_flow(report_name):
    """ Interactive setup for creating a report

    :param report_name: the name of the report to create
    :type report_name: str
    """
    print("Creating report '{}'\n".format(report_name))
    report_json = {}
    print("Do you want this report to be generated automatically? (y/N)")
    if input.yes_no_input():
        report_json["autodo"] = 1
    print("What period of time should this report cover?")
    report_json["frequency"] = input.frequency_input()
    print("Should this report be offset a certain number of periods from the" +
          " current date? (y/N)")
    if input.yes_no_input():
        print("How many periods in the past should this report be?")
        report_json["offset"] = input.int_input()
    report_json["sections"] = []
    report_sections_flow(report_json)
    print("Saving report...")
    with open("report_json/{}.json".format(report_name), "w") as outfile:
        json.dump(report_json, outfile)
    print("Successfully created report '{}'\n".format(report_name))
예제 #7
0
def create_report_func_flow(index):
    print("What report function is argument {}?".format(index))
    report_function = [input.text_input()]
    print("How many arguments does" + " {} take?".format(report_function[0]))
    no_args = input.int_input()
    for i in range(no_args):
        print("Is {} argument {} a value (y),".format(report_function[0], i) +
              "or is it a figure function (N)?")
        if input.yes_no_input():
            print("What is the value of argument {}?".format(i))
            report_function.append(input.text_input())
        else:
            report_function.append(create_figure_func_flow(index, i))
            print("Returned to report function creation" +
                  " for report function {}\n".format(report_function[0]))
    return report_function
예제 #8
0
def create_section_flow():
    print("What LaTeX function should this section call?")
    new_section = [input.text_input()]
    print("How many arguments does {} take?".format(new_section[0]))
    no_args = input.int_input()
    for i in range(no_args):
        print("Is {} argument {} a value (y),".format(new_section[0], i) +
              "or is it a report function (N)?")
        if input.yes_no_input():
            print("What is the value of argument {}?".format(i))
            new_section.append(input.text_input())
        else:
            new_section.append(create_report_func_flow(i))
            print("Returned to section creation" +
                  " for section {}\n".format(new_section[0]))
    return new_section
예제 #9
0
def modify_figure_func_flow(figure_func):
    print("Now modifying the figure function {}".format(figure_func[0]))
    while True:
        print("Current figure function arguments:")
        for i, item in enumerate(figure_func[1:]):
            print("{}: value '{}'".format(i, item))
        print("Do you wish to replace an argument (y)" +
              " or stop modifying this figure function (N)?")
        if input.yes_no_input():
            print("Which index argument do you wish to modify?")
            modify_index = input.int_input()
            while True:
                try:
                    val_to_change = figure_func[modify_index + 1]
                    break
                except:
                    print("The index you gave ({})".format(modify_index) +
                          " is not a valid index.")
                    modify_index = input.int_input()
            print("What is the value of argument {}?".format(modify_index))
            figure_func[modify_index + 1] = input.text_input()
        else:
            break
    return figure_func
예제 #10
0
def default_setup_flow(foldername=None):
    """ Interactive setup for the user.
    Called with --setup argument.

    :param foldername: the name of the drive folder,
        defaults to None (in which case, if a config.ini exists, the default
        folder name in it is used, and otherwise config setup is executed to
        get a default folder name set up.)
    :type foldername: str, optional
    """
    config_already_done = False
    #If necessary, generate defaults
    try:
        with open("config.ini", "r") as configfile:
            config_txt = configfile.read()
        config_dict = dict([
            item.split(":") for item in config_txt.split("\n")
            if len(item.split(":")) == 2
        ])
    except IOError:
        print("No config.ini found. Running config setup...")
        config_dict = {
            "__default_payment": "__default_payment",
            "__default_to_account": "__default_to_account",
            "__default_from_account": "__default_from_account"
        }
        config.config_setup_flow(config_dict)
        config_already_done = True
    if foldername is None:
        foldername = config_dict["__default_folder_name"]
    #Create an auth token
    drive_folder = odf.DriveFolder(foldername)
    #Create missing subdirectories and files on machine
    dirlist = os.listdir(os.getcwd())
    for folder_name in ["databases", "templates", "report_json"]:
        if folder_name not in dirlist:
            print("Creating '{}' folder".format(folder_name))
            os.mkdir(folder_name)
    #Opt: modify defaults
    if not config_already_done:
        print("Do you wish to modify the values in config.ini? (y/N)")
        if input.yes_no_input():
            config.config_setup_flow(config_dict)
    #Opt: initialise financial account(s)
    print("Do you wish to initialise a financial account? (y/N)")
    finance_init = input.yes_no_input()
    if finance_init:
        finance_data = fdat.FinanceData(foldername)
        while (finance_init):
            print("Which account would you like to set the" +
                  " initial balance for?")
            account_name = input.text_input()
            print("What is the initial balance for '{}'".format(account_name))
            balance = input.money_input()
            init_time = datetime.datetime.now()
            finance_data.set_initial_balance(account_name, balance, init_time)
            print("Set initial balance of '{}' to {}".format(
                account_name, balance))
            print("Do you wish to initialise another financial account? (y/N)")
            finance_init = input.yes_no_input()
    #Opt: initialise shortcut(s)
    print("Do you want to set up payment shortcuts? (y/N)")
    shortcut_init = input.yes_no_input()
    if shortcut_init:
        #Get parsed payments file
        import src.parse.shortcuts as shortparse
        raw_shortcut_file = drive_folder.child_file("Shortcuts")
        parsed_shortcut_file = shortparse.ParsedShortcuts(raw_shortcut_file)
        #Do shortcuts flow
        while shortcut_init:
            shortcuts.shortcut_setup_flow(parsed_shortcut_file)
            print("Do you want to set up another payment shortcut? (y/N)")
            shortcut_init = input.yes_no_input()
        #Save to drive
        write_text = "\r\n".join([line for line in parsed_shortcut_file])
        raw_shortcut_file.write_from_string(write_text)
    #Opt: initialise report(s)
    print("Do you want to create/modify/clone a report? (y/N)")
    report_init = input.yes_no_input()
    while report_init:
        reports.report_setup_flow()
        print("Do you want to set up another report? (y/N)")
        report_init = input.yes_no_input()
예제 #11
0
def report_setup_flow():
    """ Interactive setup for creating, cloning or modifying a report
    """
    report_names = [item[:-5] for item in os.listdir("report_json/")]
    print("\nReport Setup\n============\n")
    print("You may create, clone or modify a report," +
          " or cancel out of this dialogue.")
    dokey = ""
    modify_name = None
    while True:
        print("Do you want to create a new report? (y/N)")
        if input.yes_no_input():
            dokey = "create"
            break
        print("Do you want to clone an existing report? (y/N)")
        if input.yes_no_input():
            dokey = "clone"
            break
        print("Do you want to modify an existing report? (y/N)")
        if input.yes_no_input():
            dokey = "modify"
            break
        print("Do you want to exit this dialogue? (y/N)")
        if input.yes_no_input():
            dokey = "leave"
            break
    if dokey == "create":
        print("What should the new report be named?")
        new_name = input.text_input()
        while new_name in report_names:
            print("The name you gave ({})".format(clone_name) +
                  " is already a recognised report name." +
                  " Please input an original name.")
            print("Existing reports are:")
            print(report_names)
        report_creation_flow(new_name)
    if dokey == "clone":
        print("Existing reports are:")
        print(report_names)
        print("Which report would you like to clone?")
        clone_name = input.text_input()
        while clone_name not in report_names:
            print("The name you gave ({})".format(clone_name) +
                  " is not a recognised report name.")
            print("Existing reports are:")
            print(report_names)
        print("Selected '{}' to clone".format(clone_name))
        print("What should the cloned report be named?")
        new_name = input.text_input()
        while new_name in report_names:
            print("The name you gave ({})".format(clone_name) +
                  " is already a recognised report name." +
                  " Please input an original name.")
            print("Existing reports are:")
            print(report_names)
        with open("report_json/{}.json".format(clone_name), "r") as infile:
            clone_file_txt = infile.read()
        with open("report_json/{}.json".format(new_name), "w") as outfile:
            outfile.write(clone_file_txt)
        print(
            "Successfully cloned '{}' to '{}'.".format(clone_name, new_name) +
            " Would you like to further modify '{}'? (y/N)".format(new_name))
        if input.yes_no_input():
            dokey = "modify"
            modify_name = new_name
    if dokey == "modify":
        if modify_name is None:
            print("Existing reports are:")
            print(report_names)
            print("Which report would you like to modify?")
            modify_name = input.text_input()
            while modify_name not in report_names:
                print("The name you gave ({})".format(modify_name) +
                      " is not a recognised report name.")
                print("Existing reports are:")
                print(report_names)
        report_modification_flow(modify_name)
예제 #12
0
def shortcut_setup_flow(shortcuts):
    """ Interactive setup for adding payment shortcuts

    :param shortcuts: the parsed shortcuts file
    :type shortcuts: class: `src.parse.shortcuts.ParsedShortcuts`
    """
    #Get shortcut key
    input_fine = False
    while not input_fine:
        print("What would you like the shortcut to be named?")
        print("(Note: all shortcuts start with an asterisk (*)."
            + " One will be added if not given.)")
        shortcut_key = input.text_input()
        if shortcut_key[0] != "*":
            shortcut_key = "*" + shortcut_key
        print("Shortcut key: '{}'. Is this fine? (y/N)".format(shortcut_key))
        input_fine = input.yes_no_input()
    #Is the shortcut a purchase or a transfer?
    input_fine = False
    while not input_fine:
        print("Is the shortcut a purchase or is it a transfer?")
        shortcut_type = input.text_input().lower().strip()
        if shortcut_type in ["purchase","transfer"]:
            print("Shortcut type: '{}'. Is this fine? (y/N)".format(shortcut_type))
            input_fine = input.yes_no_input()
        else:
            print("Please type either 'purchase' or 'transfer'.")
    isTransfer = shortcut_type == "transfer"
    #To account (leave blank for default)
    input_fine = False
    while not input_fine:
        if isTransfer:
            print("Which account are you transferring to?"
                + " (Leave blank for default transfer account)")
        else:
            print("What are you purchasing?")
        to_account = input.text_input().lower().strip()
        if to_account == "":
            if isTransfer:
                to_account = "__default_to_account"
                print("Transferring to default account. Is this fine? (y/N)")
                input_fine = input.yes_no_input()
            else:
                print("Please input a valid (non-blank) purchase item.")
        else:
            if isTransfer:
                print("Transferring to account '{}'.".format(to_account)
                    + " Is this fine? (y/N)")
            else:
                print("Purchasing '{}'.".format(to_account)
                    + " Is this fine? (y/N)")
            input_fine = input.yes_no_input()
    #Get shortcut amount
    input_fine = False
    while not input_fine:
        if isTransfer:
            print("How much money is this transfer?")
        else:
            print("How much does this purchase cost?")
        shortcut_amount = input.money_input()
        print("Amount: '£{}'. Is this fine? (y/N)".format(shortcut_amount))
        input_fine = input.yes_no_input()
    #From account (leave blank for default)
    input_fine = False
    while not input_fine:
        if isTransfer:
            print("Which account are you transferring from?"
                + " (Leave blank for default transfer account)")
        else:
            print("Which account are you using to pay?"
                + " (Leave blank for default payment account)")
        from_account = input.text_input().lower().strip()
        if from_account == "":
            if isTransfer:
                from_account = "__default_from_account"
                print("Transferring from default account. Is this fine? (y/N)")
                input_fine = input.yes_no_input()
            else:
                from_account = "__default_payment"
                print("Paying with default payment account."
                    + " Is this fine? (y/N)")
                input_fine = input.yes_no_input()
        else:
            if isTransfer:
                print("Transferring from account '{}'.".format(from_account)
                    + " Is this fine? (y/N)")
            else:
                print("Paying with account '{}'.".format(from_account)
                    + " Is this fine? (y/N)")
            input_fine = input.yes_no_input()
    #Create shortcut code
    if isTransfer:
        #Transfer: £{amount} transferred from {from_account} to {to_account}
        shortcut_code = "£{} transferred".format(shortcut_amount)
        if from_account != "__default_from_account":
            shortcut_code += " from {}".format(from_account)
        if to_account != "__default_to_account":
            shortcut_code += " to {}".format(to_account)
    else:
        #Payment: £{amount} spent on {item} paid by {account}
        shortcut_code = "£{} spent on {}".format(shortcut_amount,to_account)
        if from_account != "__default_payment":
            shortcut_code += " paid by {}".format(from_account)
    #Add shortcut to file
    shortcuts.add_line(shortcut_key,shortcut_code)