Skip to content
Snippets Groups Projects
Commit 7686e1bc authored by lejeune quentin's avatar lejeune quentin
Browse files

[IMP] hw_drivers: Add possibility to add manually a printer to the IoT Box


The IoT Box detects printers automatically under certain conditions.
And so there are printers that are not detected by the box
and cannot be used in Odoo.
With this commit we give the possibility to add printers manually
with Cups and to be able to use them in Odoo.

closes odoo/odoo#52154

Signed-off-by: default avatarQuentin Lejeune (qle) <qle@odoo.com>
parent 0116ccf2
Branches
Tags
No related merge requests found
......@@ -16,7 +16,7 @@ from PIL import Image, ImageOps
from odoo import http, _
from odoo.addons.hw_drivers.controllers.driver import event_manager, Driver, iot_devices
from odoo.addons.hw_drivers.iot_handlers.interfaces.PrinterInterface import PPDs, conn, printers, cups_lock
from odoo.addons.hw_drivers.iot_handlers.interfaces.PrinterInterface import PPDs, conn, cups_lock
from odoo.addons.hw_drivers.tools import helpers
from odoo.addons.hw_proxy.controllers.main import drivers as old_drivers
......@@ -92,6 +92,8 @@ class PrinterDriver(Driver):
@classmethod
def supported(cls, device):
if device.get('supported', False):
return True
protocol = ['dnssd', 'lpd']
if any(x in device['url'] for x in protocol) and device['device-make-and-model'] != 'Unknown' or 'direct' in device['device-class']:
model = cls.get_device_model(device)
......@@ -105,15 +107,12 @@ class PrinterDriver(Driver):
conn.addPrinter(name=device['identifier'], ppdname=ppdFile, device=device['url'])
else:
conn.addPrinter(name=device['identifier'], device=device['url'])
if device['identifier'] not in printers:
conn.setPrinterInfo(device['identifier'], device['device-make-and-model'])
conn.enablePrinter(device['identifier'])
conn.acceptJobs(device['identifier'])
conn.setPrinterUsersAllowed(device['identifier'], ['all'])
conn.addPrinterOptionDefault(device['identifier'], "usb-no-reattach", "true")
conn.addPrinterOptionDefault(device['identifier'], "usb-unidir", "true")
else:
device['device-make-and-model'] = printers[device['identifier']]['printer-info']
conn.setPrinterInfo(device['identifier'], device['device-make-and-model'])
conn.enablePrinter(device['identifier'])
conn.acceptJobs(device['identifier'])
conn.setPrinterUsersAllowed(device['identifier'], ['all'])
conn.addPrinterOptionDefault(device['identifier'], "usb-no-reattach", "true")
conn.addPrinterOptionDefault(device['identifier'], "usb-unidir", "true")
if 'STR_T' in device['device-id']:
# Star printers have either STR_T or ESP in their name depending on the protocol used.
print_star_error(device['identifier'])
......
......@@ -6,7 +6,6 @@ from odoo.addons.hw_drivers.controllers.driver import Interface
conn = cups_connection()
PPDs = conn.getPPDs()
printers = conn.getPrinters()
cups_lock = Lock() # We can only make one call to Cups at a time
class PrinterInterface(Interface):
......@@ -16,14 +15,24 @@ class PrinterInterface(Interface):
def get_devices(self):
printer_devices = {}
with cups_lock:
printers = conn.getPrinters()
for printer in printers:
printers[printer]['supported'] = True # these printers are automatically supported
printers[printer]['device-make-and-model'] = printers[printer]['printer-make-and-model']
if 'usb' in printers[printer]['device-uri']:
printers[printer]['device-class'] = 'direct'
else:
printers[printer]['device-class'] = 'network'
devices = conn.getDevices()
if printers:
devices.update(printers)
for path in devices:
if 'uuid=' in path:
identifier = sub('[^a-zA-Z0-9 ]+', '', path.split('uuid=')[1])
identifier = sub('[^a-zA-Z0-9_]', '', path.split('uuid=')[1])
elif 'serial=' in path:
identifier = sub('[^a-zA-Z0-9 ]+', '', path.split('serial=')[1])
identifier = sub('[^a-zA-Z0-9_]', '', path.split('serial=')[1])
else:
identifier = sub('[^a-zA-Z0-9 ]+', '', path)
identifier = sub('[^a-zA-Z0-9_]', '', path)
devices[path]['identifier'] = identifier
devices[path]['url'] = path
printer_devices[identifier] = devices[path]
......
......@@ -46,16 +46,14 @@ DefaultPaperSize None
# Restrict access to configuration files...
<Location /admin/conf>
AuthType Default
Require user @SYSTEM
Order allow
Order allow,deny
Allow all
</Location>
# Restrict access to log files...
<Location /admin/log>
AuthType Default
Require user @SYSTEM
Order allow
Order allow,deny
Allow all
</Location>
# Set the default printer/job policies...
......@@ -68,36 +66,36 @@ DefaultPaperSize None
# Job-related operations must be done by the owner or an administrator...
<Limit Create-Job Print-Job Print-URI Validate-Job>
Order deny,allow
Order allow,deny
Allow all
</Limit>
<Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
Require user @OWNER @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# All administration operations require an administrator to authenticate...
<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
AuthType Default
Require user @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# All printer operations require a printer operator to authenticate...
<Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
AuthType Default
Require user @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# Only the owner or an administrator can cancel or authenticate a job...
<Limit Cancel-Job CUPS-Authenticate-Job>
Require user @OWNER @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
<Limit All>
Order deny,allow
Order allow,deny
Allow all
</Limit>
</Policy>
......@@ -111,39 +109,36 @@ DefaultPaperSize None
# Job-related operations must be done by the owner or an administrator...
<Limit Create-Job Print-Job Print-URI Validate-Job>
AuthType Default
Order deny,allow
Order allow,deny
Allow all
</Limit>
<Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
AuthType Default
Require user @OWNER @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# All administration operations require an administrator to authenticate...
<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
AuthType Default
Require user @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# All printer operations require a printer operator to authenticate...
<Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
AuthType Default
Require user @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# Only the owner or an administrator can cancel or authenticate a job...
<Limit Cancel-Job CUPS-Authenticate-Job>
AuthType Default
Require user @OWNER @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
<Limit All>
Order deny,allow
Order allow,deny
Allow all
</Limit>
</Policy>
......@@ -157,38 +152,35 @@ DefaultPaperSize None
# Job-related operations must be done by the owner or an administrator...
<Limit Create-Job Print-Job Print-URI Validate-Job>
AuthType Negotiate
Order deny,allow
Order allow,deny
Allow all
</Limit>
<Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
AuthType Negotiate
Require user @OWNER @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# All administration operations require an administrator to authenticate...
<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
AuthType Default
Require user @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# All printer operations require a printer operator to authenticate...
<Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
AuthType Default
Require user @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
# Only the owner or an administrator can cancel or authenticate a job...
<Limit Cancel-Job CUPS-Authenticate-Job>
AuthType Negotiate
Require user @OWNER @SYSTEM
Order deny,allow
Order allow,deny
Allow all
</Limit>
<Limit All>
Order deny,allow
Order allow,deny
Allow all
</Limit>
</Policy>
\ No newline at end of file
......@@ -158,6 +158,7 @@ systemctl enable autologin@.service
systemctl disable systemd-timesyncd.service
systemctl unmask hostapd.service
systemctl disable hostapd.service
systemctl disable cups-browsed.service
# disable overscan in /boot/config.txt, we can't use
# overwrite_after_init because it's on a different device
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment