[Windows][Fixed] Avoid asuming bash is part of the system

Related to #325
This commit is contained in:
Salvador E. Tropea 2022-12-22 08:44:46 -03:00
parent c1f7b8dcff
commit 11773e920d
7 changed files with 71 additions and 2 deletions

View File

@ -206,6 +206,12 @@ Notes:
- Create PDF, PNG, PS and EPS formats for `pcb_print`
- Create PNG, JPG and BMP images for `pcbdraw`
[**Bash**](https://www.gnu.org/software/bash/) [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://www.gnu.org/software/bash/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/bash)
- Optional to:
- Run external commands to create replacement text for `pcb_replace`
- Run external commands to create replacement text for `sch_replace`
- Run external commands to create replacement text for `set_text_variables`
[**Ghostscript**](https://www.ghostscript.com/) [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://www.ghostscript.com/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/ghostscript) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png)
- Optional to:
- Create outputs preview for `navigate_results`

View File

@ -84,6 +84,10 @@ Dependencies:
debian: xvfb
arch: xorg-server-xvfb
no_cmd_line_version: true
- name: Bash
url: https://www.gnu.org/software/bash/
debian: bash
arch: bash
"""
import importlib
import os

View File

@ -93,6 +93,7 @@ class Base_Replace(BasePreFlight): # noqa: F821
content = f.read()
os.environ['KIBOT_' + type(self)._context + '_NAME'] = file
o = self._value
bash_command = None
for r in o.replace_tags:
text = r.text
if not text:
@ -100,7 +101,9 @@ class Base_Replace(BasePreFlight): # noqa: F821
if re_git.search(command):
git_command = self.ensure_tool('git')
command = re_git.sub(r'\1'+git_command+' ', command)
cmd = ['/bin/bash', '-c', command]
if not bash_command:
bash_command = self.ensure_tool('Bash')
cmd = [bash_command, '-c', command]
logger.debugl(2, 'Running: {}'.format(cmd))
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
if result.returncode:

View File

@ -7,6 +7,8 @@
Dependencies:
- from: Git
role: Find commit hash and/or date
- from: Bash
role: Run external commands to create replacement text
"""
from .gs import GS
from .pre_any_replace import TagReplaceBase, Base_ReplaceOptions, Base_Replace

View File

@ -7,6 +7,8 @@
Dependencies:
- from: Git
role: Find commit hash and/or date
- from: Bash
role: Run external commands to create replacement text
"""
import os
from .gs import GS

View File

@ -7,6 +7,8 @@
Dependencies:
- from: Git
role: Find commit hash and/or date
- from: Bash
role: Run external commands to create replacement text
"""
import json
import os
@ -114,6 +116,7 @@ class Set_Text_Variables(BasePreFlight): # noqa: F821
os.environ['KIBOT_PCB_NAME'] = GS.pcb_file
if GS.sch_file:
os.environ['KIBOT_SCH_NAME'] = GS.sch_file
bash_command = None
for r in o:
text = r.text
if not text and r.command:
@ -121,7 +124,9 @@ class Set_Text_Variables(BasePreFlight): # noqa: F821
if re_git.search(command):
git_command = self.ensure_tool('git')
command = re_git.sub(r'\1'+git_command.replace('\\', r'\\')+' ', command)
cmd = ['/bin/bash', '-c', command]
if not bash_command:
bash_command = self.ensure_tool('Bash')
cmd = [bash_command, '-c', command]
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
if result.returncode:
logger.error('Failed to execute:\n{}\nreturn code {}'.format(r.command, result.returncode))

View File

@ -19,6 +19,53 @@ import subprocess
import sys
deps = '{\
"Bash": {\
"arch": "bash",\
"command": "bash",\
"comments": [],\
"deb_package": "bash",\
"downloader": null,\
"downloader_str": null,\
"extra_arch": null,\
"extra_deb": null,\
"help_option": "--version",\
"importance": 3,\
"in_debian": true,\
"is_kicad_plugin": false,\
"is_python": false,\
"name": "Bash",\
"no_cmd_line_version": false,\
"no_cmd_line_version_old": false,\
"output": "pcb_replace",\
"plugin_dirs": null,\
"pypi_name": "Bash",\
"roles": [\
{\
"desc": "Run external commands to create replacement text",\
"mandatory": false,\
"max_version": null,\
"output": "pcb_replace",\
"version": null\
},\
{\
"desc": "Run external commands to create replacement text",\
"mandatory": false,\
"max_version": null,\
"output": "sch_replace",\
"version": null\
},\
{\
"desc": "Run external commands to create replacement text",\
"mandatory": false,\
"max_version": null,\
"output": "set_text_variables",\
"version": null\
}\
],\
"tests": [],\
"url": "https://www.gnu.org/software/bash/",\
"url_down": null\
},\
"Colorama": {\
"arch": "python-colorama",\
"command": "colorama",\