[lib/impression] on déplace tout dans impression
Ignore-this: f8064e9bceb8818911dcdaf73cb9f0ec darcs-hash:20090518184018-bd074-ae9530b4d2aba374d34d5a9e26e422c649d9e8db.gz
This commit is contained in:
parent
9e2cd076f5
commit
788012f862
7 changed files with 32 additions and 67 deletions
|
@ -1,51 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: iso8859-15 -*-
|
||||
#
|
||||
# bourrages.py : récupération des fichiers de logs de bourrage l'imprimante.
|
||||
#
|
||||
# Stocke les logs de l'imprimante au fur et à mesure
|
||||
#
|
||||
# Copyright (c) 2008 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
|
||||
#
|
||||
|
||||
import urllib
|
||||
import sys
|
||||
import re
|
||||
|
||||
nom_fichier_log = "/var/log/bourrages.log"
|
||||
URL = "https://laserjet.adm.crans.org/hp/device/this.LCDispatcher?dispatch=html&cat=0&pos=3"
|
||||
|
||||
span_rex = re.compile(r'<span[^>]+class="hpPageText"[^>]*>(?P<contenu>[^<]+)</span>', re.IGNORECASE)
|
||||
|
||||
try:
|
||||
f = open(nom_fichier_log)
|
||||
except:
|
||||
sys.stderr.write("Erreur d'ouverture du fichier de logs en lecture...\n")
|
||||
lastpage = 0
|
||||
else:
|
||||
lastpage = f.readlines()[-1].strip().split()[0]
|
||||
f.close()
|
||||
|
||||
try:
|
||||
lignesimpr = urllib.urlopen(URL).readlines()
|
||||
except:
|
||||
sys.stderr.write("Problème de lecture de la page d'impression...\n")
|
||||
else:
|
||||
lignes_recup = [span_rex.match(ligne).group("contenu") for ligne in lignesimpr if span_rex.match(ligne)]
|
||||
|
||||
premier_indice = lignes_recup.index('Num\xe9ro') + 4
|
||||
erreurs = []
|
||||
|
||||
for i in xrange(premier_indice, len(lignes_recup), 4):
|
||||
erreurs.append(tuple(lignes_recup[i+1:i+4]))
|
||||
|
||||
try:
|
||||
fichier_log = open(nom_fichier_log, 'a')
|
||||
except:
|
||||
sys.stderr.write("Erreur d'ouverture du fichier de logs en écriture...\n")
|
||||
else:
|
||||
for erreur in reversed(erreurs):
|
||||
if erreur[0] > lastpage:
|
||||
fichier_log.write("%s %s %s\n" % erreur)
|
||||
|
||||
fichier_log.close()
|
Loading…
Add table
Add a link
Reference in a new issue