aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSjur Fredriksen <sjur@sjurtf.net>2025-04-22 22:54:29 +0200
committerGitHub <noreply@github.com>2025-04-22 22:54:29 +0200
commit7111f02967a18740f23fb00b56ec9012d2173020 (patch)
tree68175a1a7490b19338543add1e644bafab786ca8
parentd98b28fb005d6c379299175a3aedc15f56cfa925 (diff)
parent9b7d6fe5be6a68a4954a5f02c877d47086663d39 (diff)
Merge pull request #122 from sklirg/feat/read-from-planningHEADmain
feat: Support reading from (planning output) file
-rw-r--r--tech-support/labels/README.rst10
-rw-r--r--tech-support/labels/main.py20
-rw-r--r--tech-support/labels/planning_output.py14
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)