[DOCs] Added examples and warnings about spaces in names

- For the replace pre-flights

Related to #366
This commit is contained in:
Salvador E. Tropea 2023-01-17 15:40:32 -03:00
parent eb8c04f870
commit 16e61e6f23
4 changed files with 21 additions and 10 deletions

View File

@ -445,9 +445,9 @@ This section is used to specify tasks that will be executed before generating an
This preflight modifies the PCB. Even when a back-up is done use it carefully. This preflight modifies the PCB. Even when a back-up is done use it carefully.
* Valid keys: * Valid keys:
- `date_command`: [string=''] Command to get the date to use in the PCB.\ - `date_command`: [string=''] Command to get the date to use in the PCB.\
```git log -1 --format='%as' -- $KIBOT_PCB_NAME```\ ```git log -1 --format='%as' -- "$KIBOT_PCB_NAME"```\
Will return the date in YYYY-MM-DD format.\ Will return the date in YYYY-MM-DD format.\
```date -d @`git log -1 --format='%at' -- $KIBOT_PCB_NAME` +%Y-%m-%d_%H-%M-%S```\ ```date -d @`git log -1 --format='%at' -- "$KIBOT_PCB_NAME"` +%Y-%m-%d_%H-%M-%S```\
Will return the date in YYYY-MM-DD_HH-MM-SS format.\ Will return the date in YYYY-MM-DD_HH-MM-SS format.\
Important: on KiCad 6 the title block data is optional. Important: on KiCad 6 the title block data is optional.
This command will work only if you have a date in the PCB/Schematic. This command will work only if you have a date in the PCB/Schematic.
@ -472,9 +472,9 @@ This section is used to specify tasks that will be executed before generating an
This preflight modifies the schematics. Even when a back-up is done use it carefully. This preflight modifies the schematics. Even when a back-up is done use it carefully.
* Valid keys: * Valid keys:
- `date_command`: [string=''] Command to get the date to use in the SCH.\ - `date_command`: [string=''] Command to get the date to use in the SCH.\
```git log -1 --format='%as' -- $KIBOT_SCH_NAME```\ ```git log -1 --format='%as' -- "$KIBOT_SCH_NAME"```\
Will return the date in YYYY-MM-DD format.\ Will return the date in YYYY-MM-DD format.\
```date -d @`git log -1 --format='%at' -- $KIBOT_SCH_NAME` +%Y-%m-%d_%H-%M-%S```\ ```date -d @`git log -1 --format='%at' -- "$KIBOT_SCH_NAME"` +%Y-%m-%d_%H-%M-%S```\
Will return the date in YYYY-MM-DD_HH-MM-SS format.\ Will return the date in YYYY-MM-DD_HH-MM-SS format.\
Important: on KiCad 6 the title block data is optional. Important: on KiCad 6 the title block data is optional.
This command will work only if you have a date in the SCH/Schematic. This command will work only if you have a date in the SCH/Schematic.
@ -497,6 +497,10 @@ This section is used to specify tasks that will be executed before generating an
- `after`: [string=''] Text to add after the output of `command`. - `after`: [string=''] Text to add after the output of `command`.
- `before`: [string=''] Text to add before the output of `command`. - `before`: [string=''] Text to add before the output of `command`.
- `command`: [string=''] Command to execute to get the text, will be used only if `text` is empty. - `command`: [string=''] Command to execute to get the text, will be used only if `text` is empty.
This command will be executed using the Bash shell.
Be careful about spaces in file names (i.e. use "$KIBOT_PCB_NAME").
The `KIBOT_PCB_NAME` environment variable is the PCB file and the
`KIBOT_SCH_NAME` environment variable is the schematic file.
- `expand_kibot_patterns`: [boolean=true] Expand %X patterns. The context is `schematic`. - `expand_kibot_patterns`: [boolean=true] Expand %X patterns. The context is `schematic`.
- `name`: [string=''] Name of the variable. The `version` variable will be expanded using `${version}`. - `name`: [string=''] Name of the variable. The `version` variable will be expanded using `${version}`.
- `text`: [string=''] Text to insert instead of the variable. - `text`: [string=''] Text to insert instead of the variable.

