[impression/impression_canon.py] on n'ouvree les logs que lorsque c'est nécessaire
darcs-hash:20090519021636-bd074-722d5e10b728df16ede4fe0bfe15809dc1ee0ad5.gz
This commit is contained in:
parent
f05d9405c9
commit
d7d9f9e3d5
2 changed files with 16 additions and 15 deletions
|
@ -25,7 +25,7 @@ def etat():
|
||||||
|
|
||||||
def etat_canon():
|
def etat_canon():
|
||||||
_dico = {
|
_dico = {
|
||||||
'idle(3)\nrunning(2)' : u'Pas configuré comme une imprimante',
|
'idle(3)\nrunning(2)' : u'En marche',
|
||||||
'printing(4)\nrunning(2)' : u'Impression en cours',
|
'printing(4)\nrunning(2)' : u'Impression en cours',
|
||||||
'other(1)\ndown(5)' : u"Erreur [grave] de l'imprimante",
|
'other(1)\ndown(5)' : u"Erreur [grave] de l'imprimante",
|
||||||
'other(1)\nrunning(2)' : u'Imprimante en veille',
|
'other(1)\nrunning(2)' : u'Imprimante en veille',
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
# ................................
|
# ................................
|
||||||
#
|
#
|
||||||
# #############################################################
|
# #############################################################
|
||||||
# __init__.py
|
# impression_canon.py
|
||||||
#
|
#
|
||||||
# Classe impression
|
# Classe impression pour l'imprimante canon iR C3580i
|
||||||
#
|
#
|
||||||
# Copyright (c) 2006 by www.crans.org
|
# Copyright (c) 2006, 2007, 2008, 2009 by Cr@ns (http://www.crans.org)
|
||||||
# #############################################################
|
# #############################################################
|
||||||
"""
|
"""
|
||||||
Classe pour gérer l'envoie de pdf à l'imprimante.
|
Classe pour gérer l'envoie de pdf à l'imprimante.
|
||||||
|
@ -34,7 +34,6 @@ import sys, syslog, os.path, time
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
from config import impression as config_impression
|
from config import impression as config_impression
|
||||||
from commands import getstatusoutput
|
from commands import getstatusoutput
|
||||||
from hptools import snmp
|
|
||||||
from crans.utils import QuoteForPOSIX as escapeForShell
|
from crans.utils import QuoteForPOSIX as escapeForShell
|
||||||
import crans.utils.logs
|
import crans.utils.logs
|
||||||
|
|
||||||
|
@ -42,8 +41,6 @@ import crans.utils.logs
|
||||||
# CONSTANTES #
|
# CONSTANTES #
|
||||||
# ######################################################## #
|
# ######################################################## #
|
||||||
|
|
||||||
LOG = crans.utils.logs.getFileLogger('impression')
|
|
||||||
COMM = snmp(host="imprimante.adm.crans.org",version="1",community="public")
|
|
||||||
FICHIER_LOG="/var/log/log_couts/impressions"
|
FICHIER_LOG="/var/log/log_couts/impressions"
|
||||||
|
|
||||||
SNMP_CAPA_B = "mib-2.43.11.1.1.8.1.1"
|
SNMP_CAPA_B = "mib-2.43.11.1.1.8.1.1"
|
||||||
|
@ -120,6 +117,7 @@ class SettingsError(Exception):
|
||||||
Erreur de paramètres.
|
Erreur de paramètres.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# ######################################################## #
|
# ######################################################## #
|
||||||
# CLASSE IMPRESSION #
|
# CLASSE IMPRESSION #
|
||||||
# ######################################################## #
|
# ######################################################## #
|
||||||
|
@ -152,7 +150,6 @@ class impression:
|
||||||
_base_prix_nb = 0.0
|
_base_prix_nb = 0.0
|
||||||
_base_prix_couleurs = 0.0
|
_base_prix_couleurs = 0.0
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, path_to_pdf, adh = None):
|
def __init__(self, path_to_pdf, adh = None):
|
||||||
"""impression(path_to_pdf [, adh])
|
"""impression(path_to_pdf [, adh])
|
||||||
|
|
||||||
|
@ -162,6 +159,10 @@ class impression:
|
||||||
l'adhérent. Lève l'exception FichierInvalide si le fichier
|
l'adhérent. Lève l'exception FichierInvalide si le fichier
|
||||||
n'existe pas ou si ce n'est pas un pdf.
|
n'existe pas ou si ce n'est pas un pdf.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# On ouvre les logs
|
||||||
|
self.log = crans.utils.logs.getFileLogger('impression')
|
||||||
|
|
||||||
self._fichier = path_to_pdf
|
self._fichier = path_to_pdf
|
||||||
self._adh = adh
|
self._adh = adh
|
||||||
|
|
||||||
|
@ -186,10 +187,10 @@ class impression:
|
||||||
newfile = self._fichier[:-4] + '-book.pdf'
|
newfile = self._fichier[:-4] + '-book.pdf'
|
||||||
pdfbook = "pdfbook %%s --outfile %s" % newfile
|
pdfbook = "pdfbook %%s --outfile %s" % newfile
|
||||||
(status, rep) = getstatusoutput(pdfbook % self._fichier)
|
(status, rep) = getstatusoutput(pdfbook % self._fichier)
|
||||||
LOG.info("%s | rep: %s" % ((pdfbook % self._fichier), rep))
|
self.log.info("%s | rep: %s" % ((pdfbook % self._fichier), rep))
|
||||||
self._fichier = newfile
|
self._fichier = newfile
|
||||||
if status != 0:
|
if status != 0:
|
||||||
LOG.error("pdfbook status:%d | rep: %s" % (status, rep))
|
self.log.error("pdfbook status:%d | rep: %s" % (status, rep))
|
||||||
raise FichierInvalide, ("pdfbook: Impossible de convertir le fichier",
|
raise FichierInvalide, ("pdfbook: Impossible de convertir le fichier",
|
||||||
self._fichier)
|
self._fichier)
|
||||||
|
|
||||||
|
@ -386,9 +387,9 @@ class impression:
|
||||||
self._pdfbook()
|
self._pdfbook()
|
||||||
|
|
||||||
if (self._adh != None):
|
if (self._adh != None):
|
||||||
LOG.info('Impression [%s] : %s' % (self._adh, self._fichier))
|
self.log.info('Impression [%s] : %s' % (self._adh, self._fichier))
|
||||||
else:
|
else:
|
||||||
LOG.info("Impression : %s" % self._fichier)
|
self.log.info("Impression : %s" % self._fichier)
|
||||||
|
|
||||||
# Envoi du fichier à CUPS
|
# Envoi du fichier à CUPS
|
||||||
options = ''
|
options = ''
|
||||||
|
@ -449,10 +450,10 @@ class impression:
|
||||||
cmd = "lpr %s -# %d %s" % (options, self._settings['copies'],
|
cmd = "lpr %s -# %d %s" % (options, self._settings['copies'],
|
||||||
self._fichier)
|
self._fichier)
|
||||||
(status, rep) = getstatusoutput(cmd)
|
(status, rep) = getstatusoutput(cmd)
|
||||||
LOG.info("printing: %s" % cmd)
|
self.log.info("printing: %s" % cmd)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
LOG.error("erreur impression")
|
self.log.error("erreur impression")
|
||||||
LOG.error("lpr status:%d | rep: %s" % (status, rep))
|
self.log.error("lpr status:%d | rep: %s" % (status, rep))
|
||||||
raise PrintError, "%s \n status:%d rep: %s" % (cmp, status, rep)
|
raise PrintError, "%s \n status:%d rep: %s" % (cmp, status, rep)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue