partsdb

electronic parts inventory
git clone https://git.e1e0.net/partsdb.git
Log | Files | Refs

commit fe79e4d648678496118516a473b985b974e22fd9
parent 2c2b844e90c705a76b81c2db3a8586dab474d728
Author: Paco Esteban <paco@e1e0.net>
Date:   Sat, 13 Mar 2021 13:30:45 +0100

add short option for list

Diffstat:
Mhelpers.py | 44+++++++++++++++++++++++++++++---------------
MmyChips.py | 8+++++---
2 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/helpers.py b/helpers.py @@ -2,18 +2,32 @@ # -*- coding: utf-8 -*- # vim:fenc=utf-8 -def print_parts_list(parts): - print(f"{'ID':5} | {'PN':10} | " - f"{'Manufacturer':20} | " - f"{'Description':50} | " - f"{'Footp':6} | " - f"{'Qty':4} |" - ) - print("-"*112) - for p in parts: - print(f"{p['id']:<5} | {p['pn'][0:9]:10} | " - f"{p['manufacturer'][0:19]:20} | " - f"{p['description'][0:49]:50} | " - f"{p['footprint'][0:5]:6} | " - f"{p['quantity']:4} |" - ) +def print_parts_list(parts, short=False): + if short: + print(f"{'ID':5} | {'PN':10} | " + f"{'Manufacturer':20} | " + f"{'Footp':6} | " + f"{'Qty':4} |" + ) + print("-"*59) + for p in parts: + print(f"{p['id']:<5} | {p['pn'][0:9]:10} | " + f"{p['manufacturer'][0:19]:20} | " + f"{p['footprint'][0:5]:6} | " + f"{p['quantity']:4} |" + ) + else: + print(f"{'ID':5} | {'PN':10} | " + f"{'Manufacturer':20} | " + f"{'Description':50} | " + f"{'Footp':6} | " + f"{'Qty':4} |" + ) + print("-"*112) + for p in parts: + print(f"{p['id']:<5} | {p['pn'][0:9]:10} | " + f"{p['manufacturer'][0:19]:20} | " + f"{p['description'][0:49]:50} | " + f"{p['footprint'][0:5]:6} | " + f"{p['quantity']:4} |" + ) diff --git a/myChips.py b/myChips.py @@ -91,7 +91,7 @@ def add_part(mpn): db.new_part(part) -def list_parts(category): +def list_parts(category, short): if category == 'all': parts = db.get_parts() else: @@ -101,7 +101,7 @@ def list_parts(category): print("There are no parts in this category") return - print_parts_list(parts) + print_parts_list(parts, short) def search_part(search_term): @@ -154,6 +154,8 @@ if __name__ == '__main__': ap_list = asp.add_parser("list", help="List all parts from a category (or all)") ap_list.add_argument("category", help="Category Name") + ap_list.add_argument("-s", dest='short', + action='store_true', help="Short output") # search ap_search = asp.add_parser("search", help="Search for parts") ap_search.add_argument("search_term", help="Term to search for") @@ -180,7 +182,7 @@ if __name__ == '__main__': if args.command == 'add': add_part(args.mpn) elif args.command == 'list': - list_parts(args.category) + list_parts(args.category, args.short) elif args.command == 'search': search_part(args.search_term) elif args.command == 'get':