[Dependencies] Added support for QRCodeGen auto-download

This commit is contained in:
Salvador E. Tropea 2022-07-01 13:17:02 -03:00
parent 3e331cd7a3
commit 9c6062e0c8
3 changed files with 20 additions and 11 deletions

View File

@ -139,7 +139,7 @@ Notes:
[**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) [**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) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png)
- Mandatory for `qr_lib` - Mandatory for `qr_lib`
[**Colorama**](https://pypi.org/project/Colorama/) [![Python module](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/Python-logo-notext-22x22.png)](https://pypi.org/project/Colorama/) [![PyPi dependency](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/PyPI_logo_simplified-22x22.png)](https://pypi.org/project/Colorama/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/python3-colorama) [**Colorama**](https://pypi.org/project/Colorama/) [![Python module](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/Python-logo-notext-22x22.png)](https://pypi.org/project/Colorama/) [![PyPi dependency](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/PyPI_logo_simplified-22x22.png)](https://pypi.org/project/Colorama/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/python3-colorama)

View File

@ -4,7 +4,6 @@
# License: GPL-3.0 # License: GPL-3.0
# Project: KiBot (formerly KiPlot) # Project: KiBot (formerly KiPlot)
import os import os
from qrcodegen import QrCode
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from .gs import GS from .gs import GS
from .optionable import BaseOptions, Optionable from .optionable import BaseOptions, Optionable
@ -13,18 +12,21 @@ from .kicad.sexpdata import Symbol, dumps, Sep, load, SExpData, sexp_iter
from .kicad.v6_sch import DrawRectangleV6, PointXY, Stroke, Fill, SchematicFieldV6, FontEffects from .kicad.v6_sch import DrawRectangleV6, PointXY, Stroke, Fill, SchematicFieldV6, FontEffects
from .kiplot import load_board from .kiplot import load_board
from .misc import ToolDependency, ToolDependencyRole from .misc import ToolDependency, ToolDependencyRole
from .dep_downloader import check_tool, python_downloader
from .registrable import RegDependency from .registrable import RegDependency
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
from . import log from . import log
try:
import qrcodegen
except ImportError:
qrcodegen = None
QR_ECCS = {'low': QrCode.Ecc.LOW,
'medium': QrCode.Ecc.MEDIUM,
'quartile': QrCode.Ecc.QUARTILE,
'high': QrCode.Ecc.HIGH}
logger = log.get_logger() logger = log.get_logger()
TO_SEPARATE = {'kicad_pcb', 'general', 'title_block', 'layers', 'setup', 'pcbplotparams', 'net_class', 'module', TO_SEPARATE = {'kicad_pcb', 'general', 'title_block', 'layers', 'setup', 'pcbplotparams', 'net_class', 'module',
'kicad_sch', 'lib_symbols', 'symbol', 'sheet', 'sheet_instances', 'symbol_instances'} 'kicad_sch', 'lib_symbols', 'symbol', 'sheet', 'sheet_instances', 'symbol_instances'}
RegDependency.register(ToolDependency('qr_lib', 'QRCodeGen', is_python=True, roles=ToolDependencyRole())) qrcodegen_dep = ToolDependency('qr_lib', 'QRCodeGen', is_python=True, roles=ToolDependencyRole(),
downloader=python_downloader)
RegDependency.register(qrcodegen_dep)
def is_symbol(name, sexp): def is_symbol(name, sexp):
@ -90,7 +92,6 @@ class QRCodeOptions(Optionable):
def config(self, parent): def config(self, parent):
super().config(parent) super().config(parent)
self.correction_level = QR_ECCS[self.correction_level]
self.layer = 'F.SilkS' if self.layer == 'silk' else 'F.Cu' self.layer = 'F.SilkS' if self.layer == 'silk' else 'F.Cu'
@ -474,6 +475,14 @@ class QR_LibOptions(BaseOptions):
return sheets return sheets
def run(self, output): def run(self, output):
global qrcodegen
if qrcodegen is None:
qrcodegen = check_tool(qrcodegen_dep, fatal=True)
# Now we are sure we have qrcodegen
QR_ECCS = {'low': qrcodegen.QrCode.Ecc.LOW,
'medium': qrcodegen.QrCode.Ecc.MEDIUM,
'quartile': qrcodegen.QrCode.Ecc.QUARTILE,
'high': qrcodegen.QrCode.Ecc.HIGH}
if self.use_sch_dir: if self.use_sch_dir:
self._odir_sch = GS.sch_dir self._odir_sch = GS.sch_dir
self._odir_pcb = GS.pcb_dir self._odir_pcb = GS.pcb_dir
@ -482,9 +491,9 @@ class QR_LibOptions(BaseOptions):
# Create the QR codes # Create the QR codes
for qr in self.qrs: for qr in self.qrs:
qr._text_sch = self.expand_filename_both(qr.text, make_safe=False) qr._text_sch = self.expand_filename_both(qr.text, make_safe=False)
qr._code_sch = QrCode.encode_text(qr._text_sch, qr.correction_level) qr._code_sch = qrcodegen.QrCode.encode_text(qr._text_sch, QR_ECCS[qr.correction_level])
qr._text_pcb = self.expand_filename_both(qr.text, is_sch=False, make_safe=False) qr._text_pcb = self.expand_filename_both(qr.text, is_sch=False, make_safe=False)
qr._code_pcb = QrCode.encode_text(qr._text_pcb, qr.correction_level) qr._code_pcb = qrcodegen.QrCode.encode_text(qr._text_pcb, QR_ECCS[qr.correction_level])
# Create the symbols # Create the symbols
if GS.ki5(): if GS.ki5():
self.symbol_lib_k5() self.symbol_lib_k5()

View File

@ -536,7 +536,7 @@ deps = '{\
"QRCodeGen": {\ "QRCodeGen": {\
"command": "qrcodegen",\ "command": "qrcodegen",\
"deb_package": "python3-qrcodegen",\ "deb_package": "python3-qrcodegen",\
"downloader": null,\ "downloader": {},\
"extra_deb": null,\ "extra_deb": null,\
"help_option": "--version",\ "help_option": "--version",\
"importance": 10000,\ "importance": 10000,\