commit b0f4cff8611557a2a1363d750bddad73b889303b
parent 11155244d430e976b2ea4312d9ef9e072f7472a1
Author: Paco Esteban <paco@e1e0.net>
Date: Sun, 14 Mar 2021 12:45:56 +0100
account for missing values in listings
Diffstat:
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/helpers.py b/helpers.py
@@ -17,9 +17,9 @@ def print_parts_list(parts, short=False):
for p in parts:
print(f"{p['id']:<4} | "
f"{p['cname'][0:7]:8} | "
- f"{p['pn'][0:9]:10} | "
- f"{p['manufacturer'][0:17]:18} | "
- f"{p['description'][0:24]:25} |"
+ f"{_sanitize_value(p['pn'])[0:9]:10} | "
+ f"{_sanitize_value(p['manufacturer'])[0:17]:18} | "
+ f"{_sanitize_value(p['description'])[0:24]:25} |"
)
else:
# max takes an iterable and key is a function where iterables are
@@ -50,10 +50,10 @@ def print_parts_list(parts, short=False):
for p in parts:
print(f"{p['id']:<5} | {p['pn']:{l_pn}} | "
f"{p['cname']:{l_cat}} | "
- f"{p['manufacturer']:{l_man}} | "
- f"{p['description']:{l_desc}} | "
- f"{p['part_type'][0:3]:4} | "
- f"{p['footprint'][0:5]:6} | "
+ f"{_sanitize_value(p['manufacturer']):{l_man}} | "
+ f"{_sanitize_value(p['description']):{l_desc}} | "
+ f"{_sanitize_value(p['part_type'])[0:3]:4} | "
+ f"{_sanitize_value(p['footprint'])[0:5]:6} | "
f"{p['quantity']:4} |"
)
@@ -88,3 +88,8 @@ def print_part(p, history, get_files=False):
print(f"{h['insert_date']} | "
f"{h['movement']:4} | "
f"{h['mcomment']}")
+
+def _sanitize_value(value):
+ if value is None:
+ return "-"
+ return value