From 9c67ce4623ae1f2bf9a9d71de781c12054c1001c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 4 Apr 2023 17:14:12 +0200 Subject: ... --- overlays/worktime/worktime/__main__.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'overlays') diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 19737805..84c8a8e2 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -442,7 +442,7 @@ def format_days(worktime, days, date_format=None): ))) def format_group(group): if len(group) > 1: - return group[0].strftime(date_format) + '--' + group[-1].strftime(date_format) + return group[0].strftime(date_format) + '…' + group[-1].strftime(date_format) else: return group[0].strftime(date_format) return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) @@ -551,7 +551,7 @@ def diff(now, **args): print(now.time_to_work - then.time_to_work) -def holidays(year, **args): +def holidays(year, table_format, **args): config = Worktime.config() date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') @@ -561,9 +561,9 @@ def holidays(year, **args): for k, v in holidays.items(): kstr = k.strftime(date_format) table_data += [[kstr, v]] - print(tabulate(table_data, tablefmt="plain")) + print(tabulate(table_data, tablefmt=table_format, headers=["Date", "Proportion"] if table_format != 'plain' else None)) -def leave(year, table, **args): +def leave(year, table, table_format, **args): def_year = datetime.now(tzlocal()).year worktime = Worktime(**dict(**args, end_datetime = datetime(year = (year if year else def_year) + 1, month = 1, day = 1, tzinfo=tzlocal()) - timedelta(microseconds=1))) config = Worktime.config() @@ -611,22 +611,22 @@ def leave(year, table, **args): next_count = count + len(group) if len(group) > 1: - table_data.append([count, group[0].strftime('%m-%d') + '--' + group[-1].strftime('%m-%d'), len(group), sum(year_leave_budget.values())]) + table_data.append([count, group[0].strftime('%m–%d') + '…' + group[-1].strftime('%m–%d'), len(group), sum(year_leave_budget.values())]) else: - table_data.append([count, group[0].strftime('%m-%d'), len(group), sum(year_leave_budget.values())]) + table_data.append([count, group[0].strftime('%m–%d'), len(group), sum(year_leave_budget.values())]) count = next_count - print(tabulate(table_data, tablefmt="plain")) + print(tabulate(table_data, tablefmt=table_format, headers=["Running Count", "Leave Days", "# of Leave Days", "# of Leave Days Left"] if table_format != 'plain' else None)) elif table: table_data = [] for year, offset in leave_budget.items(): leave_days = sorted([day for day in worktime.leave_days if day.year == year]) would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)] - table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m-%d')]] - print(tabulate(table_data, tablefmt="plain")) + table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m–%d')]] + print(tabulate(table_data, tablefmt=table_format, headers=["Year", "Δ of Leave Days", " # of Leave Days\n/ Pot. Workdays", "Leave Days"] if table_format != 'plain' else None)) else: print(leave_budget[year if year else def_year]) -def classification(classification_name, table, **args): +def classification(classification_name, table, table_format, **args): worktime = Worktime(**args) config = Worktime.config() date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') @@ -719,10 +719,15 @@ def classification(classification_name, table, **args): else: row_data.append(f"{len(classified)}/{len(year_classification[year])}") - row_data.append(format_days(worktime, classified, date_format='%m-%d')) + row_data.append(format_days(worktime, classified, date_format='%m–%d')) table_data.append(row_data) - print(tabulate(table_data, tablefmt="plain")) + print(tabulate( + table_data, + tablefmt=table_format, + headers=["Year", "Running Difference", f" # of {classification_name.title()} Days\n / # of Classified Days\n(/ # of Pot. Classifiable Days)", f"{classification_name.title()} Days"] if table_format != 'plain' else None, + maxcolwidths=[None, None, None, 50] if table_format != 'plain' else None + )) def main(): config = Worktime.config() @@ -739,15 +744,18 @@ def main(): diff_parser = subparsers.add_parser('diff') diff_parser.set_defaults(cmd = diff) holidays_parser = subparsers.add_parser('holidays') + holidays_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') holidays_parser.add_argument('year', metavar = 'YEAR', type = int, help = 'Year to evaluate holidays for (default: current year)', default = datetime.now(tzlocal()).year, nargs='?') holidays_parser.set_defaults(cmd = holidays) leave_parser = subparsers.add_parser('leave') leave_parser.add_argument('year', metavar = 'YEAR', type = int, help = 'Year to evaluate leave days for (default: current year)', default = None, nargs='?') leave_parser.add_argument('--table', action = 'store_true') + leave_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') leave_parser.set_defaults(cmd = leave) for classification_name in config.get('day-classification', {}).keys(): classification_parser = subparsers.add_parser(classification_name) classification_parser.add_argument('--table', action = 'store_true') + classification_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) args = parser.parse_args() -- cgit v1.2.3