[FIX] hw_drivers: Add printer manually to IoT
Actually it is not possible to add manually a printer. With this commit we loop into all printer recorded in cups to check if a printer is not automatically added. If a printer does not match with a identifier automaticcaly generated, it is added to the list of usable printer. closes odoo/odoo#95709 X-original-commit: de03cbefd537503cd46cbecf1622bd2a547b4615 Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
@@ -20,18 +20,29 @@ class PrinterInterface(Interface):
|
||||
with cups_lock:
|
||||
printers = conn.getPrinters()
|
||||
devices = conn.getDevices()
|
||||
for printer in printers:
|
||||
path = printers.get(printer).get('device-uri', False)
|
||||
if path and path in devices:
|
||||
devices.get(path).update({'supported': True}) # these printers are automatically supported
|
||||
for path in devices:
|
||||
if 'uuid=' in path:
|
||||
identifier = sub('[^a-zA-Z0-9_]', '', path.split('uuid=')[1])
|
||||
elif 'serial=' in path:
|
||||
identifier = sub('[^a-zA-Z0-9_]', '', path.split('serial=')[1])
|
||||
else:
|
||||
identifier = sub('[^a-zA-Z0-9_]', '', path)
|
||||
devices[path]['identifier'] = identifier
|
||||
devices[path]['url'] = path
|
||||
printer_devices[identifier] = devices[path]
|
||||
for printer_name, printer in printers.items():
|
||||
path = printer.get('device-uri', False)
|
||||
if printer_name != self.get_identifier(path):
|
||||
printer.update({'supported': True}) # these printers are automatically supported
|
||||
device_class = 'network'
|
||||
if 'usb' in printer.get('device-uri'):
|
||||
device_class = 'direct'
|
||||
printer.update({'device-class': device_class})
|
||||
printer.update({'device-make-and-model': printer_name}) # give name setted in Cups
|
||||
printer.update({'device-id': ''})
|
||||
devices.update({printer_name: printer})
|
||||
for path, device in devices.items():
|
||||
identifier = self.get_identifier(path)
|
||||
device.update({'identifier': identifier})
|
||||
device.update({'url': path})
|
||||
printer_devices.update({identifier: device})
|
||||
return printer_devices
|
||||
|
||||
def get_identifier(self, path):
|
||||
if 'uuid=' in path:
|
||||
identifier = sub('[^a-zA-Z0-9_]', '', path.split('uuid=')[1])
|
||||
elif 'serial=' in path:
|
||||
identifier = sub('[^a-zA-Z0-9_]', '', path.split('serial=')[1])
|
||||
else:
|
||||
identifier = sub('[^a-zA-Z0-9_]', '', path)
|
||||
return identifier
|
||||
|
||||
Reference in New Issue
Block a user