From 998754753d2af7dc6d31b47cd8382758d70c5f0b Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 15 Nov 2021 14:40:30 -0300 Subject: [PATCH] Added Default global `dir` option --- CHANGELOG.md | 1 + README.md | 57 +++++++++++++++++----------- docs/README.in | 11 +++++- docs/samples/generic_plot.kibot.yaml | 4 +- kibot/config_reader.py | 1 + kibot/globals.py | 3 ++ kibot/gs.py | 1 + kibot/out_base.py | 6 ++- kibot/out_bom.py | 3 +- 9 files changed, 60 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06f229c0..a2516186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 space. This helps for cases like "10K 1%". - Generic filter: options to match if a field is/isn't defined. - Excellon drill: added `route_mode_for_oval_holes` option. +- Default global `dir` option. ### Changed - Internal BoM: now components with different Tolerance, Voltage, Current diff --git a/README.md b/README.md index 160e68a8..38eaeadc 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ KiCad 6 uses strings to differentiate errors, use them for the `error` field. To ### Default global options The section `global` contains default global options that affects all the outputs. -Currently only one option is supported. +Currently only a few option are supported. #### Default *output* option @@ -218,6 +218,15 @@ global: output: '%f_rev_%r-%i.%x' ``` +#### Default *dir* option + +The default `dir` value for any output is `.`. You can change it here. + +Expansion patterns are allowed. + +Note that you can use this value as a base for output's `dir` options. In this case the value defined in the `output` must start with `+`. +In this case the `+` is replaced by the default `dir` value defined here. + #### Default *variant* option This option controls the default variant applied to all the outputs. Example: @@ -624,7 +633,7 @@ Next time you need this list just use an alias, like this: The output can be loaded using Open Board View (https://openboardview.org/) * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `boardview` output. * Valid keys: @@ -641,7 +650,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'Tools/Generate Bill of Materials' menu in eeschema. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `bom` output. * Valid keys: @@ -720,7 +729,8 @@ Next time you need this list just use an alias, like this: - `merge_both_blank`: [boolean=true] When creating groups two components with empty/missing field will be interpreted as with the same value. - `no_conflict`: [list(string)] List of fields where we tolerate conflicts. Use it to avoid undesired warnings. - By default the field indicated in `fit_field`, the field used for variants and the field `part` are excluded. + By default the field indicated in `fit_field`, the field used for variants and + the field `part` are excluded. - `no_distributors`: [string|list(string)] Exclude this distributors list. They are removed after computing `distributors`. - `normalize_locale`: [boolean=false] When normalizing values use the locale decimal point. - `normalize_values`: [boolean=false] Try to normalize the R, L and C values, producing uniform units and prefixes. @@ -754,7 +764,7 @@ Next time you need this list just use an alias, like this: This is used to generate groups of files in compressed file format. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `compress` output. * Valid keys: @@ -776,7 +786,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the File/Plot menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `layers`: [list(dict)|list(string)|string] [all,selected,copper,technical,user] List of PCB layers to plot. * Valid keys: @@ -820,7 +830,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'File/Fabrication output/Drill Files' menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `excellon` output. * Valid keys: @@ -842,6 +852,7 @@ Next time you need this list just use an alias, like this: - `filename`: [string=''] Name of the drill report. Not generated unless a name is specified. (%i='drill_report' %x='txt'). - `right_digits`: [number=0] number of digits for mantissa part of coordinates (0 is auto). + - `route_mode_for_oval_holes`: Undocumented. - `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates. - `zeros_format`: [string='DECIMAL_FORMAT'] [DECIMAL_FORMAT,SUPPRESS_LEADING,SUPPRESS_TRAILING,KEEP_ZEROS] How to handle the zeros. @@ -852,7 +863,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'File/Fabrication output/Drill Files' menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `gerb_drill` output. * Valid keys: @@ -876,7 +887,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the File/Plot menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `layers`: [list(dict)|list(string)|string] [all,selected,copper,technical,user] List of PCB layers to plot. * Valid keys: @@ -925,7 +936,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the File/Plot menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `layers`: [list(dict)|list(string)|string] [all,selected,copper,technical,user] List of PCB layers to plot. * Valid keys: @@ -971,7 +982,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the InteractiveHtmlBom plug-in (pcbnew). * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `ibom` output. * Valid keys: @@ -1033,7 +1044,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'Tools/Generate Bill of Materials' menu in eeschema. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `kibom` output. * Valid keys: @@ -1124,7 +1135,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the KiCost plug-in (eeschema). * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `kicost` output. * Valid keys: @@ -1161,7 +1172,7 @@ Next time you need this list just use an alias, like this: Can also render the components if the 2D models are available * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `pcbdraw` output. * Valid keys: @@ -1207,7 +1218,7 @@ Next time you need this list just use an alias, like this: - `content`: [string=''] Content for the report. Use ${basename} for the project name without extension. Use ${filename(LAYER)} for the file corresponding to LAYER. - `output`: [string='Custom_report.txt'] File name for the custom report. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `dnf_filter`: [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. - `drill_marks`: [string='full'] what to use to indicate the drill places, can be none, small or full (for real scale). @@ -1267,7 +1278,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'File/Print' menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `layers`: [list(dict)|list(string)|string] [all,selected,copper,technical,user] List of PCB layers to include in the PDF. * Valid keys: @@ -1297,7 +1308,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'File/Print' menu in eeschema. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `pdf_sch_print` output. * Valid keys: @@ -1313,7 +1324,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'File/Fabrication output/Footprint poistion (.pos) file' menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `position` output. * Valid keys: @@ -1338,7 +1349,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the File/Plot menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `layers`: [list(dict)|list(string)|string] [all,selected,copper,technical,user] List of PCB layers to plot. * Valid keys: @@ -1388,7 +1399,7 @@ Next time you need this list just use an alias, like this: Is just a tweaked version of the original where you can look at the results. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `sch_variant` output. * Valid keys: @@ -1403,7 +1414,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the 'File/Export/STEP' menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `step` output. * Valid keys: @@ -1427,7 +1438,7 @@ Next time you need this list just use an alias, like this: This output is what you get from the File/Plot menu in pcbnew. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `dir`: [string='.'] Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir. - `layers`: [list(dict)|list(string)|string] [all,selected,copper,technical,user] List of PCB layers to plot. * Valid keys: @@ -1469,7 +1480,7 @@ Next time you need this list just use an alias, like this: This is a format to document your schematic. * Valid keys: - `comment`: [string=''] A comment for documentation purposes. - - `dir`: [string='.'] Output directory for the generated files. + - `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 `svg_sch_print` output. * Valid keys: diff --git a/docs/README.in b/docs/README.in index dae219b7..696044ac 100644 --- a/docs/README.in +++ b/docs/README.in @@ -168,7 +168,7 @@ KiCad 6 uses strings to differentiate errors, use them for the `error` field. To ### Default global options The section `global` contains default global options that affects all the outputs. -Currently only one option is supported. +Currently only a few option are supported. #### Default *output* option @@ -197,6 +197,15 @@ global: output: '%f_rev_%r-%i.%x' ``` +#### Default *dir* option + +The default `dir` value for any output is `.`. You can change it here. + +Expansion patterns are allowed. + +Note that you can use this value as a base for output's `dir` options. In this case the value defined in the `output` must start with `+`. +In this case the `+` is replaced by the default `dir` value defined here. + #### Default *variant* option This option controls the default variant applied to all the outputs. Example: diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 7881ba1a..8b1a8ddf 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -169,7 +169,8 @@ outputs: merge_both_blank: true # [list(string)] List of fields where we tolerate conflicts. # Use it to avoid undesired warnings. - # By default the field indicated in `fit_field`, the field used for variants and the field `part` are excluded + # By default the field indicated in `fit_field`, the field used for variants and + # the field `part` are excluded no_conflict: ['Config', 'Part'] # [string|list(string)] Exclude this distributors list. They are removed after computing `distributors` no_distributors: @@ -340,6 +341,7 @@ outputs: filename: '' # [number=0] number of digits for mantissa part of coordinates (0 is auto) right_digits: 0 + route_mode_for_oval_holes: true # [boolean=false] Use the auxiliary axis as origin for coordinates use_aux_axis_as_origin: false # [string='DECIMAL_FORMAT'] [DECIMAL_FORMAT,SUPPRESS_LEADING,SUPPRESS_TRAILING,KEEP_ZEROS] How to handle the zeros diff --git a/kibot/config_reader.py b/kibot/config_reader.py index 5244a970..37683bcd 100644 --- a/kibot/config_reader.py +++ b/kibot/config_reader.py @@ -327,6 +327,7 @@ class CfgYamlReader(object): data = self.load_yaml(fstream) # Transfer command line global overwrites GS.global_output = GS.global_from_cli.get('output', None) + GS.global_dir = GS.global_from_cli.get('dir', None) GS.global_variant = GS.global_from_cli.get('variant', None) GS.global_kiauto_wait_start = GS.global_from_cli.get('kiauto_wait_start', None) GS.global_kiauto_time_out_scale = GS.global_from_cli.get('kiauto_time_out_scale', None) diff --git a/kibot/globals.py b/kibot/globals.py index d5e8e4a7..794dba71 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -17,6 +17,8 @@ class Globals(FiltersOptions): with document: self.output = '' """ Default pattern for output file names """ + self.dir = '' + """ Default pattern for the output directories """ self.variant = '' """ Default variant to apply to all outputs """ self.kiauto_wait_start = 0 @@ -40,6 +42,7 @@ class Globals(FiltersOptions): def config(self, parent): super().config(parent) GS.global_output = self.set_global(GS.global_output, self.output, 'output') + GS.global_dir = self.set_global(GS.global_dir, self.dir, 'dir') GS.global_variant = self.set_global(GS.global_variant, self.variant, 'variant') GS.global_kiauto_wait_start = self.set_global(GS.global_kiauto_wait_start, self.kiauto_wait_start, 'kiauto_wait_start') if GS.global_kiauto_wait_start and int(GS.global_kiauto_wait_start) != GS.global_kiauto_wait_start: diff --git a/kibot/gs.py b/kibot/gs.py index 4bcd45a6..2cc282bb 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -70,6 +70,7 @@ class GS(object): # after defining its own options to allow Optionable do the overwrite. global_from_cli = {} global_output = None + global_dir = None global_variant = None global_kiauto_wait_start = None global_kiauto_time_out_scale = None diff --git a/kibot/out_base.py b/kibot/out_base.py index 8ada9958..f0030588 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -30,9 +30,11 @@ class BaseOutput(RegOutput): self.type = '' """ Type of output """ self.dir = '.' - """ Output directory for the generated files """ + """ Output directory for the generated files. If it starts with `+` the rest is concatenated to the default dir """ self.comment = '' """ A comment for documentation purposes """ + if GS.global_dir: + self.dir = GS.global_dir self._sch_related = False self._unkown_is_error = True self._done = False @@ -66,6 +68,8 @@ class BaseOutput(RegOutput): def config(self, parent): super().config(parent) + if self.dir[0] == '+': + self.dir = (GS.global_dir if GS.global_dir is not None else '.') + self.dir[1:] if getattr(self, 'options', None) and isinstance(self.options, type): # No options, get the defaults self.options = self.options() diff --git a/kibot/out_bom.py b/kibot/out_bom.py index 7425778e..8ea1d691 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -295,7 +295,8 @@ class BoMOptions(BaseOptions): self.no_conflict = NoConflict """ [list(string)] List of fields where we tolerate conflicts. Use it to avoid undesired warnings. - By default the field indicated in `fit_field`, the field used for variants and the field `part` are excluded """ + By default the field indicated in `fit_field`, the field used for variants and + the field `part` are excluded """ self.aggregate = Aggregate """ [list(dict)] Add components from other projects """ self.ref_id = ''