Skip to content

Commit 141b19e

Browse files
committed
Make config file apply to some command line defaults
1 parent e32d068 commit 141b19e

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

InteractiveHtmlBom/config.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class Config:
5252
board_variant_blacklist = []
5353
dnp_field = ''
5454

55+
@staticmethod
56+
def _split(s):
57+
"""Splits string by ',' and drops empty strings from resulting array."""
58+
return [a for a in s.split(',') if a]
59+
5560
def __init__(self):
5661
"""Init from config file if it exists."""
5762
if not os.path.isfile(self.config_file):
@@ -72,32 +77,27 @@ def __init__(self):
7277

7378
f.SetPath('/general')
7479
self.bom_dest_dir = f.Read('bom_dest_dir', self.bom_dest_dir)
75-
self.component_sort_order = f.Read(
80+
self.component_sort_order = self._split(f.Read(
7681
'component_sort_order',
77-
','.join(self.component_sort_order)
78-
).split(',')
79-
self.component_blacklist = f.Read(
82+
','.join(self.component_sort_order)))
83+
self.component_blacklist = self._split(f.Read(
8084
'component_blacklist',
81-
','.join(self.component_blacklist)
82-
).split(',')
85+
','.join(self.component_blacklist)))
8386
self.blacklist_virtual = f.ReadBool(
8487
'blacklist_virtual', self.blacklist_virtual)
8588

8689
f.SetPath('/extra_fields')
87-
self.extra_fields = f.Read(
90+
self.extra_fields = self._split(f.Read(
8891
'extra_fields',
89-
','.join(self.extra_fields)
90-
).split(',')
92+
','.join(self.extra_fields)))
9193
self.board_variant_field = f.Read(
9294
'board_variant_field', self.board_variant_field)
93-
self.board_variant_whitelist = f.Read(
95+
self.board_variant_whitelist = self._split(f.Read(
9496
'board_variant_whitelist',
95-
','.join(self.board_variant_whitelist)
96-
).split(',')
97-
self.board_variant_blacklist = f.Read(
97+
','.join(self.board_variant_whitelist)))
98+
self.board_variant_blacklist = self._split(f.Read(
9899
'board_variant_blacklist',
99-
','.join(self.board_variant_blacklist)
100-
).split(',')
100+
','.join(self.board_variant_blacklist)))
101101
self.dnp_field = f.Read('dnp_field', self.dnp_field)
102102

103103
def save(self):
@@ -217,8 +217,7 @@ def safe_set_checked_strings(clb, strings):
217217
dlg.finish_init()
218218

219219
# noinspection PyTypeChecker
220-
@classmethod
221-
def add_options(cls, parser):
220+
def add_options(self, parser):
222221
# type: (argparse.ArgumentParser) -> None
223222
parser.add_argument('--show-dialog', action='store_true',
224223
help='Shows config dialog. All other flags '
@@ -235,30 +234,32 @@ def add_options(cls, parser):
235234
parser.add_argument('--no-redraw-on-drag',
236235
help='Do not redraw pcb on drag by default.',
237236
action='store_true')
238-
parser.add_argument('--board-rotation', type=int, default=0,
237+
parser.add_argument('--board-rotation', type=int,
238+
default=self.board_rotation * 5,
239239
help='Board rotation in degrees (-180 to 180). '
240240
'Will be rounded to multiple of 5.')
241241
parser.add_argument('--checkboxes',
242-
default=','.join(cls.default_checkboxes),
242+
default=self.checkboxes,
243243
help='Comma separated list of checkbox columns.')
244-
parser.add_argument('--bom-view', default='left-right',
245-
choices=cls.bom_view_choices,
244+
parser.add_argument('--bom-view', default=self.bom_view,
245+
choices=self.bom_view_choices,
246246
help='Default BOM view.')
247-
parser.add_argument('--layer-view', default='FB',
248-
choices=cls.layer_view_choices,
247+
parser.add_argument('--layer-view', default=self.layer_view,
248+
choices=self.layer_view_choices,
249249
help='Default layer view.')
250250
parser.add_argument('--no-browser', help='Do not launch browser.',
251251
action='store_true')
252252

253253
# General
254-
parser.add_argument('--dest-dir', default='bom/',
254+
parser.add_argument('--dest-dir', default=self.bom_dest_dir,
255255
help='Destination directory for bom file '
256256
'relative to pcb file directory.')
257257
parser.add_argument('--sort-order',
258258
help='Default sort order for components. '
259259
'Must contain "~" once.',
260-
default=','.join(cls.default_sort_order))
261-
parser.add_argument('--blacklist', default='',
260+
default=','.join(self.component_sort_order))
261+
parser.add_argument('--blacklist',
262+
default=','.join(self.component_blacklist),
262263
help='List of comma separated blacklisted '
263264
'components or prefixes with *. E.g. "X1,MH*"')
264265
parser.add_argument('--no-blacklist-virtual', action='store_true',
@@ -267,7 +268,8 @@ def add_options(cls, parser):
267268
# Extra fields section
268269
parser.add_argument('--netlist-file',
269270
help='Path to netlist or xml file.')
270-
parser.add_argument('--extra-fields', default='',
271+
parser.add_argument('--extra-fields',
272+
default=','.join(self.extra_fields),
271273
help='Comma separated list of extra fields to '
272274
'pull from netlist or xml file.')
273275
parser.add_argument('--variant-field',
@@ -279,7 +281,7 @@ def add_options(cls, parser):
279281
parser.add_argument('--variants-blacklist', default='', nargs='+',
280282
help='List of board variants to '
281283
'exclude from the BOM.')
282-
parser.add_argument('--dnp-field',
284+
parser.add_argument('--dnp-field', default=self.dnp_field,
283285
help='Name of the extra field that indicates '
284286
'do not populate status. Components with this '
285287
'field not empty will be blacklisted.')
@@ -301,13 +303,13 @@ def set_from_args(self, args):
301303

302304
# General
303305
self.bom_dest_dir = args.dest_dir
304-
self.component_sort_order = args.sort_order.split(',')
305-
self.component_blacklist = args.blacklist.split(',')
306+
self.component_sort_order = self._split(args.sort_order)
307+
self.component_blacklist = self._split(args.blacklist)
306308
self.blacklist_virtual = not args.no_blacklist_virtual
307309

308310
# Extra
309311
self.netlist_file = args.netlist_file
310-
self.extra_fields = [f for f in args.extra_fields.split(',') if f]
312+
self.extra_fields = self._split(args.extra_fields)
311313
self.board_variant_field = args.variant_field
312314
self.board_variant_whitelist = args.variants_whitelist
313315
self.board_variant_blacklist = args.variants_blacklist

0 commit comments

Comments
 (0)