Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save renzo1974/0453e91ff3e13350a1e46a11ebb02e8d to your computer and use it in GitHub Desktop.
Save renzo1974/0453e91ff3e13350a1e46a11ebb02e8d to your computer and use it in GitHub Desktop.
Index: base_report_to_printer/models/printing_printer.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- base_report_to_printer/models/printing_printer.py (revision d995be287613fa41a3b35e843ce2bc4144839ab6)
+++ base_report_to_printer/models/printing_printer.py (revision 6b53cd15358ba913e5302fb82dab1664d90ca280)
@@ -9,11 +9,11 @@
import errno
import logging
import os
+import subprocess
from tempfile import mkstemp
from flectra import models, fields, api
-
_logger = logging.getLogger(__name__)
try:
@@ -172,12 +172,28 @@
options = self.print_options(report=report, **print_opts)
_logger.debug(
'Sending job to CUPS printer %s on %s'
% (self.system_name, self.server_id.address))
- connection.printFile(self.system_name,
- file_name,
- file_name,
- options=options)
+ try:
+ connection.printFile(self.system_name,
+ file_name,
+ file_name,
+ options=options)
+ except cups.IPPError:
+ cmd = [
+ 'lp',
+ '-h', '%s:%s' % (self.server_id.address, self.server_id.port),
+ '-d', self.system_name,
+ ]
+ for opt, val in options.items():
+ cmd.append('-o')
+ if val:
+ cmd.append('%s=%s' % (opt, val))
+ else:
+ cmd.append(opt)
+
+ cmd.append(file_name)
+ subprocess.check_call(cmd)
_logger.info("Printing job: '%s' on %s" % (
file_name,
self.server_id.address,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment