Now you can import outputs from another config file.
This commit is contained in:
parent
befbcc3fe3
commit
3ed25cc5ff
|
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Support for ZIP/TAR/RAR generation.
|
- Support for ZIP/TAR/RAR generation.
|
||||||
- Makefile generation.
|
- Makefile generation.
|
||||||
- KiAuto time-out control.
|
- KiAuto time-out control.
|
||||||
|
- Now you can import outputs from another config file.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Now the default output name applies to the DRC and ERC report names.
|
- Now the default output name applies to the DRC and ERC report names.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from collections import OrderedDict
|
||||||
|
|
||||||
from .error import (KiPlotConfigurationError, config_error)
|
from .error import (KiPlotConfigurationError, config_error)
|
||||||
from .kiplot import (load_board)
|
from .kiplot import (load_board)
|
||||||
from .misc import (NO_YAML_MODULE, EXIT_BAD_ARGS, EXAMPLE_CFG, WONT_OVERWRITE)
|
from .misc import (NO_YAML_MODULE, EXIT_BAD_ARGS, EXAMPLE_CFG, WONT_OVERWRITE, W_NOOUTPUTS)
|
||||||
from .gs import GS
|
from .gs import GS
|
||||||
from .registrable import RegOutput, RegVariant, RegFilter
|
from .registrable import RegOutput, RegVariant, RegFilter
|
||||||
from .pre_base import BasePreFlight
|
from .pre_base import BasePreFlight
|
||||||
|
|
@ -162,7 +162,7 @@ class CfgYamlReader(object):
|
||||||
""" Get global options """
|
""" Get global options """
|
||||||
logger.debug("Parsing global options: {}".format(gb))
|
logger.debug("Parsing global options: {}".format(gb))
|
||||||
if not isinstance(gb, dict):
|
if not isinstance(gb, dict):
|
||||||
config_error("Incorrect `global` section")
|
config_error("Incorrect `global` section (must be a dict)")
|
||||||
# Parse all keys inside it
|
# Parse all keys inside it
|
||||||
glb = GS.global_opts_class()
|
glb = GS.global_opts_class()
|
||||||
glb.set_tree(gb)
|
glb.set_tree(gb)
|
||||||
|
|
@ -171,16 +171,44 @@ class CfgYamlReader(object):
|
||||||
except KiPlotConfigurationError as e:
|
except KiPlotConfigurationError as e:
|
||||||
config_error("In `global` section: "+str(e))
|
config_error("In `global` section: "+str(e))
|
||||||
|
|
||||||
|
def _parse_import(self, imp, name):
|
||||||
|
""" Get imports """
|
||||||
|
logger.debug("Parsing imports: {}".format(imp))
|
||||||
|
if not isinstance(imp, list):
|
||||||
|
config_error("Incorrect `import` section (must be a list)")
|
||||||
|
# Import the files
|
||||||
|
dir = os.path.dirname(os.path.abspath(name))
|
||||||
|
outputs = []
|
||||||
|
for fn in imp:
|
||||||
|
if not isinstance(fn, str):
|
||||||
|
config_error("`import` items must be strings ({})".format(str(fn)))
|
||||||
|
if not os.path.isabs(fn):
|
||||||
|
fn = os.path.join(dir, fn)
|
||||||
|
if not os.path.isfile(fn):
|
||||||
|
config_error("missing import file `{}`".format(fn))
|
||||||
|
data = self.load_yaml(open(fn))
|
||||||
|
if 'outputs' in data:
|
||||||
|
outs = self._parse_outputs(data['outputs'])
|
||||||
|
outputs.extend(outs)
|
||||||
|
logger.debug('Outputs loaded from `{}`: {}'.format(os.path.relpath(fn), list(map(lambda c: c.name, outs))))
|
||||||
|
else:
|
||||||
|
logger.warning(W_NOOUTPUTS+" No outputs found in `{}`".format(fn))
|
||||||
|
return outputs
|
||||||
|
|
||||||
|
def load_yaml(self, fstream):
|
||||||
|
try:
|
||||||
|
data = yaml.safe_load(fstream)
|
||||||
|
except yaml.YAMLError as e:
|
||||||
|
config_error("Error loading YAML "+str(e))
|
||||||
|
return data
|
||||||
|
|
||||||
def read(self, fstream):
|
def read(self, fstream):
|
||||||
"""
|
"""
|
||||||
Read a file object into a config object
|
Read a file object into a config object
|
||||||
|
|
||||||
:param fstream: file stream of a config YAML file
|
:param fstream: file stream of a config YAML file
|
||||||
"""
|
"""
|
||||||
try:
|
data = self.load_yaml(fstream)
|
||||||
data = yaml.safe_load(fstream)
|
|
||||||
except yaml.YAMLError as e:
|
|
||||||
config_error("Error loading YAML "+str(e))
|
|
||||||
# Transfer command line global overwrites
|
# Transfer command line global overwrites
|
||||||
GS.global_output = GS.global_from_cli.get('output', None)
|
GS.global_output = GS.global_from_cli.get('output', None)
|
||||||
GS.global_variant = GS.global_from_cli.get('variant', None)
|
GS.global_variant = GS.global_from_cli.get('variant', None)
|
||||||
|
|
@ -198,12 +226,14 @@ class CfgYamlReader(object):
|
||||||
self._parse_preflight(v)
|
self._parse_preflight(v)
|
||||||
elif k == 'global':
|
elif k == 'global':
|
||||||
self._parse_global(v)
|
self._parse_global(v)
|
||||||
|
elif k == 'import':
|
||||||
|
outputs.extend(self._parse_import(v, fstream.name))
|
||||||
elif k == 'variants':
|
elif k == 'variants':
|
||||||
RegOutput.set_variants(self._parse_variants(v))
|
RegOutput.set_variants(self._parse_variants(v))
|
||||||
elif k == 'filters':
|
elif k == 'filters':
|
||||||
RegOutput.set_filters(self._parse_filters(v))
|
RegOutput.set_filters(self._parse_filters(v))
|
||||||
elif k == 'outputs':
|
elif k == 'outputs':
|
||||||
outputs = self._parse_outputs(v)
|
outputs.extend(self._parse_outputs(v))
|
||||||
else:
|
else:
|
||||||
config_error('Unknown section `{}` in config.'.format(k))
|
config_error('Unknown section `{}` in config.'.format(k))
|
||||||
if version is None:
|
if version is None:
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ W_NOKIVER = '(W052) '
|
||||||
W_EXTNAME = '(W053) '
|
W_EXTNAME = '(W053) '
|
||||||
W_TIMEOUT = '(W054) '
|
W_TIMEOUT = '(W054) '
|
||||||
W_MUSTBEINT = '(W055) '
|
W_MUSTBEINT = '(W055) '
|
||||||
|
W_NOOUTPUTS = '(W056) '
|
||||||
|
|
||||||
|
|
||||||
class Rect(object):
|
class Rect(object):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue