From 7d870c1de57a670e71956e217e7b8886ac49ca2d Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 5 Dec 2014 11:06:42 +0100 Subject: [PATCH] Remove the PPD file once read, otherwise they accumulate --- printer_tray/printer.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 7197ff3..3030ea0 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -19,6 +19,8 @@ # ############################################################################## import cups +import errno +import os from openerp import models, fields, api @@ -35,12 +37,19 @@ class Printer(models.Model): vals = super(Printer, self)._prepare_update_from_cups(cups_connection, cups_printer) - ppd_file_path = cups_connection.getPPD3(self.system_name) - if not ppd_file_path[2]: + ppd_info = cups_connection.getPPD3(self.system_name) + ppd_path = ppd_info[2] + if not ppd_path: return vals - ppd = cups.PPD(ppd_file_path[2]) + ppd = cups.PPD(ppd_path) option = ppd.findOption('InputSlot') + try: + os.unlink(ppd_path) + except OSError as err: + if err.errno == errno.ENOENT: + pass + raise if not option: return vals