From 3e5e4338253068ddb9758b90a2579044f26f6847 Mon Sep 17 00:00:00 2001 From: Michael Hohenstein Date: Wed, 6 Sep 2023 22:19:26 +0200 Subject: [PATCH] got rid of prettytable dependency, new release --- pyproject.toml | 3 +-- src/timeforge/__main__.py | 49 +++++++++++++++++++-------------------- src/timeforge/core.py | 25 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 518f63a..f05f8c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "TimeForge" -version = "1.0.1" +version = "1.0.2" authors = [ { name="Michael Hohenstein", email="michael@hohenste.in" }, ] @@ -22,7 +22,6 @@ classifiers = [ ] dependencies = [ "argcomplete >= 3.0.5", - "prettytable >= 3.6.0", "feiertage-de >= 0.1.0", "requests >= 2.31.0", "pypdf >= 3.10.0", diff --git a/src/timeforge/__main__.py b/src/timeforge/__main__.py index fe4cefb..edc37bc 100644 --- a/src/timeforge/__main__.py +++ b/src/timeforge/__main__.py @@ -57,26 +57,6 @@ def main(): ######################################### - if args.verbose: - from prettytable import PrettyTable - tab = PrettyTable() - tab.field_names = ["Parameter", "Value"] - tab.add_row(["Name", args.name]) - tab.add_row(["Month", args.month]) - tab.add_row(["Year", args.year]) - tab.add_row(["Working Time", args.time]) - tab.add_row(["Personell number", args.personell]) - tab.add_row(["Salary", str(args.salary) + '€']) - tab.add_row(["Organisation unit", args.organisation]) - tab.add_row(["GF", args.g]) - tab.add_row(["UB", args.u]) - tab.add_row(["Verbose", args.verbose]) - tab.add_row(["Output-File", args.output]) - tab.add_row(["Job-task", args.job]) - print(tab) - - ######################################### - # prevent autopep8 from moving these imports to the front if True: import feiertage @@ -91,6 +71,28 @@ def main(): ######################################### + if args.verbose: + core.PrintDictAsTable( + { + "Name": args.month, + "Month": args.month, + "Year": args.year, + "Working Time": args.time, + "Personell number": args.personell, + "Salary": str(args.salary) + '€', + "Organisation unit": args.organisation, + "GF": args.g, + "UB": args.u, + "Verbose": args.verbose, + "Output-File": args.output, + "Job-task": args.job, + }, + "Command Line Arguments", + "Values" + ) + + ######################################### + form_data = { 'Std': args.time, 'Summe': args.time, @@ -116,9 +118,7 @@ def main(): ######################################### if args.verbose: - from pprint import pprint - print("\nCalculated Holidays:") - pprint(feiertage_list) + core.PrintListAsTable(feiertage_list, "Calculated Holidays") ######################################### @@ -138,8 +138,7 @@ def main(): ######################################### if args.verbose: - print("\nForm Data:") - pprint(form_data) + core.PrintDictAsTable(form_data, "PDF Form field", "Value") ######################################### diff --git a/src/timeforge/core.py b/src/timeforge/core.py index 2064ca5..bfea1f8 100644 --- a/src/timeforge/core.py +++ b/src/timeforge/core.py @@ -43,6 +43,31 @@ def PrintDictAsTable(dataset: dict, title_keys: str, title_values: str): print("└─" + "─" * max_key_len + "─┴─" + "─" * max_value_len + "─┘") +def PrintListAsTable(dataset: list, title: str): + """ + This function prints a list as a table. + This is really useful for debugging purpose and will be called multiple times when the verbose flag is set. + + Parameters + ---------- + dataset : list + The list which should be printed as a table + title : str + The title of the list + + """ + max_len = len(title) + for i in dataset: + max_len = max(len(str(i)), max_len) + + print("┌─" + "─" * max_len + "─┐") + print("│ " + title + " " * (max_len - len(title)) + " │") + print("├─" + "─" * max_len + "─┤") + for i in dataset: + print("│ " + str(i) + " " * (max_len - len(str(i))) + " │") + print("└─" + "─" * max_len + "─┘") + + class APP_Data: def __init__(self):