Added aliases for options.
The test case is the pdf_pcb_print.output_name, which is different than other *.output options. Now output_name is an alias for output.
This commit is contained in:
parent
ba88f49383
commit
9fdc02ecea
|
|
@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- pdf_pcb_print.output can be used instead of pdf_pcb_print.output_name
|
||||
|
||||
## [0.5.0] - 2020-07-11
|
||||
### Changed
|
||||
|
|
|
|||
|
|
@ -572,7 +572,8 @@ Next time you need this list just use an alias, like this:
|
|||
- `name`: [string=''] Used to identify this particular output definition.
|
||||
- `options`: [dict] Options for the `pdf_pcb_print` output.
|
||||
* Valid keys:
|
||||
- `output_name`: [string=''] filename for the output PDF (the name of the PCB if empty).
|
||||
- `output`: [string='%f.pdf'] filename for the output PDF.
|
||||
- *output_name*: Alias for output.
|
||||
|
||||
* PDF Schematic Print (Portable Document Format)
|
||||
* Type: `pdf_sch_print`
|
||||
|
|
|
|||
|
|
@ -363,8 +363,9 @@ outputs:
|
|||
type: 'pdf_pcb_print'
|
||||
dir: 'Example/pdf_pcb_print_dir'
|
||||
options:
|
||||
# [string=''] filename for the output PDF (the name of the PCB if empty)
|
||||
output_name: ''
|
||||
# [string='%f.pdf'] filename for the output PDF
|
||||
output: '%f.pdf'
|
||||
# `output_name` is an alias for `output`
|
||||
layers: all
|
||||
|
||||
# PDF Schematic Print (Portable Document Format):
|
||||
|
|
|
|||
|
|
@ -183,11 +183,16 @@ def print_output_options(name, cl, indent):
|
|||
if not num_opts:
|
||||
# We found one, put the title
|
||||
print(ind_str+'* Valid keys:')
|
||||
help = getattr(obj, '_help_'+k)
|
||||
help, alias, is_alias = obj.get_doc(k)
|
||||
if is_alias:
|
||||
help = 'Alias for '+alias
|
||||
entry = ' - *{}*: '
|
||||
else:
|
||||
entry = ' - `{}`: '
|
||||
if help is None:
|
||||
help = 'Undocumented' # pragma: no cover
|
||||
lines = help.split('\n')
|
||||
preface = ind_str+' - `{}`: '.format(k)
|
||||
preface = ind_str+entry.format(k)
|
||||
clines = len(lines)
|
||||
print('{}{}{}'.format(preface, lines[0].strip(), '.' if clines == 1 else ''))
|
||||
ind_help = len(preface)*' '
|
||||
|
|
@ -249,7 +254,10 @@ def print_example_options(f, cls, name, indent, po):
|
|||
if po:
|
||||
obj.read_vals_from_po(po)
|
||||
for k, v in obj.get_attrs_gen():
|
||||
help = getattr(obj, '_help_'+k)
|
||||
help, alias, is_alias = obj.get_doc(k)
|
||||
if is_alias:
|
||||
f.write(ind_str+'# `{}` is an alias for `{}`\n'.format(k, alias))
|
||||
continue
|
||||
if help:
|
||||
help_lines = help.split('\n')
|
||||
for hl in help_lines:
|
||||
|
|
|
|||
|
|
@ -52,6 +52,13 @@ class Optionable(object):
|
|||
if not isinstance(val, bool):
|
||||
raise KiPlotConfigurationError("Option `{}` must be true/false".format(key))
|
||||
|
||||
def get_doc(self, name):
|
||||
doc = getattr(self, '_help_'+name).strip()
|
||||
if doc[0] == '{':
|
||||
alias = doc[1:-1]
|
||||
return getattr(self, '_help_'+alias).strip(), alias, True
|
||||
return doc, name, False
|
||||
|
||||
@staticmethod
|
||||
def _typeof(v):
|
||||
if isinstance(v, bool):
|
||||
|
|
@ -77,8 +84,8 @@ class Optionable(object):
|
|||
logger.warning("Unknown option `{}`".format(k))
|
||||
continue
|
||||
# Check the data type
|
||||
cur_val = getattr(self, k)
|
||||
cur_doc = getattr(self, '_help_'+k).lstrip()
|
||||
cur_doc, alias, is_alias = self.get_doc(k)
|
||||
cur_val = getattr(self, alias)
|
||||
if isinstance(cur_val, bool):
|
||||
Optionable._check_bool(k, v)
|
||||
elif isinstance(cur_val, (int, float)):
|
||||
|
|
@ -126,7 +133,7 @@ class Optionable(object):
|
|||
new_val.append(element)
|
||||
v = new_val
|
||||
# Seems to be ok, map it
|
||||
setattr(self, k, v)
|
||||
setattr(self, alias if is_alias else k, v)
|
||||
|
||||
def config(self, tree):
|
||||
self._tree = tree
|
||||
|
|
|
|||
|
|
@ -17,16 +17,15 @@ class PDF_Pcb_PrintOptions(BaseOptions):
|
|||
def __init__(self):
|
||||
super().__init__()
|
||||
with document:
|
||||
self.output_name = ''
|
||||
""" filename for the output PDF (the name of the PCB if empty) """ # pragma: no cover
|
||||
self.output = '%f.pdf'
|
||||
""" filename for the output PDF """
|
||||
self.output_name = None
|
||||
""" {output} """ # pragma: no cover
|
||||
|
||||
def run(self, output_dir, board, layers):
|
||||
check_script(CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, '1.4.1')
|
||||
# Output file name
|
||||
output = self.output_name
|
||||
if not output:
|
||||
output = os.path.splitext(os.path.basename(GS.pcb_file))[0]+'.pdf'
|
||||
output = os.path.abspath(os.path.join(output_dir, output))
|
||||
output = os.path.abspath(os.path.join(output_dir, self.expand_filename(self.output)))
|
||||
cmd = [CMD_PCBNEW_PRINT_LAYERS, 'export', '--output_name', output]
|
||||
if BasePreFlight.get_option('check_zone_fills'):
|
||||
cmd.append('-f')
|
||||
|
|
|
|||
Loading…
Reference in New Issue