[Dependencies] Added auto-download for iBoM

This commit is contained in:
Salvador E. Tropea 2022-06-30 10:03:26 -03:00
parent 166e927ca4
commit 59d6d2caac
6 changed files with 33 additions and 37 deletions

View File

@ -133,7 +133,7 @@ Notes:
- Mandatory for `pcbdraw`
- Optional to create realistic solder masks for `pcb_print`
[**Interactive HTML BoM**](https://github.com/INTI-CMNB/InteractiveHtmlBom) v2.4.1.4 [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://github.com/INTI-CMNB/InteractiveHtmlBom)
[**Interactive HTML BoM**](https://github.com/INTI-CMNB/InteractiveHtmlBom) v2.4.1.4 [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://github.com/INTI-CMNB/InteractiveHtmlBom) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png)
- Mandatory for `ibom`
[**KiBoM**](https://github.com/INTI-CMNB/KiBoM) v1.8.0 [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://github.com/INTI-CMNB/KiBoM) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png)

View File

@ -17,8 +17,8 @@ import site
from sys import exit, stdout
from shutil import which, rmtree, move
from math import ceil
from .kiplot import search_as_plugin
from .misc import MISSING_TOOL, TRY_INSTALL_CHECK, W_DOWNTOOL, W_MISSTOOL, USER_AGENT
from .gs import GS
from . import log
logger = log.get_logger()
@ -32,6 +32,20 @@ version_check_fail = False
binary_tools_cache = {}
def search_as_plugin(cmd, names):
""" If a command isn't in the path look for it in the KiCad plugins """
name = which(cmd)
if name is not None:
return name
for dir in GS.kicad_plugins_dirs:
for name in names:
fname = os.path.join(dir, name, cmd)
if os.path.isfile(fname):
logger.debug('Using `{}` for `{}` ({})'.format(fname, cmd, name))
return fname
return None
def show_progress(done):
stdout.write("\r[%s%s] %3d%%" % ('=' * done, ' ' * (50-done), 2*done))
stdout.flush()
@ -423,8 +437,9 @@ def do_int(v):
return int(v) if v is not None else 0
def run_command(cmd, only_first_line=True, pre_ver_text=None, no_err_2=False):
def run_command(cmd, only_first_line=False, pre_ver_text=None, no_err_2=False):
global last_stderr
logger.debugl(3, '- Running {}'.format(cmd))
try:
res_run = subprocess.run(cmd, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
@ -445,6 +460,7 @@ def run_command(cmd, only_first_line=True, pre_ver_text=None, no_err_2=False):
for pre_ver in pre_vers:
if pre_ver and res.startswith(pre_ver):
res = res[len(pre_ver):]
logger.debugl(3, '- Looking for version in `{}`'.format(res))
res = ver_re.search(res)
if res:
return tuple(map(do_int, res.groups()))

View File

@ -135,19 +135,6 @@ def check_eeschema_do():
check_script(CMD_EESCHEMA_DO, URL_EESCHEMA_DO, '1.5.4')
def search_as_plugin(cmd, names):
""" If a command isn't in the path look for it in the KiCad plugins """
if which(cmd) is not None:
return cmd
for dir in GS.kicad_plugins_dirs:
for name in names:
fname = os.path.join(dir, name, cmd)
if os.path.isfile(fname):
logger.debug('Using `{}` for `{}` ({})'.format(fname, cmd, name))
return fname
return cmd
def extract_errors(text):
in_error = in_warning = False
msg = ''

View File

@ -7,8 +7,8 @@ import os
from subprocess import (check_output, STDOUT, CalledProcessError)
from shutil import which
from .misc import (CMD_IBOM, URL_IBOM, BOM_ERROR, W_EXTNAME, ToolDependency, ToolDependencyRole, W_NONETLIST)
from .gs import (GS)
from .kiplot import check_script, search_as_plugin
from .gs import GS
from .dep_downloader import check_tool, pytool_downloader
from .out_base import VariantOptions
from .registrable import RegDependency
from .macros import macros, document, output_class # noqa: F401
@ -18,15 +18,11 @@ logger = log.get_logger()
WARNING_MIX = "Avoid using it in conjunction with IBoM native filtering options"
PLUGIN_NAMES = ['InteractiveHtmlBom', 'InteractiveHtmlBom/InteractiveHtmlBom',
'org_openscopeproject_InteractiveHtmlBom/InteractiveHtmlBom']
RegDependency.register(ToolDependency('ibom', 'Interactive HTML BoM', URL_IBOM, url_down=URL_IBOM+'/releases',
ibom_dep = ToolDependency('ibom', 'Interactive HTML BoM', URL_IBOM, url_down=URL_IBOM+'/releases',
command=CMD_IBOM, in_debian=False, no_cmd_line_version_old=True,
plugin_dirs=PLUGIN_NAMES, roles=ToolDependencyRole(version=(2, 4, 1, 4))))
def check_tool():
tool = search_as_plugin(CMD_IBOM, PLUGIN_NAMES)
check_script(tool, URL_IBOM)
return tool
plugin_dirs=PLUGIN_NAMES, downloader=pytool_downloader,
roles=ToolDependencyRole(version=(2, 4, 1, 4)))
RegDependency.register(ibom_dep)
class IBoMOptions(VariantOptions):
@ -149,7 +145,7 @@ class IBoMOptions(VariantOptions):
def run(self, name):
super().run(name)
tool = check_tool()
tool = check_tool(ibom_dep, fatal=True)
logger.debug('Doing Interactive BoM')
# Tell ibom we don't want to use the screen
os.environ['INTERACTIVE_HTML_BOM_NO_DISPLAY'] = ''
@ -226,11 +222,7 @@ class IBoM(BaseOutput): # noqa: F821
@staticmethod
def get_conf_examples(name, layers, templates):
enabled = True
try:
check_tool()
except SystemExit:
enabled = False
if not enabled:
tool = check_tool(ibom_dep)
if tool is None:
return None
return BaseOutput.simple_conf_examples(name, 'Interactive HTML BoM', 'Assembly') # noqa: F821

View File

@ -188,7 +188,7 @@ deps = '{\
"Interactive HTML BoM": {\
"command": "generate_interactive_bom.py",\
"deb_package": "interactive html bom",\
"downloader": null,\
"downloader": {},\
"extra_deb": null,\
"help_option": "--version",\
"importance": 10000,\

View File

@ -9,7 +9,8 @@ from kibot.layer import Layer
from kibot.pre_base import BasePreFlight
from kibot.out_base import BaseOutput
from kibot.gs import GS
from kibot.kiplot import load_actions, _import, load_board, search_as_plugin, generate_makefile
from kibot.kiplot import load_actions, _import, load_board, generate_makefile
from kibot.dep_downloader import search_as_plugin
from kibot.registrable import RegOutput, RegFilter
from kibot.misc import (WRONG_INSTALL, BOM_ERROR, DRC_ERROR, ERC_ERROR, PDF_PCB_PRINT, CMD_PCBNEW_PRINT_LAYERS, KICAD2STEP_ERR)
from kibot.bom.columnlist import ColumnList
@ -308,7 +309,7 @@ def test_search_as_plugin_fail(test_dir, caplog):
dir_fake = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data')
GS.kicad_plugins_dirs.append(dir_fake)
fname = search_as_plugin('fake', [''])
assert fname == 'fake'
assert fname is None
def test_layer_no_id():