Skip to content

Commit

Permalink
Update README and requirements for printer detection; add printer lis…
Browse files Browse the repository at this point in the history
…ting functionality
  • Loading branch information
alevilar committed Nov 17, 2024
1 parent 5b72926 commit bd5387d
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ Para enviar un JSON (mediante websocket), que fiscalberry lo reciba, lo transfor

Descarga la última versión socketio para windows

[fiscalberry-win]([https://github.com/user-attachments/files/16818395/fiscalberry-win.zip](https://github.com/paxapos/fiscalberry/releases/download/v1.0.13/fiscalberry-win.exe))
[fiscalberry-win]([https://github.com/paxapos/fiscalberry/releases/latest/download/fiscalberry-win.exe))

Para Linux
[fiscalberry-lin]([https://github.com/paxapos/fiscalberry/releases/latest/download/fiscalberry-lin))

Para Raspberry pi
[fiscalberry-lin]([https://github.com/paxapos/fiscalberry/releases/latest/download/fiscalberry-pi))

# Como comenzar (solo developers del proyecto)

Expand Down
3 changes: 2 additions & 1 deletion requirements.cli.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ argparse==1.4.0
uuid==1.30
appdirs==1.4.4
platformdirs==4.2.2
pika
pika
win32print; sys_platform == 'win32'
1 change: 1 addition & 0 deletions requirements.kivy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ appdirs==1.4.4
platformdirs==4.2.2
kivy==2.3.0
pika
win32print; sys_platform == 'win32'
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ cython==3.0.11
buildozer==1.5.0
pyjnius==1.6.1
twisted==24.7.0
pika
pika
win32print; sys_platform == 'win32'
17 changes: 17 additions & 0 deletions src/common/ComandosHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def runTraductor(jsonTicket, queue):
if driverName == "Win32Raw":
# classprinter.Win32Raw(printer_name='', *args, **kwargs)[source]
driver = printer.Win32Raw(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")

elif driverName == "Usb":
# classprinter.Usb(idVendor=None, idProduct=None, usb_args={}, timeout=0, in_ep=130, out_ep=1, *args, **kwargs)
# convertir de string eJ: 0x82 a int
Expand All @@ -112,23 +115,37 @@ def runTraductor(jsonTicket, queue):
idVendor = int(idVendor, 16)

driver = printer.Usb(idVendor, idProduct, **driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
elif driverName == "Network":
# classprinter.Network(host='', port=9100, timeout=60, *args, **kwargs)[source]
driver = printer.Network(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
elif driverName == "Serial":
# classprinter.Serial(devfile='', baudrate=9600, bytesize=8, timeout=1, parity=None, stopbits=None, xonxoff=False, dsrdtr=True, *args, **kwargs)
driver = printer.Serial(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
elif driverName == "File":
# (devfile='', auto_flush=True
driver = printer.File(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
elif driverName == "Dummy":
driver = printer.Dummy(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
elif driverName == "CupsPrinter":
# CupsPrinter(printer_name='', *args, **kwargs)[source]
driver = printer.CupsPrinter(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
elif driverName == "LP":
# classprinter.LP(printer_name='', *args, **kwargs)[source]
driver = printer.LP(**driverOps)
if not driver.is_usable():
raise DriverError(f"Driver {driverName} not usable")
else:
raise DriverError(f"Invalid driver: {driver}")

Expand Down
6 changes: 4 additions & 2 deletions src/common/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from common.Configberry import Configberry
from common.fiscalberry_logger import getLogger

from common.printer_detector import listar_impresoras

configberry = Configberry()

Expand All @@ -18,9 +18,11 @@ def send_discover():
logger.error("No se ha configurado el uuid en el archivo de configuracion")
return None

data = configberry.getJSON()
data["installed_printers"] = listar_impresoras()
senddata = {
"uuid": configberry.config.get("SERVIDOR", "uuid"),
"raw_data": json.dumps(configberry.getJSON())
"raw_data": json.dumps(data)
}

### Enviar al Discover
Expand Down
19 changes: 19 additions & 0 deletions src/common/printer_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import platform

def listar_impresoras():
sistema_operativo = platform.system()
impresoras = []

if sistema_operativo == "Linux":
import subprocess

resultado = subprocess.run(['lpstat', '-e'], stdout=subprocess.PIPE)
impresoras = resultado.stdout.decode('utf-8').splitlines()
elif sistema_operativo == "Windows":
import win32print

impresoras = [printer[2] for printer in win32print.EnumPrinters(2)]
else:
raise NotImplementedError("Sistema operativo no soportado")

return impresoras
8 changes: 7 additions & 1 deletion src/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from common.ComandosHandler import ComandosHandler
import sys
from common.printer_detector import listar_impresoras

'''
si ejecuto el script sin argumentos que me de un listado de opciones y ayuda de uso
Expand All @@ -17,6 +18,12 @@
si no se especifica se envia a la impresora Dummy
'''



# Ejemplo de uso
impresoras = listar_impresoras()
print("Impresoras instaladas:", impresoras)

class ComandosEnum:
REMITO1 = "remito1"
REMITO2 = "remito2"
Expand Down Expand Up @@ -80,7 +87,6 @@ class ComandosEnum:
sys.exit()



# si comando existe en el listado de comandos disponibles, envio el comando a
# la impresora
if comando in comandosDisponibles:
Expand Down

0 comments on commit bd5387d

Please sign in to comment.