diff options
author | Håkon Solbjørg <hakon@solbj.org> | 2025-04-14 15:13:16 +0200 |
---|---|---|
committer | Håkon Solbjørg <hakon@solbj.org> | 2025-04-18 10:39:19 +0200 |
commit | 9b7d6fe5be6a68a4954a5f02c877d47086663d39 (patch) | |
tree | 6a8b4244477377cb9401ab7ff846e5f662d7f7c5 | |
parent | 5aaf88e07130007016de778dce44f8ee88f01d56 (diff) |
feat: Support reading from (planning output) file
-rw-r--r-- | tech-support/labels/README.rst | 10 | ||||
-rw-r--r-- | tech-support/labels/main.py | 20 | ||||
-rw-r--r-- | tech-support/labels/planning_output.py | 14 |
3 files changed, 33 insertions, 11 deletions
diff --git a/tech-support/labels/README.rst b/tech-support/labels/README.rst index c242d3c..b1ebada 100644 --- a/tech-support/labels/README.rst +++ b/tech-support/labels/README.rst @@ -12,10 +12,12 @@ Run the script with either ``cables`` or ``switches``, depending if you want labels for cables or switches. Configure the application further if needed. Consult ``--help``. -Specify gondul credentials either using environment variables -(``GONDUL_USERNAME``, ``GONDUL_PASSWORD``) or the command line. -It's also possible to update the API root or API endpoint to use, -as well as a regex for matching switches. +Specify gondul credentials using environment variables +(``GONDUL_USERNAME``, ``GONDUL_PASSWORD``) or the command line +to fetch from Gondul. It's possible to specify the API root +or API endpoint to use. +Use ``--planning-input-file`` to read from a local file +which contains the output from `planning <../../planning>`_. Specify the output file with the ``--outfile`` argument. diff --git a/tech-support/labels/main.py b/tech-support/labels/main.py index bb6cd23..65ab6c4 100644 --- a/tech-support/labels/main.py +++ b/tech-support/labels/main.py @@ -4,6 +4,7 @@ import sys from cables import make_cable_labels from gondul import fetch_gondul_switches from switches import make_switch_labels +from planning_output import read_planning_switches parser = argparse.ArgumentParser( "Label generator script 2000", @@ -22,6 +23,7 @@ parser.add_argument("--match-switches", type=str, default="^e([0-9]+-[0-9]+)", help="Regex for matching switches") parser.add_argument("--outfile", "-o", type=str, default=None, help="Output (base) file name. Might be appended with numbers for cables.") +parser.add_argument("--planning-input-file", type=str, help="Output file from planning, to use as input") cables_args = parser.add_argument_group("cables") cables_args.add_argument("--ap", type=str, action="append", @@ -38,13 +40,17 @@ cables_args.add_argument("--split", "-s", type=int, default=100, if __name__ == "__main__": args = parser.parse_args() - switches = fetch_gondul_switches( - api=args.gondul_api, - endpoint=args.gondul_switches, - username=args.gondul_user, - password=args.gondul_pass, - match=args.match_switches, - ) + switches = None + if args.planning_input_file: + switches = read_planning_switches(args.planning_input_file, match=args.match_switches) + else: + switches = fetch_gondul_switches( + api=args.gondul_api, + endpoint=args.gondul_switches, + username=args.gondul_user, + password=args.gondul_pass, + match=args.match_switches, + ) kwargs = {} if args.outfile is not None: diff --git a/tech-support/labels/planning_output.py b/tech-support/labels/planning_output.py new file mode 100644 index 0000000..934dc83 --- /dev/null +++ b/tech-support/labels/planning_output.py @@ -0,0 +1,14 @@ +from gondul import _match_switches +from gondul import _sort_switches + +def read_planning_switches(path, match=None): + lines = None + with open(path) as f: + lines = f.readlines() + + switches = [] + for line in lines: + switches.append(line.split(" ")[0]) + + switches = _match_switches(switches, match=match) + return _sort_switches(switches) |