View File

@ -75,7 +75,7 @@ preflight:
# The KiCad project file is modified. # The KiCad project file is modified.
set_text_variables: set_text_variables:
- name: 'git_hash' - name: 'git_hash'
command: 'git log -1 --format="%h" $KIBOT_PCB_NAME' command: 'git log -1 --format="%h" "$KIBOT_PCB_NAME"'
before: 'Git hash: <' before: 'Git hash: <'
after: '>' after: '>'
# [boolean=false] Update the QR codes. # [boolean=false] Update the QR codes.

View File

@ -54,9 +54,9 @@ class Base_ReplaceOptions(Optionable):
with document: with document:
self.date_command = '' self.date_command = ''
""" Command to get the date to use in the PCB.\\ """ Command to get the date to use in the PCB.\\
```git log -1 --format='%as' -- $KIBOT_PCB_NAME```\\ ```git log -1 --format='%as' -- \"$KIBOT_PCB_NAME\"```\\
Will return the date in YYYY-MM-DD format.\\ Will return the date in YYYY-MM-DD format.\\
```date -d @`git log -1 --format='%at' -- $KIBOT_PCB_NAME` +%Y-%m-%d_%H-%M-%S```\\ ```date -d @`git log -1 --format='%at' -- \"$KIBOT_PCB_NAME\"` +%Y-%m-%d_%H-%M-%S```\\
Will return the date in YYYY-MM-DD_HH-MM-SS format.\\ Will return the date in YYYY-MM-DD_HH-MM-SS format.\\
Important: on KiCad 6 the title block data is optional. Important: on KiCad 6 the title block data is optional.
This command will work only if you have a date in the PCB/Schematic """ This command will work only if you have a date in the PCB/Schematic """

View File

@ -41,7 +41,11 @@ class KiCadVariable(Optionable):
self.text = '' self.text = ''
""" Text to insert instead of the variable """ """ Text to insert instead of the variable """
self.command = '' self.command = ''
""" Command to execute to get the text, will be used only if `text` is empty """ """ Command to execute to get the text, will be used only if `text` is empty.
This command will be executed using the Bash shell.
Be careful about spaces in file names (i.e. use "$KIBOT_PCB_NAME").
The `KIBOT_PCB_NAME` environment variable is the PCB file and the
`KIBOT_SCH_NAME` environment variable is the schematic file """
self.before = '' self.before = ''
""" Text to add before the output of `command` """ """ Text to add before the output of `command` """
self.after = '' self.after = ''
@ -91,7 +95,7 @@ class Set_Text_Variables(BasePreFlight): # noqa: F821
def get_example(cls): def get_example(cls):
""" Returns a YAML value for the example config """ """ Returns a YAML value for the example config """
return ("\n - name: 'git_hash'" return ("\n - name: 'git_hash'"
"\n command: 'git log -1 --format=\"%h\" $KIBOT_PCB_NAME'" "\n command: 'git log -1 --format=\"%h\" \"$KIBOT_PCB_NAME\"'"
"\n before: 'Git hash: <'" "\n before: 'Git hash: <'"
"\n after: '>'") "\n after: '>'")
@ -132,7 +136,10 @@ class Set_Text_Variables(BasePreFlight): # noqa: F821
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
if result.returncode: if result.returncode:
logger.error('Failed to execute:\n{}\nreturn code {}'.format(r.command, result.returncode)) logger.error('Failed to execute:\n{}\nreturn code {}'.format(r.command, result.returncode))
logger.error('stdout:\n{}\nstderr:\n{}'.format(result.stdout, result.stderr)) if result.stdout:
logger.error('stdout:\n{}'.format(result.stdout))
if result.stderr:
logger.error('stderr:\n{}'.format(result.stderr))
sys.exit(FAILED_EXECUTE) sys.exit(FAILED_EXECUTE)
if not result.stdout: if not result.stdout:
logger.warning(W_EMPTREP+"Empty value from `{}`".format(r.command)) logger.warning(W_EMPTREP+"Empty value from `{}`".format(r.command))