summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Prieels <anp@odoo.com>2019-07-04 08:12:12 +0000
committerAntoine Prieels <anp@odoo.com>2019-08-08 05:47:03 +0000
commitdd7de1bcb65d339e5865afcc980cbb4d171fbb74 (patch)
treef40693fdfad72dca5027152586274224a1b33e6a
parentc20cb62f498772e678387b0ea02594374acdaa56 (diff)
[IMP] hw_drivers: Move PrinterDriver to Community
Printers should be usable by IoT Boxes connected to a community DB. TaskID: 1939455
-rw-r--r--addons/hw_drivers/drivers/PrinterDriver.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/addons/hw_drivers/drivers/PrinterDriver.py b/addons/hw_drivers/drivers/PrinterDriver.py
new file mode 100644
index 00000000000..ccf0a6963bf
--- /dev/null
+++ b/addons/hw_drivers/drivers/PrinterDriver.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from base64 import b64decode
+import logging
+import subprocess
+import tempfile
+
+from odoo import _
+from odoo.addons.hw_drivers.controllers.driver import Driver, PPDs, conn, printers
+
+_logger = logging.getLogger(__name__)
+
+class PrinterDriver(Driver):
+ connection_type = 'printer'
+
+ def __init__(self, device):
+ super(PrinterDriver, self).__init__(device)
+ self._device_type = 'printer'
+ self._device_connection = self.dev['device-class'].lower()
+ self._device_name = self.dev['device-make-and-model']
+ self._device_identifier = self.dev['identifier']
+
+ @classmethod
+ def supported(cls, device):
+ protocol = ['dnssd', 'lpd']
+ if any(x in device['url'] for x in protocol) or 'direct' in device['device-class']:
+ ppdFile = ''
+ for device_id in [device_lo for device_lo in device['device-id'].split(';') if device['device-id']]:
+ if any(x in device_id for x in ['MDL','MODEL']):
+ device.update({'MDL': device_id.split(':')[1]})
+ for ppd in PPDs:
+ if device['MDL'] in PPDs[ppd]['ppd-product']:
+ ppdFile = ppd
+ if ppdFile:
+ 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'])
+ else:
+ device['device-make-and-model'] = printers[device['identifier']]['printer-info']
+ return True
+ return False
+
+ def action(self, data):
+ try:
+ with tempfile.NamedTemporaryFile() as tmp:
+ tmp.write(b64decode(data['document']))
+ tmp.flush()
+ subprocess.check_call("lp -d %s %s" % (self.dev['identifier'], tmp.name), shell=True)
+ except subprocess.CalledProcessError as e:
+ _logger.warning(e.output)