aboutsummaryrefslogtreecommitdiffstats
path: root/tech-support/labels/switches.py
diff options
context:
space:
mode:
authorOle Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com>2019-04-02 20:20:25 +0200
committerGitHub <noreply@github.com>2019-04-02 20:20:25 +0200
commit02bb6476b443765bb673d4a0e93770698e44e8a7 (patch)
treeb7ae384ea3cc28f3550dd73b0baeb659faf43e26 /tech-support/labels/switches.py
parentf706bae1c3c2222a702e4121e1db8b7e9d45ab50 (diff)
parent7cd4617b362b99562e265fd9715764e4976cdf3e (diff)
Merge pull request #102 from sklirg/feat/support-label-scripts
Add label generation scripts for Tech Support
Diffstat (limited to 'tech-support/labels/switches.py')
-rw-r--r--tech-support/labels/switches.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tech-support/labels/switches.py b/tech-support/labels/switches.py
new file mode 100644
index 0000000..a218489
--- /dev/null
+++ b/tech-support/labels/switches.py
@@ -0,0 +1,43 @@
+switch_label_format = "%(switch_name)s-%(switch_num)s"
+switch_label_layout = """<!DOCTYPE html>
+<html><head>
+ <style>
+ div.a4 {
+ font-size: 24em;
+ text-align: center;
+ @page size: A4 landscape;
+
+ /* this is the part that makes each div print per page. */
+ page-break-after: always;
+ }
+ </style>
+</head>
+<body>%s</body></html>
+"""
+switch_label_page = '<div class="a4">%s</div>'
+
+
+def generate_label(switch_name, switch_number):
+ return switch_label_page % switch_label_format % {
+ "switch_name": switch_name,
+ "switch_num": switch_number,
+ }
+
+
+def generate_labels(switches):
+ labels = list(map(lambda switch: generate_label(
+ switch[1:].split("-")[0], switch.split("-")[1]), switches))
+
+ return switch_label_layout % "".join(labels)
+
+
+def write_html_to_file(html, outfile="switch_labels.html"):
+ with open(outfile, "w") as f:
+ f.write(html)
+ print("Wrote labels to '{}'.\nOpen the file in your browser and print it.".format(outfile))
+
+
+def make_switch_labels(switches, outfile="switch_labels.html"):
+ print("Generating labels for switches")
+ labels = generate_labels(switches)
+ write_html_to_file(labels, outfile=outfile)