diff options
| author | Håkon Solbjørg <hlsolbjorg@gmail.com> | 2019-04-01 23:47:22 +0200 | 
|---|---|---|
| committer | Håkon Solbjørg <hlsolbjorg@gmail.com> | 2019-04-02 19:56:13 +0200 | 
| commit | e823b8fc077d4645a0565c8a769b1fb698b25a30 (patch) | |
| tree | aceb83253d28c64c93dcdc482ff9815b1cfe0ce1 /cables.py | |
| parent | 24d7c04b0a7210c6de5c83e81eb5119338685e41 (diff) | |
chore: Make the code more readable and extensible 👀
Diffstat (limited to 'cables.py')
| -rw-r--r-- | cables.py | 19 | 
1 files changed, 12 insertions, 7 deletions
@@ -1,5 +1,4 @@  from itertools import chain -import operator  from gondul import fetch_gondul_switches @@ -8,7 +7,6 @@ mark_twice = True  num_tabs = 1 -  def generate_label(switch, cable_name):      data = {          "switch_name": switch.split("-")[0], @@ -29,11 +27,18 @@ def generate_label_copies(switch, cable_name, copies=2):  def generate_labels(switches, copies=2, uplinks=3):      print("Generating {} copies of each label for {} uplinks for {} switches ({} labels)".format(          copies, uplinks, len(switches), len(switches) * uplinks * copies)) -    labels = list(map(lambda switch: -                      [generate_label_copies(switch[1:], i + 1, copies=copies) -                       for i in range(0, uplinks)], -                      switches)) -    return list(chain.from_iterable(chain.from_iterable(labels))) + +    labels = [] +    for i in range(0, len(switches)): +        switch = switches[i] +        switch_name = switch[1:] +        cable_labels = [generate_label_copies( +            switch_name, uplink + 1, copies=copies) for uplink in range(0, uplinks)] + +        # Destructure the list of copies into a flat list +        labels.extend(chain.from_iterable(cable_labels)) + +    return labels  def write_to_file(data, outfile="cable_labels.csv", filenum=1):  | 
