impression_hp: état d'un bac

Et utilise le bac 4 en prio, par rapport au 3, lorsqu'il n'est pas low.
This commit is contained in:
Daniel STAN 2014-12-05 13:24:06 +01:00
parent 7fbd3ad275
commit 0e1178bd1a

View file

@ -10,14 +10,12 @@ License: GPLv3
"""
# impression_hp.py
#
# Classe impression pour HP MFP 880
#
# Copyright (c) 2006, 2007, 2008, 2009 by Cr@ns (http://www.crans.org)
# #############################################################
import sys, os
import logging
import logging.handlers
import BeautifulSoup
import requests
if '/usr/scripts' not in sys.path:
sys.path.append('/usr/scripts')
@ -28,6 +26,12 @@ from gestion.config import impression as config_impression
from subprocess import Popen, PIPE, check_output
import livret
## Pour les codes qui se connectent direct à l'imprimante en http
BASE_URL = 'https://imprimante.adm.crans.org'
URL_JOBLIST = BASE_URL + '/hp/device/JobLogReport/Index'
URL_STATE = BASE_URL + '/'
CA = '/etc/ssl/certs/cacert.org.pem'
##
logger = logging.getLogger('impression_hp')
logger.setLevel(logging.DEBUG)
@ -165,7 +169,7 @@ class Perforation(SelectOption):
#
#
class impression(object):
"""impression
"""impression d'un fichier avec l'imprimante HP MFP M880
Un objet impression correspond à un fichier pdf et un adhérent.
"""
@ -366,6 +370,24 @@ class impression(object):
# imprime le document
self._exec_imprime()
_doc = None
def low_tray(self, num):
"""Indique si un bac est vide ou presque vide"""
if self._doc is None:
req = requests.get(URL_STATE, verify=CA)
self._doc = BeautifulSoup.BeautifulSoup(req.text)
try:
tray = self._doc.findAll(attrs={'id': 'TrayBinStatus_%d' % num})[0]
except IndexError:
return False
state = tray.attrMap['class']
if 'morethan40' in state or 'between20and40':
return False
if 'empty' in state:
return True
logger.info('Unknown Tray State: %s' % state)
return False
def _calcule_prix(self):
faces = self._pages
@ -455,6 +477,10 @@ class impression(object):
options.append('InputSlot=Tray1')
elif self._settings['livret'].value:
options.append('InputSlot=Tray2')
else: # A4, dans Tray3 et Tray4
## On utilise en priorité le Tray 4 (plus gros)
if not self.low_tray(4) or self.low_tray(3):
options.append('InputSlot=Tray4')
else:
options.append('InputSlot=Tray3')