Added a mechanism to set a default variant for all outputs.
It can be used to overwrite the output file template too.
This commit is contained in:
parent
709d6facb9
commit
512776ce8e
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
Usage:
|
||||
kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE]
|
||||
[-q | -v...] [-i] [TARGET...]
|
||||
[-q | -v...] [-i] [-g DEF]... [TARGET...]
|
||||
kibot [-v...] [-c PLOT_CONFIG] --list
|
||||
kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] --example
|
||||
kibot [-v...] --help-list-outputs
|
||||
|
|
@ -28,6 +28,7 @@ Options:
|
|||
-c CONFIG, --plot-config CONFIG The plotting config file to use
|
||||
-d OUT_DIR, --out-dir OUT_DIR The output directory [default: .]
|
||||
-e SCHEMA, --schematic SCHEMA The schematic file (.sch)
|
||||
-g DEF, --global-redef DEF Overwrite a global value (VAR=VAL)
|
||||
--help-list-outputs List supported outputs
|
||||
--help-output HELP_OUTPUT Help for this particular output
|
||||
--help-outputs List supported outputs and details
|
||||
|
|
@ -257,6 +258,14 @@ def main():
|
|||
GS.debug_enabled = logger.getEffectiveLevel() <= DEBUG
|
||||
GS.debug_level = args.verbose
|
||||
|
||||
# Parse global overwrite options
|
||||
for redef in args.global_redef:
|
||||
if '=' not in redef:
|
||||
logger.error('Malformed global-redef option, must be VARIABLE=VALUE ({})'.format(redef))
|
||||
sys.exit(EXIT_BAD_ARGS)
|
||||
var = redef.split('=')[0]
|
||||
GS.global_from_cli[var] = redef[len(var)+1:]
|
||||
|
||||
clean_cache()
|
||||
|
||||
# Output dir: relative to CWD (absolute path overrides)
|
||||
|
|
|
|||
|
|
@ -150,17 +150,27 @@ class CfgYamlReader(object):
|
|||
config_error("In preflight '"+k+"': "+str(e))
|
||||
BasePreFlight.add_preflight(o_pre)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _parse_global_str(k, v, current):
|
||||
if not isinstance(v, str):
|
||||
config_error("Global `{}` must be a string".format(k))
|
||||
if current:
|
||||
logger.info('Using command line value `{}` for global option `{}`'.format(current, k))
|
||||
return current
|
||||
return v
|
||||
|
||||
def _parse_global(self, gb):
|
||||
""" Get global options """
|
||||
logger.debug("Parsing global options: {}".format(gb))
|
||||
if not isinstance(gb, dict):
|
||||
config_error("Incorrect `global` section")
|
||||
|
||||
# Parse all keys inside it
|
||||
for k, v in gb.items():
|
||||
if k == 'output':
|
||||
if not isinstance(v, str):
|
||||
config_error("Global `output` must be a string")
|
||||
GS.global_output = v
|
||||
GS.global_output = self._parse_global_str(k, v, GS.global_output)
|
||||
elif k == 'variant':
|
||||
GS.global_variant = self._parse_global_str(k, v, GS.global_variant)
|
||||
else:
|
||||
logger.warning("Unknown global option `{}`".format(k))
|
||||
|
||||
|
|
@ -174,6 +184,9 @@ class CfgYamlReader(object):
|
|||
data = yaml.safe_load(fstream)
|
||||
except yaml.YAMLError as e:
|
||||
config_error("Error loading YAML "+str(e))
|
||||
# Transfer command line global overwrites
|
||||
GS.global_output = GS.global_from_cli.get('output', None)
|
||||
GS.global_variant = GS.global_from_cli.get('variant', None)
|
||||
# List of outputs
|
||||
outputs = []
|
||||
version = None
|
||||
|
|
|
|||
10
kibot/gs.py
10
kibot/gs.py
|
|
@ -22,12 +22,12 @@ class GS(object):
|
|||
pcb_file = None # /.../dir/pcb.kicad_pcb
|
||||
pcb_no_ext = None # /.../dir/pcb
|
||||
pcb_dir = None # /.../dir
|
||||
pcb_basename = None # file
|
||||
pcb_basename = None # pcb
|
||||
# SCH name and useful parts
|
||||
sch_file = None # /.../dir/file.sch
|
||||
sch_basename = None # /.../dir/file
|
||||
sch_no_ext = None # /.../dir
|
||||
sch_dir = None # pcb
|
||||
sch_no_ext = None # /.../dir/file
|
||||
sch_dir = None # /.../dir
|
||||
sch_basename = None # file
|
||||
# Main output dir
|
||||
out_dir = None
|
||||
filter_file = None
|
||||
|
|
@ -56,7 +56,9 @@ class GS(object):
|
|||
# This value will overwrite GS.def_global_output if defined
|
||||
# Classes supporting global "output" option must call super().__init__()
|
||||
# after defining its own options to allow Optionable do the overwrite.
|
||||
global_from_cli = {}
|
||||
global_output = None
|
||||
global_variant = None
|
||||
|
||||
@staticmethod
|
||||
def set_sch(name):
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ class Optionable(object):
|
|||
super().__init__()
|
||||
if GS.global_output is not None and getattr(self, 'output', None):
|
||||
setattr(self, 'output', GS.global_output)
|
||||
if GS.global_variant is not None and hasattr(self, 'variant'):
|
||||
setattr(self, 'variant', GS.global_variant)
|
||||
|
||||
@staticmethod
|
||||
def _check_str(key, val, doc):
|
||||
|
|
|
|||
|
|
@ -74,13 +74,13 @@ class BoMRegex(Optionable):
|
|||
class VariantOptions(BaseOptions):
|
||||
""" BaseOptions plus generic support for variants. """
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
with document:
|
||||
self.variant = ''
|
||||
""" Board variant to apply """
|
||||
self.dnf_filter = Optionable
|
||||
""" [string|list(string)=''] Name of the filter to mark components as not fitted.
|
||||
A short-cut to use for simple cases where a variant is an overkill """
|
||||
super().__init__()
|
||||
self._comps = None
|
||||
|
||||
def config(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue