[FIX] .travis.yml: Update definition

This commit is contained in:
Pedro M. Baeza
2019-10-01 15:26:55 +02:00
committed by David Montull
parent 587f020bc3
commit 06b229c342
25 changed files with 995 additions and 1043 deletions

View File

@@ -11,15 +11,14 @@ import logging
import os
from tempfile import mkstemp
from odoo import models, fields
from odoo import fields, models
_logger = logging.getLogger(__name__)
try:
import cups
except ImportError:
_logger.debug('Cannot `import cups`.')
_logger.debug("Cannot `import cups`.")
class PrintingPrinter(models.Model):
@@ -27,63 +26,65 @@ class PrintingPrinter(models.Model):
Printers
"""
_name = 'printing.printer'
_description = 'Printer'
_order = 'name'
_name = "printing.printer"
_description = "Printer"
_order = "name"
name = fields.Char(required=True, index=True)
server_id = fields.Many2one(
comodel_name='printing.server', string='Server', required=True,
help='Server used to access this printer.')
comodel_name="printing.server",
string="Server",
required=True,
help="Server used to access this printer.",
)
job_ids = fields.One2many(
comodel_name='printing.job', inverse_name='printer_id', string='Jobs',
help='Jobs printed on this printer.')
comodel_name="printing.job",
inverse_name="printer_id",
string="Jobs",
help="Jobs printed on this printer.",
)
system_name = fields.Char(required=True, index=True)
default = fields.Boolean(readonly=True)
status = fields.Selection(
selection=[
('unavailable', 'Unavailable'),
('printing', 'Printing'),
('unknown', 'Unknown'),
('available', 'Available'),
('error', 'Error'),
('server-error', 'Server Error'),
("unavailable", "Unavailable"),
("printing", "Printing"),
("unknown", "Unknown"),
("available", "Available"),
("error", "Error"),
("server-error", "Server Error"),
],
required=True,
readonly=True,
default='unknown')
default="unknown",
)
status_message = fields.Char(readonly=True)
model = fields.Char(readonly=True)
location = fields.Char(readonly=True)
uri = fields.Char(string='URI', readonly=True)
tray_ids = fields.One2many(comodel_name='printing.tray',
inverse_name='printer_id',
string='Paper Sources')
uri = fields.Char(string="URI", readonly=True)
tray_ids = fields.One2many(
comodel_name="printing.tray", inverse_name="printer_id", string="Paper Sources"
)
def _prepare_update_from_cups(self, cups_connection, cups_printer):
mapping = {
3: 'available',
4: 'printing',
5: 'error'
}
mapping = {3: "available", 4: "printing", 5: "error"}
vals = {
'name': cups_printer['printer-info'],
'model': cups_printer.get('printer-make-and-model', False),
'location': cups_printer.get('printer-location', False),
'uri': cups_printer.get('device-uri', False),
'status': mapping.get(cups_printer.get(
'printer-state'), 'unknown'),
'status_message': cups_printer.get('printer-state-message', ''),
"name": cups_printer["printer-info"],
"model": cups_printer.get("printer-make-and-model", False),
"location": cups_printer.get("printer-location", False),
"uri": cups_printer.get("device-uri", False),
"status": mapping.get(cups_printer.get("printer-state"), "unknown"),
"status_message": cups_printer.get("printer-state-message", ""),
}
printer_uri = cups_printer['printer-uri-supported']
printer_system_name = printer_uri[printer_uri.rfind('/') + 1:]
printer_uri = cups_printer["printer-uri-supported"]
printer_system_name = printer_uri[printer_uri.rfind("/") + 1 :]
ppd_info = cups_connection.getPPD3(printer_system_name)
ppd_path = ppd_info[2]
if not ppd_path:
return vals
ppd = cups.PPD(ppd_path)
option = ppd.findOption('InputSlot')
option = ppd.findOption("InputSlot")
try:
os.unlink(ppd_path)
except OSError as err:
@@ -94,25 +95,29 @@ class PrintingPrinter(models.Model):
if not option:
return vals
vals['tray_ids'] = []
vals["tray_ids"] = []
cups_trays = {
tray_option['choice']: tray_option['text']
for tray_option in option.choices
tray_option["choice"]: tray_option["text"] for tray_option in option.choices
}
# Add new trays
vals['tray_ids'].extend([
(0, 0, {'name': text, 'system_name': choice})
for choice, text in cups_trays.items()
if choice not in self.tray_ids.mapped('system_name')
])
vals["tray_ids"].extend(
[
(0, 0, {"name": text, "system_name": choice})
for choice, text in cups_trays.items()
if choice not in self.tray_ids.mapped("system_name")
]
)
# Remove deleted trays
vals['tray_ids'].extend([
(2, tray.id)
for tray in self.tray_ids.filtered(
lambda record: record.system_name not in cups_trays.keys())
])
vals["tray_ids"].extend(
[
(2, tray.id)
for tray in self.tray_ids.filtered(
lambda record: record.system_name not in cups_trays.keys()
)
]
)
return vals
def print_document(self, report, content, **print_opts):
@@ -126,12 +131,11 @@ class PrintingPrinter(models.Model):
finally:
os.close(fd)
return self.print_file(
file_name, report=report, **print_opts)
return self.print_file(file_name, report=report, **print_opts)
@staticmethod
def _set_option_doc_format(report, value):
return {'raw': 'True'} if value == 'raw' else {}
return {"raw": "True"} if value == "raw" else {}
# Backwards compatibility of builtin used as kwarg
_set_option_format = _set_option_doc_format
@@ -139,7 +143,7 @@ class PrintingPrinter(models.Model):
def _set_option_tray(self, report, value):
"""Note we use self here as some older PPD use tray
rather than InputSlot so we may need to query printer in override"""
return {'InputSlot': str(value)} if value else {}
return {"InputSlot": str(value)} if value else {}
@staticmethod
def _set_option_noop(report, value):
@@ -152,8 +156,7 @@ class PrintingPrinter(models.Model):
options = {}
for option, value in print_opts.items():
try:
options.update(getattr(
self, '_set_option_%s' % option)(report, value))
options.update(getattr(self, "_set_option_%s" % option)(report, value))
except AttributeError:
options[option] = str(value)
return options
@@ -165,33 +168,30 @@ class PrintingPrinter(models.Model):
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)
_logger.info("Printing job: '%s' on %s" % (
file_name,
self.server_id.address,
))
"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)
_logger.info(
"Printing job: '{}' on {}".format(file_name, self.server_id.address)
)
return True
def set_default(self):
if not self:
return
self.ensure_one()
default_printers = self.search([('default', '=', True)])
default_printers = self.search([("default", "=", True)])
default_printers.unset_default()
self.write({'default': True})
self.write({"default": True})
return True
def unset_default(self):
self.write({'default': False})
self.write({"default": False})
return True
def get_default(self):
return self.search([('default', '=', True)], limit=1)
return self.search([("default", "=", True)], limit=1)
def action_cancel_all_jobs(self):
self.ensure_one()
@@ -200,11 +200,10 @@ class PrintingPrinter(models.Model):
def cancel_all_jobs(self, purge_jobs=False):
for printer in self:
connection = printer.server_id._open_connection()
connection.cancelAllJobs(
name=printer.system_name, purge_jobs=purge_jobs)
connection.cancelAllJobs(name=printer.system_name, purge_jobs=purge_jobs)
# Update jobs' states into Odoo
self.mapped('server_id').update_jobs(which='completed')
self.mapped("server_id").update_jobs(which="completed")
return True
@@ -214,7 +213,7 @@ class PrintingPrinter(models.Model):
connection.enablePrinter(printer.system_name)
# Update printers' stats into Odoo
self.mapped('server_id').update_printers()
self.mapped("server_id").update_printers()
return True
@@ -224,6 +223,6 @@ class PrintingPrinter(models.Model):
connection.disablePrinter(printer.system_name)
# Update printers' stats into Odoo
self.mapped('server_id').update_printers()
self.mapped("server_id").update_printers()
return True