From 53bdb0113d8cd362dc4551296980fe13fe0a5afb Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 27 Sep 2024 09:47:43 +0200 Subject: ... --- .sops.yaml | 3 +++ flake.lock | 21 +++++++++++++++++---- flake.nix | 2 +- overlays/worktime/worktime/__main__.py | 33 +++++++++++++++++---------------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/.sops.yaml b/.sops.yaml index 51823ad2..7b0507ee 100644 --- a/.sops.yaml +++ b/.sops.yaml @@ -5,6 +5,9 @@ keys: - &machine_sif age1fj65apkhfkrwyv5tx6zcs9nkjg8267fy733qph30sc7zfn7vapjqkd5kne creation_rules: + - path_regex: ^hosts/surtr/email/ca + key_groups: + - age: [ *admin_gkleen ] - path_regex: surtr\/?[^\/]*$ key_groups: - age: [ *admin_gkleen, *machine_surtr ] diff --git a/flake.lock b/flake.lock index 8510955d..df28d666 100644 --- a/flake.lock +++ b/flake.lock @@ -29,6 +29,7 @@ "ca-util": { "inputs": { "flake-parts": "flake-parts_2", + "leapseconds": "leapseconds", "nixpkgs": [ "nixpkgs" ], @@ -38,16 +39,16 @@ "pre-commit-hooks-nix": "pre-commit-hooks-nix_2" }, "locked": { - "lastModified": 1701974982, - "narHash": "sha256-crVlSEyoox6g8dpndqCgts3i6otVoGfDUmPz2ltG3IY=", + "lastModified": 1727074335, + "narHash": "sha256-Sn7wqhrXargYzdw19m2mtBceQnW3VdhVneXRjl0iV3U=", "owner": "gkleen", "repo": "ca", - "rev": "8cfabef934ee8219d12b9ba46e2b2f4d6dc61f8d", + "rev": "9d681fe550639eab54cc402de4852e9a438b9757", "type": "gitlab" }, "original": { "owner": "gkleen", - "ref": "v2.3.3", + "ref": "v3.0.0", "repo": "ca", "type": "gitlab" } @@ -390,6 +391,18 @@ "type": "github" } }, + "leapseconds": { + "flake": false, + "locked": { + "narHash": "sha256-5ZaoY/bScQS7EGJRHu6vj9XWhbObmxNEaGugaGU7+lg=", + "type": "file", + "url": "https://data.iana.org/time-zones/tzdb/leap-seconds.list" + }, + "original": { + "type": "file", + "url": "https://data.iana.org/time-zones/tzdb/leap-seconds.list" + } + }, "nix-github-actions": { "inputs": { "nixpkgs": [ diff --git a/flake.nix b/flake.nix index 728a6322..fc60e599 100644 --- a/flake.nix +++ b/flake.nix @@ -131,7 +131,7 @@ type = "gitlab"; owner = "gkleen"; repo = "ca"; - ref = "v2.3.3"; + ref = "v3.0.0"; inputs = { nixpkgs.follows = "nixpkgs"; poetry2nix.follows = "poetry2nix"; diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 21316182..c2c1829c 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -6,6 +6,8 @@ from xdg import BaseDirectory import toml from uritools import (uricompose) +from inspect import signature + from dateutil.easter import * from dateutil.tz import * from dateutil.parser import isoparse @@ -633,14 +635,15 @@ def holidays(year, table_format, **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() - date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') leave_expires = config.get("WORKTIME", {}).get("LeaveExpires", None) if leave_expires: leave_expires = datetime.strptime(leave_expires, '%m-%d').date() + worktime = Worktime(**dict(**args, end_datetime = datetime.combine(leave_expires.replace(year = (year if year else def_year) + 1), time(), tzinfo=tzlocal()) + timedelta(days=1) if leave_expires else datetime(year = (year if year else def_year) + 1, month = 1, day = 1, tzinfo=tzlocal()) - timedelta(microseconds=1))) + date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') days = [worktime.start_date.date() + timedelta(days = x) for x in range(0, (worktime.end_date.date() - worktime.start_date.date()).days + 1)] + leave_days_budget = {} leave_budget = deepcopy(worktime.leave_budget) year_leave_budget = deepcopy(worktime.leave_budget) if year else None @@ -655,36 +658,28 @@ def leave(year, table, table_format, **args): if leave_budget[iyear] <= 0: continue + leave_days_budget[day] = iyear leave_budget[iyear] -= 1 - if year_leave_budget and day.year < year: - year_leave_budget[iyear] -= 1 break else: print(f'Unaccounted leave: {day}', file=stderr) if table and year: table_data = [] - leave_days = sorted([day for day in worktime.leave_days if day.year == year and worktime.would_be_workday(day)]) + leave_days = sorted([day for day in worktime.leave_days if leave_days_budget[day] == year and worktime.would_be_workday(day)]) count = 0 for _, group in groupby(enumerate(leave_days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])): group = list(map(lambda kv: kv[1], group)) for day in group: - for iyear in years: - if day > leave_expires.replace(year = iyear + 1): - continue - if year_leave_budget[iyear] <= 0: - continue - - year_leave_budget[iyear] -= 1 - break + year_leave_budget[year] -= 1 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' if group[0].year == year else '%Y-%m-%d') + '…' + group[-1].strftime('%m-%d' if group[-1].year == year else '%Y-%m-%d'), len(group), year_leave_budget[year]]) 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' if group[0].year == year else '%Y-%m-%d'), len(group), year_leave_budget[year]]) count = next_count 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: @@ -834,7 +829,13 @@ def main(): classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) args = parser.parse_args() - args.cmd(**vars(args)) + args.cmd( + **{ + k: v + for k, v in vars(args).items() + if k in signature(args.cmd).parameters.keys() + } + ) if __name__ == "__main__": sys.exit(main()) -- cgit v1.2.3