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 capability for ini file usage from the command line #432

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
61 changes: 61 additions & 0 deletions InteractiveHtmlBom/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Config:
board_variant_whitelist = []
board_variant_blacklist = []
dnp_field = ''
use_ini = False

@staticmethod
def _split(s):
Expand Down Expand Up @@ -371,6 +372,8 @@ def add_options(cls, parser, version):
action='store_true')
parser.add_argument('--no-browser', help='Do not launch browser.',
action='store_true')
parser.add_argument('--use-ini', help='Use all run options from ibom ini file.',
action='store_true')

# General
parser.add_argument('--dest-dir', default=cls.bom_dest_dir,
Expand Down Expand Up @@ -432,6 +435,64 @@ def add_options(cls, parser, version):
'do not populate status. Components with '
'this field not empty will be excluded.')

def set_from_args_with_ini(self, args):
import configparser
import math

if os.path.isfile(self.local_config_file):
file = self.local_config_file
elif os.path.isfile(self.global_config_file):
file = self.global_config_file
else:
print("Error! No ini file in usual locations")
exit(0)

config = configparser.ConfigParser()
config.read(file)

# Html
self.dark_mode = config.get('html_defaults', 'dark_mode')
self.show_pads = config.get('html_defaults', 'show_pads')
self.show_fabrication = config.get('html_defaults', 'show_fabrication')
self.show_silkscreen = config.get('html_defaults', 'show_silkscreen')
self.highlight_pin1 = config.get('html_defaults', 'highlight_pin1')
self.redraw_on_drag = config.get('html_defaults', 'redraw_on_drag')
self.board_rotation = config.get('html_defaults', 'board_rotation')
self.checkboxes = config.get('html_defaults', 'checkboxes')
self.bom_view = config.get('html_defaults', 'bom_view')
self.layer_view = config.get('html_defaults', 'layer_view')
self.compression = config.get('html_defaults', 'compression')

# Using the command-line arg here because people will forget to set this
#self.open_browser = int(config.get('html_defaults', 'open_browser'))
self.open_browser = not args.no_browser

# General
#self.bom_dest_dir = config.get('general', 'bom_dest_dir')
self.bom_dest_dir = args.dest_dir
self.bom_name_format = config.get('general', 'bom_name_format')
self.component_sort_order = self._split(config.get('general', 'component_sort_order'))
self.component_blacklist = self._split(config.get('general', 'component_blacklist'))
self.blacklist_virtual = config.get('general', 'blacklist_virtual')
self.blacklist_empty_val = config.get('general', 'blacklist_empty_val')
self.include_tracks = config.get('general', 'include_tracks')
self.include_nets = config.get('general', 'include_nets')

# Fields
self.extra_data_file = args.extra_data_file or args.netlist_file
if args.extra_fields is not None:
self.show_fields = self.default_show_group_fields + \
self._split(args.extra_fields)
self.group_fields = self.show_fields
else:
self.show_fields = self._split(config.get('fields', 'show_fields'))
self.group_fields = self._split(config.get('fields', 'group_fields'))
self.normalize_field_case = config.get('fields', 'normalize_field_case')
self.board_variant_field = config.get('fields', 'board_variant_field')
self.board_variant_whitelist = self._split(config.get('fields', 'board_variant_whitelist'))
self.board_variant_blacklist = self._split(config.get('fields', 'board_variant_blacklist'))
self.dnp_field = config.get('fields', 'dnp_field')

def set_from_args(self, args):
# type: (argparse.Namespace) -> None
import math
Expand Down
6 changes: 5 additions & 1 deletion InteractiveHtmlBom/generate_interactive_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def main():
except ParsingException as e:
exit_error(logger, ExitCodes.ERROR_PARSE, e)
else:
config.set_from_args(args)
if args.use_ini:
config.set_from_args_with_ini(args)
else:
config.set_from_args(args)

try:
ibom.main(parser, config, logger)
except ParsingException as e:
Expand Down