etat_imprimante.py 1.29 KB
Newer Older
1
2
3
4
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

import sys
bobot's avatar
bobot committed
5
sys.path.append("/usr/scripts/gestion")
6
7
8

import hptools

9
dico = {
10
11
12
13
14
15
16
17
  u"Prt": u"Prt",
  u"Pr menus, appuy \x1e": u"",
  u"Powersave activ": u"En veille",
  u"Verification": u"Vrification imprimante",
  u"imprimante": u"",
  u"Prchauffage": u"Prchauffage",
  u"Traitement de la": u"Impression en cours",
  u"tche du bac 4": u"",
glondu's avatar
glondu committed
18
  u"tche du bac 3": u"",
19
20
  u"COMMANDER CARTOUCHE": u"",
  u"CYAN": u"",
glondu's avatar
glondu committed
21
  u"MAGENTA": u"",
22
23
}

24
25
def etat():
    """ Renvoie une liste des differents ecrans actuels du display de l'imprimante """
bobot's avatar
bobot committed
26
    liste_oid = ["mib-2.43.16.5.1.2.1.1","mib-2.43.16.5.1.2.1.2","mib-2.43.16.5.1.2.1.3","mib-2.43.16.5.1.2.1.4","mib-2.43.16.5.1.2.1.5"]
27
    try:
bobot's avatar
bobot committed
28
        comm = hptools.snmp(host="laserjet.adm.crans.org",version="1",community="public")
29
        liste_msg = []
30
        for oid in liste_oid:
31
            msg = comm.get_string(oid).decode("ISO-8859-1")
32
33
            msg = dico.get(msg, msg).encode("ISO-8859-1")
            if msg: liste_msg.append(msg)
34
    except Exception,err:
35
36
        liste_msg.append("[%s]" % unicode(err))
    return liste_msg
37
38

def enregistre(filename="/usr/script/impression/imprimante.etat"):
bobot's avatar
bobot committed
39
    l = etat()
40
41
42
43
    fichier = open(filename,'w')
    for x in l:
        fichier.write(x+"\n")
    fichier.close()