Beispiel #1
0
 def __init__(self, argparser):
     from InteractiveHtmlBom.core import ibom
     from InteractiveHtmlBom.core.config import Config
     from InteractiveHtmlBom.version import version
     self._config = Config(version)
     self._config.add_options(argparser, self._config.FILE_NAME_FORMAT_HINT)
     self._argparser = argparser
     self.pcbdata = None
     self.components = None
     self._logger = ibom.Logger(cli=True)
    create_wx_app = 'INTERACTIVE_HTML_BOM_NO_DISPLAY' not in os.environ
    if create_wx_app:
        import wx
        app = wx.App()

    parser = argparse.ArgumentParser(
        description='KiCad InteractiveHtmlBom plugin CLI.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('file',
                        type=lambda s: to_utf(s),
                        help="KiCad PCB file")
    config = Config(version)
    config.add_options(parser, config.FILE_NAME_FORMAT_HINT)
    args = parser.parse_args()
    logger = ibom.Logger(cli=True)
    if not os.path.isfile(args.file):
        exit_error(logger, ExitCodes.ERROR_FILE_NOT_FOUND,
                   "File %s does not exist." % args.file)
    print("Loading %s" % args.file)
    parser = get_parser_by_extension(os.path.abspath(args.file), config,
                                     logger)
    if args.show_dialog:
        if not create_wx_app:
            exit_error(
                logger, ExitCodes.ERROR_NO_DISPLAY, "Can not show dialog when "
                "INTERACTIVE_HTML_BOM_NO_DISPLAY is set.")
        try:
            ibom.run_with_dialog(parser, config, logger)
        except ParsingException as e:
            exit_error(logger, ExitCodes.ERROR_PARSE, e)