[Dependencies] Added support for LXML download

This commit is contained in:
Salvador E. Tropea 2022-07-01 12:45:37 -03:00
parent 1f123d3f22
commit 3e331cd7a3
3 changed files with 22 additions and 14 deletions

View File

@ -136,7 +136,7 @@ Notes:
[**KiBoM**](https://github.com/INTI-CMNB/KiBoM) v1.8.0 [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://github.com/INTI-CMNB/KiBoM) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png) [**KiBoM**](https://github.com/INTI-CMNB/KiBoM) v1.8.0 [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://github.com/INTI-CMNB/KiBoM) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png)
- Mandatory for `kibom` - Mandatory for `kibom`
[**LXML**](https://pypi.org/project/LXML/) [![Python module](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/Python-logo-notext-22x22.png)](https://pypi.org/project/LXML/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/python3-lxml) [**LXML**](https://pypi.org/project/LXML/) [![Python module](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/Python-logo-notext-22x22.png)](https://pypi.org/project/LXML/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/python3-lxml) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png)
- Mandatory for `pcb_print` - Mandatory for `pcb_print`
[**QRCodeGen**](https://pypi.org/project/QRCodeGen/) [![Python module](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/Python-logo-notext-22x22.png)](https://pypi.org/project/QRCodeGen/) [![PyPi dependency](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/PyPI_logo_simplified-22x22.png)](https://pypi.org/project/QRCodeGen/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/python3-qrcodegen) [**QRCodeGen**](https://pypi.org/project/QRCodeGen/) [![Python module](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/Python-logo-notext-22x22.png)](https://pypi.org/project/QRCodeGen/) [![PyPi dependency](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/PyPI_logo_simplified-22x22.png)](https://pypi.org/project/QRCodeGen/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/python3-qrcodegen)

View File

@ -7,17 +7,16 @@
import re import re
import os import os
import subprocess import subprocess
import importlib
from pcbnew import B_Cu, F_Cu, FromMM, IsCopperLayer, PLOT_CONTROLLER, PLOT_FORMAT_SVG, wxSize, F_Mask, B_Mask, ZONE_FILLER from pcbnew import B_Cu, F_Cu, FromMM, IsCopperLayer, PLOT_CONTROLLER, PLOT_FORMAT_SVG, wxSize, F_Mask, B_Mask, ZONE_FILLER
from shutil import rmtree from shutil import rmtree
from tempfile import NamedTemporaryFile, mkdtemp from tempfile import NamedTemporaryFile, mkdtemp
from .svgutils.transform import fromstring, RectElement, fromfile
from .error import KiPlotConfigurationError from .error import KiPlotConfigurationError
from .gs import GS from .gs import GS
from .optionable import Optionable from .optionable import Optionable
from .out_base import VariantOptions from .out_base import VariantOptions
from .kicad.color_theme import load_color_theme from .kicad.color_theme import load_color_theme
from .kicad.patch_svg import patch_svg_file from .kicad.patch_svg import patch_svg_file
from .kicad.worksheet import Worksheet, WksError
from .kicad.config import KiConf from .kicad.config import KiConf
from .kicad.v5_sch import SchError from .kicad.v5_sch import SchError
from .kicad.pcb import PCB from .kicad.pcb import PCB
@ -27,7 +26,8 @@ from .misc import (CMD_PCBNEW_PRINT_LAYERS, PDF_PCB_PRINT, W_PDMASKFAIL, KICAD5_
from .kiplot import exec_with_retry, add_extra_options from .kiplot import exec_with_retry, add_extra_options
from .registrable import RegDependency from .registrable import RegDependency
from .create_pdf import create_pdf_from_pages from .create_pdf import create_pdf_from_pages
from .dep_downloader import check_tool, rsvg_downloader, gs_downloader, convert_downloader, pytool_downloader from .dep_downloader import (check_tool, rsvg_downloader, gs_downloader, convert_downloader, pytool_downloader,
python_downloader)
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
from .drill_marks import DRILL_MARKS_MAP, add_drill_marks from .drill_marks import DRILL_MARKS_MAP, add_drill_marks
from .layer import Layer, get_priority from .layer import Layer, get_priority
@ -54,13 +54,16 @@ pcbdraw_dep = pcbdraw_dependency('pcb_print', pytool_downloader, roles=ToolDepen
# The plot_frame_gui() needs KiAuto to print the frame # The plot_frame_gui() needs KiAuto to print the frame
kiauto_dep = kiauto_dependency('pcb_print', None, CMD_PCBNEW_PRINT_LAYERS, pytool_downloader, kiauto_dep = kiauto_dependency('pcb_print', None, CMD_PCBNEW_PRINT_LAYERS, pytool_downloader,
role=ToolDependencyRole(desc='Print the page frame in GUI mode', version=(1, 6, 7))) role=ToolDependencyRole(desc='Print the page frame in GUI mode', version=(1, 6, 7)))
# SVGUtils dependency. But this is also a PcbDraw dependency
svgutils = None # Will be loaded during dependency check
kicad_worksheet = None # Also needs svgutils
lxml_dep = ToolDependency('pcb_print', 'LXML', is_python=True, downloader=python_downloader)
RegDependency.register(rsvg_dep) RegDependency.register(rsvg_dep)
RegDependency.register(rsvg_dep2) RegDependency.register(rsvg_dep2)
RegDependency.register(gs_dep) RegDependency.register(gs_dep)
RegDependency.register(convert_dep) RegDependency.register(convert_dep)
RegDependency.register(pcbdraw_dep) RegDependency.register(pcbdraw_dep)
# SVGUtils dependency. But this is also a PcbDraw dependency RegDependency.register(lxml_dep)
RegDependency.register(ToolDependency('pcb_print', 'LXML', is_python=True))
RegDependency.register(kiauto_dep) RegDependency.register(kiauto_dep)
@ -408,8 +411,8 @@ class PCB_PrintOptions(VariantOptions):
# Load the WKS # Load the WKS
error = None error = None
try: try:
ws = Worksheet.load(self.layout) ws = kicad_worksheet.Worksheet.load(self.layout)
except (WksError, SchError) as e: except (kicad_worksheet.WksError, SchError) as e:
error = str(e) error = str(e)
if error: if error:
raise KiPlotConfigurationError('Error reading `{}` ({})'.format(self.layout, error)) raise KiPlotConfigurationError('Error reading `{}` ({})'.format(self.layout, error))
@ -673,13 +676,13 @@ class PCB_PrintOptions(VariantOptions):
if not self.add_background: if not self.add_background:
return return
if self.background_image: if self.background_image:
img = fromfile(self.background_image) img = svgutils.fromfile(self.background_image)
w, h = get_size(img) w, h = get_size(img)
root = img.getroot() root = img.getroot()
root.moveto(0, 0) root.moveto(0, 0)
root.scale(width/w, height/h) root.scale(width/w, height/h)
svg_out.insert([root]) svg_out.insert([root])
svg_out.insert(RectElement(0, 0, width, height, color=self.background_color)) svg_out.insert(svgutils.RectElement(0, 0, width, height, color=self.background_color))
def merge_svg(self, input_folder, input_files, output_folder, output_file, p): def merge_svg(self, input_folder, input_files, output_folder, output_file, p):
""" Merge all pages into one """ """ Merge all pages into one """
@ -687,7 +690,7 @@ class PCB_PrintOptions(VariantOptions):
for (file, color) in input_files: for (file, color) in input_files:
logger.debug(' - Loading layer file '+file) logger.debug(' - Loading layer file '+file)
file = os.path.join(input_folder, file) file = os.path.join(input_folder, file)
new_layer = fromstring(load_svg(file, color, p.colored_holes, p.holes_color, p.monochrome)) new_layer = svgutils.fromstring(load_svg(file, color, p.colored_holes, p.holes_color, p.monochrome))
width, height = get_size(new_layer) width, height = get_size(new_layer)
# Workaround for polygon fill on KiCad 5 # Workaround for polygon fill on KiCad 5
if GS.ki5() and file.endswith('frame.svg'): if GS.ki5() and file.endswith('frame.svg'):
@ -745,11 +748,11 @@ class PCB_PrintOptions(VariantOptions):
_run_command(cmd) _run_command(cmd)
# Load the SVG created by PcbDraw # Load the SVG created by PcbDraw
with open(pcbdraw_file, 'rt') as f: with open(pcbdraw_file, 'rt') as f:
svg = fromstring(f.read()) svg = svgutils.fromstring(f.read())
# Load the plot file from KiCad to get the real coordinates system # Load the plot file from KiCad to get the real coordinates system
out_file = os.path.join(temp_dir, out_file) out_file = os.path.join(temp_dir, out_file)
with open(out_file, 'rt') as f: with open(out_file, 'rt') as f:
svg_kicad = fromstring(f.read()) svg_kicad = svgutils.fromstring(f.read())
view_box = svg_kicad.root.get('viewBox') view_box = svg_kicad.root.get('viewBox')
view_box_elements = view_box.split(' ') view_box_elements = view_box.split(' ')
# This is the paper size using the SVG precision # This is the paper size using the SVG precision
@ -979,6 +982,11 @@ class PCB_PrintOptions(VariantOptions):
def run(self, output): def run(self, output):
super().run(output) super().run(output)
check_tool(lxml_dep, fatal=True)
global svgutils
svgutils = importlib.import_module('.svgutils.transform', package=__package__)
global kicad_worksheet
kicad_worksheet = importlib.import_module('.kicad.worksheet', package=__package__)
self.filter_components() self.filter_components()
self.generate_output(output) self.generate_output(output)
self.unfilter_components() self.unfilter_components()

View File

@ -409,7 +409,7 @@ deps = '{\
"LXML": {\ "LXML": {\
"command": "lxml",\ "command": "lxml",\
"deb_package": "python3-lxml",\ "deb_package": "python3-lxml",\
"downloader": null,\ "downloader": {},\
"extra_deb": null,\ "extra_deb": null,\
"help_option": "--version",\ "help_option": "--version",\
"importance": 10000,\ "importance": 10000,\