Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional bom.ini configuration of boards (qty of PCBs in the BOM) and pcbConfig (the PCB variant). #46

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions KiBOM_CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def isExtensionSupported(filename):

parser.add_argument("netlist", help='xml netlist file. Use "%%I" when running from within KiCad')
parser.add_argument("output", default="", help='BoM output file name.\nUse "%%O" when running from within KiCad to use the default output name (csv file).\nFor e.g. HTML output, use "%%O.html"')
parser.add_argument("-n", "--number", help="Number of boards to build (default = 1)", type=int, default=1)
parser.add_argument("-n", "--number", help="Number of boards to build (default = 1)", type=int, default=None)
parser.add_argument("-v", "--verbose", help="Enable verbose output", action='count')
parser.add_argument("-r", "--variant", help="Board variant, used to determine which components are output to the BoM", type=str, default=None)
parser.add_argument("--cfg", help="BoM config file (script will try to use 'bom.ini' if not specified here)")
Expand Down Expand Up @@ -96,12 +96,14 @@ def isExtensionSupported(filename):

#pass various command-line options through
pref.verbose = verbose
pref.boards = args.number
if args.number is not None:
pref.boards = args.number
pref.separatorCSV = args.separator

if args.variant is not None:
pref.pcbConfig = args.variant
print("PCB variant:", args.variant)
print("PCB variant:", pref.pcbConfig)


#write preference file back out (first run will generate a file with default preferences)
if not have_cfile:
Expand Down
16 changes: 15 additions & 1 deletion bomlib/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class BomPref:
OPT_IGNORE_DNF = "ignore_dnf"
OPT_BACKUP = "make_backup"
OPT_INCLUDE_VERSION = "include_version_number"
OPT_DEFAULT_BOARDS = "number_boards"
OPT_DEFAULT_PCBCONFIG = "board_variant"

OPT_CONFIG_FIELD = "fit_field"

Expand All @@ -45,7 +47,7 @@ def __init__(self):
self.groupConnectors = True # Group connectors and ignore component value
self.useRegex = True # Test various columns with regex

self.boards = 1
self.boards = 1 # Quantity of boards to be made
self.mergeBlankFields = True # Blanks fields will be merged when possible
self.hideHeaders = False
self.verbose = False # By default, is not verbose
Expand Down Expand Up @@ -130,6 +132,12 @@ def Read(self, file, verbose=False):
if cf.has_option(self.SECTION_GENERAL, self.OPT_CONFIG_FIELD):
self.configField = cf.get(self.SECTION_GENERAL, self.OPT_CONFIG_FIELD)

if cf.has_option(self.SECTION_GENERAL, self.OPT_DEFAULT_BOARDS):
self.boards = self.checkInt(cf, self.OPT_DEFAULT_BOARDS, default=None)

if cf.has_option(self.SECTION_GENERAL, self.OPT_DEFAULT_PCBCONFIG):
self.pcbConfig = cf.get(self.SECTION_GENERAL, self.OPT_DEFAULT_PCBCONFIG)

if cf.has_option(self.SECTION_GENERAL, self.OPT_BACKUP):
self.backup = cf.get(self.SECTION_GENERAL, self.OPT_BACKUP)
else:
Expand Down Expand Up @@ -194,6 +202,12 @@ def Write(self, file):

cf.set(self.SECTION_GENERAL, '; Make a backup of the bom before generating the new one, using the following template')
cf.set(self.SECTION_GENERAL, self.OPT_BACKUP, self.backup)

cf.set(self.SECTION_GENERAL, '; Default number of boards to produce if none given on CLI with -n')
cf.set(self.SECTION_GENERAL, self.OPT_DEFAULT_BOARDS, self.boards)

cf.set(self.SECTION_GENERAL, '; Default PCB variant if none given on CLI with -r')
cf.set(self.SECTION_GENERAL, self.OPT_DEFAULT_PCBCONFIG, self.pcbConfig)

cf.add_section(self.SECTION_IGNORE)
cf.set(self.SECTION_IGNORE, "; Any column heading that appears here will be excluded from the Generated BoM")
Expand Down