From b1592f51d4b16a125d9b28edae56f758fcac2f02 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Sat, 29 Apr 2023 09:22:35 +0100 Subject: [PATCH] Fixed bom.py, views.py and tests.py so that vitamin descriptions can contain more than one colon. --- scripts/bom.py | 4 ++-- scripts/tests.py | 4 ++-- scripts/views.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/bom.py b/scripts/bom.py index 9ec05bc..192cd21 100755 --- a/scripts/bom.py +++ b/scripts/bom.py @@ -140,7 +140,7 @@ class BOM: for part in sorted(self.vitamins): i += 1 if ': ' in part: - part_no, description = part.split(': ') + part_no, description = part.split(': ', 1) else: part_no, description = "", part qty = self.vitamins[part].count @@ -183,7 +183,7 @@ class BOM: for part in sorted(self.vitamins): if ': ' in part: - part_no, description = part.split(': ') + part_no, description = part.split(': ', 1) else: part_no, description = "", part if breakdown: diff --git a/scripts/tests.py b/scripts/tests.py index 8756654..8c323c0 100755 --- a/scripts/tests.py +++ b/scripts/tests.py @@ -259,11 +259,11 @@ def tests(tests): things = BOM[thing] if things: body += ['### %s\n| Qty | %s |\n| ---:|:--- |%s' % (thing.title(), heading, ':---|' if '|' in heading else '')] - for item in sorted(things, key = lambda s: s.split(":")[-1]): + for item in sorted(things, key = lambda s: s.split(":",1)[-1]): name = item desc = '' if thing == "vitamins": - vit = item.split(':') + vit = item.split(':', 1) name = '`' + vit[0] + '`' if vit[0] else '' while '[[' in name and ']]' in name: i = name.find('[[') diff --git a/scripts/views.py b/scripts/views.py index 157e8a3..bfa0926 100755 --- a/scripts/views.py +++ b/scripts/views.py @@ -303,7 +303,7 @@ def views(target, do_assemblies = None): grand_total2 = 0 heading = headings[t][0].upper() + headings[t][1:] print(('| ' * len(global_bom) + '| | **%s** |') % heading, file = doc_file) - for thing in sorted(things[t], key = lambda s: s.split(":")[-1]): + for thing in sorted(things[t], key = lambda s: s.split(":",1)[-1]): for ass in global_bom: count = ass[t][thing]["count"] if thing in ass[t] else 0 print('| %s ' % pad(count if count else '.', 2, 1), file = doc_file, end = '') @@ -313,7 +313,7 @@ def views(target, do_assemblies = None): else: totals[name] = count grand_total2 += count - print('| %s | %s |' % (pad(things[t][thing], 2, 1), pad(thing.split(":")[-1], 2)), file = doc_file) + print('| %s | %s |' % (pad(things[t][thing], 2, 1), pad(thing.split(":",1)[-1], 2)), file = doc_file) grand_total = 0 for ass in global_bom: @@ -344,8 +344,8 @@ def views(target, do_assemblies = None): print("### Vitamins", file = doc_file) print("|Qty|Description|", file = doc_file) print("|---:|:----------|", file = doc_file) - for v in sorted(vitamins, key = lambda s: s.split(":")[-1]): - print("|%d|%s|" % (vitamins[v]["count"], v.split(":")[1]), file = doc_file) + for v in sorted(vitamins, key = lambda s: s.split(":",1)[-1]): + print("|%d|%s|" % (vitamins[v]["count"], v.split(":",1)[1]), file = doc_file) print("\n", file = doc_file) printed = ass["printed"]