New output "Info": collects info about the environment.

Related to #209
This commit is contained in:
Salvador E. Tropea 2022-09-05 09:07:08 -03:00
parent d5a15758a8
commit 01536726a1
7 changed files with 128 additions and 24 deletions

View File

@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- New output to compute differences between PCBs and SCHs.(INTI-CMNB/KiAuto#14)
- New outputs:
- Diff: to compute differences between PCBs and SCHs. (INTI-CMNB/KiAuto#14)
- Info: collects info about the environment. (See #209)
- Try to download missing tools and Python modules.
The user also gets more information when something is missing.
It can be disabled from the command line.

View File

@ -1507,6 +1507,8 @@ Notes:
git hashes involved in the comparison. If you plan to compress the output don't
forget to disable the `follow_links` option.
- `cache_dir`: [string=''] Directory to cache the intermediate files. Leave it blank to disable the cache.
- `copy_instead_of_link`: [boolean=false] When `add_link_id` is enabled creates a copy of the file instead of a symlink.
Useful for some Windows setups.
- `diff_mode`: [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
The `stats` mode is used to meassure the amount of difference. In this mode all
changes are red, but you can abort if the difference is bigger than certain threshold.
@ -1927,6 +1929,32 @@ Notes:
Internally we use 10 for low priority, 90 for high priority and 50 for most outputs.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Info
* Type: `info`
* Description: Records information about the current run.
It can be used to know more about the environment used to generate the files.
Please don't rely on the way things are reported, its content could change,
adding or removing information.
It current shows the `kibot-check` output
* Valid keys:
- **`comment`**: [string=''] A comment for documentation purposes.
- **`dir`**: [string='./'] Output directory for the generated files.
If it starts with `+` the rest is concatenated to the default dir.
- **`name`**: [string=''] Used to identify this particular output definition.
- **`options`**: [dict] Options for the `info` output.
* Valid keys:
- **`output`**: [string='%f-%i%I%v.%x'] Filename for the output (%i=info, %x=txt). Affected by global options.
- `category`: [string|list(string)=''] The category for this output. If not specified an internally defined category is used.
Categories looks like file system paths, i.e. PCB/fabrication/gerber.
- `disable_run_by_default`: [string|boolean] Use it to disable the `run_by_default` status of other output.
Useful when this output extends another and you don't want to generate the original.
Use the boolean true value to disable the output you are extending.
- `extends`: [string=''] Copy the `options` section from the indicated output.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first.
Internally we use 10 for low priority, 90 for high priority and 50 for most outputs.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* KiBoM (KiCad Bill of Materials)
* Type: `kibom`
* Description: Used to generate the BoM in HTML or CSV format using the KiBoM plug-in.

View File

@ -421,6 +421,9 @@ outputs:
add_link_id: false
# [string=''] Directory to cache the intermediate files. Leave it blank to disable the cache
cache_dir: ''
# [boolean=false] When `add_link_id` is enabled creates a copy of the file instead of a symlink.
# Useful for some Windows setups
copy_instead_of_link: false
# [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
# The `stats` mode is used to meassure the amount of difference. In this mode all
# changes are red, but you can abort if the difference is bigger than certain threshold
@ -838,6 +841,18 @@ outputs:
# [string=''] List of board variants to include in the BOM.
# IBoM option, avoid using in conjunction with KiBot variants/filters
variants_whitelist: ''
# Info:
# It can be used to know more about the environment used to generate the files.
# Please don't rely on the way things are reported, its content could change,
# adding or removing information.
# It current shows the `kibot-check` output
- name: 'info_example'
comment: 'Records information about the current run.'
type: 'info'
dir: 'Example/info_dir'
options:
# [string='%f-%i%I%v.%x'] Filename for the output (%i=info, %x=txt). Affected by global options
output: '%f-%i%I%v.%x'
# KiBoM (KiCad Bill of Materials):
# For more information: https://github.com/INTI-CMNB/KiBoM
# Note that this output is provided as a compatibility tool.

View File

@ -15,7 +15,7 @@ from sys import exit
from sys import path as sys_path
import shlex
from shutil import which
from subprocess import run, PIPE, Popen
from subprocess import run, PIPE, STDOUT, Popen, CalledProcessError
from glob import glob
from importlib.util import spec_from_file_location, module_from_spec
from collections import OrderedDict
@ -25,7 +25,7 @@ from .registrable import RegOutput
from .misc import (PLOT_ERROR, CORRUPTED_PCB, EXIT_BAD_ARGS, CORRUPTED_SCH, version_str2tuple,
EXIT_BAD_CONFIG, WRONG_INSTALL, UI_SMD, UI_VIRTUAL, TRY_INSTALL_CHECK, MOD_SMD, MOD_THROUGH_HOLE,
MOD_VIRTUAL, W_PCBNOSCH, W_NONEEDSKIP, W_WRONGCHAR, name2make, W_TIMEOUT, W_KIAUTO, W_VARSCH,
NO_SCH_FILE, NO_PCB_FILE, W_VARPCB, NO_YAML_MODULE, WRONG_ARGUMENTS)
NO_SCH_FILE, NO_PCB_FILE, W_VARPCB, NO_YAML_MODULE, WRONG_ARGUMENTS, FAILED_EXECUTE)
from .error import PlotError, KiPlotConfigurationError, config_error, trace_dump
from .config_reader import CfgYamlReader
from .pre_base import BasePreFlight
@ -139,6 +139,23 @@ def extract_errors(text):
logger.warning(W_KIAUTO+msg.rstrip())
def debug_output(res):
if res.stdout:
logger.debug('- Output from command: '+res.stdout.decode())
def run_command(command, change_to=None):
logger.debug('Executing: '+shlex.join(command))
try:
res = run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to)
except CalledProcessError as e:
logger.error('Running {} returned {}'.format(e.cmd, e.returncode))
debug_output(e)
exit(FAILED_EXECUTE)
debug_output(res)
return res.stdout.decode().rstrip()
def exec_with_retry(cmd):
cmd_str = shlex.join(cmd)
logger.debug('Executing: '+cmd_str)

View File

@ -21,15 +21,12 @@ Dependencies:
"""
from hashlib import sha1
import os
import shlex
from shutil import rmtree, copy2
from subprocess import run, CalledProcessError, STDOUT, PIPE
from tempfile import mkdtemp, NamedTemporaryFile
from .error import KiPlotConfigurationError
from .gs import GS
from .kiplot import load_any_sch
from .kiplot import load_any_sch, run_command
from .layer import Layer
from .misc import FAILED_EXECUTE
from .optionable import BaseOptions
from .macros import macros, document, output_class # noqa: F401
from . import log
@ -38,23 +35,6 @@ logger = log.get_logger()
STASH_MSG = 'KiBot_Changes_Entry'
def debug_output(res):
if res.stdout:
logger.debug('- Output from command: '+res.stdout.decode())
def run_command(command, change_to=None):
logger.debug('Executing: '+shlex.join(command))
try:
res = run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to)
except CalledProcessError as e:
logger.error('Running {} returned {}'.format(e.cmd, e.returncode))
debug_output(e)
exit(FAILED_EXECUTE)
debug_output(res)
return res.stdout.decode().rstrip()
class DiffOptions(BaseOptions):
def __init__(self):
with document:

54
kibot/out_info.py Normal file
View File

@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2022 Salvador E. Tropea
# Copyright (c) 2022 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
import os
import sys
from .gs import GS
from .optionable import BaseOptions
from .kiplot import run_command
from .macros import macros, document, output_class # noqa: F401
from . import log
logger = log.get_logger()
class InfoOptions(BaseOptions):
def __init__(self):
with document:
self.output = GS.def_global_output
""" *Filename for the output (%i=info, %x=txt) """
super().__init__()
self._expand_id = 'info'
self._expand_ext = 'txt'
self._none_related = True
def get_targets(self, out_dir):
return [self._parent.expand_filename(out_dir, self.output)]
def run(self, name):
dir = os.path.dirname(os.path.abspath(sys.argv[0]))
ret = run_command([os.path.join(dir, 'kibot-check')])
with open(name, 'wt') as f:
f.write(ret+'\n')
@output_class
class Info(BaseOutput): # noqa: F821
""" Info
Records information about the current run.
It can be used to know more about the environment used to generate the files.
Please don't rely on the way things are reported, its content could change,
adding or removing information.
It current shows the `kibot-check` output """
def __init__(self):
super().__init__()
self._category = ['PCB/docs', 'Schematic/docs']
with document:
self.options = InfoOptions
""" *[dict] Options for the `info` output """
@staticmethod
def get_conf_examples(name, layers, templates):
return BaseOutput.simple_conf_examples(name, 'Information about the run', '.') # noqa: F821

View File

@ -0,0 +1,8 @@
# Example KiBot config file
kibot:
version: 1
outputs:
- name: 'do_info'
comment: "Information about the run"
type: info