From 0e1178bd1aa6dcb796d741d298828a5e204723d0 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Fri, 5 Dec 2014 13:24:06 +0100 Subject: [PATCH] =?UTF-8?q?impression=5Fhp:=20=C3=A9tat=20d'un=20bac?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Et utilise le bac 4 en prio, par rapport au 3, lorsqu'il n'est pas low. --- impression/impression_hp.py | 40 ++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/impression/impression_hp.py b/impression/impression_hp.py index e83f137d..5bd8e39f 100644 --- a/impression/impression_hp.py +++ b/impression/impression_hp.py @@ -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,8 +477,12 @@ class impression(object): options.append('InputSlot=Tray1') elif self._settings['livret'].value: options.append('InputSlot=Tray2') - else: - options.append('InputSlot=Tray3') + 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') if not self._settings['couleur'].value: