Gnralisation de l'utilisation de cprint, on abandonne unicode_print qui
fait la mme chose en moins bien. darcs-hash:20060404020734-68412-5c82c3320f0da1c19d7dbea758cc56f0798adf34.gz
This commit is contained in:
parent
496ad05751
commit
41418a4c14
1 changed files with 47 additions and 46 deletions
|
@ -59,10 +59,6 @@ limit_aff_details = 1
|
||||||
limit_aff_historique = 4
|
limit_aff_historique = 4
|
||||||
aff_ipsec = 0
|
aff_ipsec = 0
|
||||||
|
|
||||||
def unicode_print(truc) :
|
|
||||||
""" Conversion de truc en iso-8859-15 puis affichage à l'écran """
|
|
||||||
print truc.encode('iso-8859-15','ignore')
|
|
||||||
|
|
||||||
def aff(qqch,mtech=0) :
|
def aff(qqch,mtech=0) :
|
||||||
""" Affichage de qqch.
|
""" Affichage de qqch.
|
||||||
qqch peut être une liste d'instances des classes adhérent ou machine
|
qqch peut être une liste d'instances des classes adhérent ou machine
|
||||||
|
@ -79,25 +75,29 @@ def aff(qqch,mtech=0) :
|
||||||
|
|
||||||
if len(qqch) > limit_aff_details :
|
if len(qqch) > limit_aff_details :
|
||||||
t = qqch[0].idn
|
t = qqch[0].idn
|
||||||
if t == 'aid' :
|
if t == 'aid':
|
||||||
unicode_print(adhers_brief(qqch))
|
cprint(adhers_brief(qqch))
|
||||||
elif t == 'mid' :
|
elif t == 'mid':
|
||||||
if mtech : unicode_print(list_machines(qqch))
|
if mtech:
|
||||||
else : unicode_print(machines_brief(qqch))
|
cprint(list_machines(qqch))
|
||||||
elif t == 'cid' :
|
else:
|
||||||
unicode_print(clubs_brief(qqch))
|
cprint(machines_brief(qqch))
|
||||||
|
elif t == 'cid':
|
||||||
|
cprint(clubs_brief(qqch))
|
||||||
else :
|
else :
|
||||||
i = 0
|
i = 0
|
||||||
for c in qqch :
|
for c in qqch :
|
||||||
t = c.idn
|
t = c.idn
|
||||||
if i : print coul(u'='*80,'cyan')
|
if i: cprint(u'='*80, 'cyan')
|
||||||
i = 1
|
i = 1
|
||||||
if t == 'aid' : unicode_print(adher_details(c))
|
if t == 'aid':
|
||||||
elif t == 'mid' :
|
cprint(adher_details(c).strip())
|
||||||
unicode_print(machine_details(c))
|
elif t == 'mid':
|
||||||
elif t == 'cid' : unicode_print(club_details(c))
|
cprint(machine_details(c).strip())
|
||||||
|
elif t == 'cid':
|
||||||
|
cprint(club_details(c).strip())
|
||||||
if len(qqch) > 1:
|
if len(qqch) > 1:
|
||||||
print u"Total: %d" % len(qqch)
|
cprint(u"Total: %d" % len(qqch))
|
||||||
|
|
||||||
def adhers_brief(adhers) :
|
def adhers_brief(adhers) :
|
||||||
"""
|
"""
|
||||||
|
@ -866,7 +866,7 @@ def prise_etat(chbre) :
|
||||||
def __usage_brief(err='') :
|
def __usage_brief(err='') :
|
||||||
""" Message d'erreur """
|
""" Message d'erreur """
|
||||||
if err : cprint(err,'gras')
|
if err : cprint(err,'gras')
|
||||||
print u"Pour obtenir de l'aide sur l'utilisation de ce programme utilisez l'option -h"
|
cprint(u"Pour obtenir de l'aide sur l'utilisation de ce programme utilisez l'option -h")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
def __usage() :
|
def __usage() :
|
||||||
|
@ -912,10 +912,10 @@ def __usage() :
|
||||||
# Dernière ligne
|
# Dernière ligne
|
||||||
liste.append(accu)
|
liste.append(accu)
|
||||||
|
|
||||||
print __doc__ % { 'prog' : sys.argv[0].split('/')[-1].split('.')[0] ,
|
cprint(__doc__ % { 'prog': sys.argv[0].split('/')[-1].split('.')[0],
|
||||||
'champs_rech' : '\n'.join(liste) ,
|
'champs_rech': '\n'.join(liste),
|
||||||
'limit_aff_details' : limit_aff_details ,
|
'limit_aff_details': limit_aff_details,
|
||||||
'limit_aff_historique' : limit_aff_historique }
|
'limit_aff_historique': limit_aff_historique })
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def __recherche() :
|
def __recherche() :
|
||||||
|
@ -960,20 +960,20 @@ def __recherche() :
|
||||||
__usage_brief('Valeur du paramètre %s incorecte (doit être un entier positif)' % opt)
|
__usage_brief('Valeur du paramètre %s incorecte (doit être un entier positif)' % opt)
|
||||||
elif opt in [ '-a', '--adherent' ] :
|
elif opt in [ '-a', '--adherent' ] :
|
||||||
only_adh = 1
|
only_adh = 1
|
||||||
print "Affichage limité aux adhérents."
|
cprint(u"Affichage limité aux adhérents.")
|
||||||
elif opt in [ '-m', '--machine' ] :
|
elif opt in [ '-m', '--machine' ] :
|
||||||
only_mac = 1
|
only_mac = 1
|
||||||
print "Affichage limité aux machines."
|
cprint(u"Affichage limité aux machines.")
|
||||||
elif opt in [ '-c', '--club' ] :
|
elif opt in [ '-c', '--club' ] :
|
||||||
only_club = 1
|
only_club = 1
|
||||||
print "Affichage limité aux clubs."
|
cprint(u"Affichage limité aux clubs.")
|
||||||
elif opt == '--crans' :
|
elif opt == '--crans' :
|
||||||
only_crans = 1
|
only_crans = 1
|
||||||
mtech = 1
|
mtech = 1
|
||||||
print "Affichage limité aux machines du crans."
|
cprint(u"Affichage limité aux machines du crans.")
|
||||||
elif opt in [ '-b', '--bornes' ] :
|
elif opt in [ '-b', '--bornes' ] :
|
||||||
only_bornes = 1
|
only_bornes = 1
|
||||||
print "Affichage limité aux bornes wifi."
|
cprint(u"Affichage limité aux bornes wifi.")
|
||||||
# On va tenter de limiter un peu la recherche
|
# On va tenter de limiter un peu la recherche
|
||||||
if not arg :
|
if not arg :
|
||||||
# Recherche initiale sans critère
|
# Recherche initiale sans critère
|
||||||
|
@ -1007,11 +1007,11 @@ def __recherche() :
|
||||||
|
|
||||||
if chbre:
|
if chbre:
|
||||||
if len(chbre) != 1 :
|
if len(chbre) != 1 :
|
||||||
print u"Prise correspondante à plusieurs chambres %s " % ' '.join(chbre)
|
cprint(u"Prise correspondante à plusieurs chambres %s" % ' '.join(chbre))
|
||||||
return
|
return
|
||||||
# On fait la recherche sur la chambre
|
# On fait la recherche sur la chambre
|
||||||
chbre= prise[0] + chbre[0]
|
chbre= prise[0] + chbre[0]
|
||||||
#print u"Recherche sur chambre %s" % chbre
|
#cprint(u"Recherche sur chambre %s" % chbre)
|
||||||
arg = 'chbre=%s' % chbre
|
arg = 'chbre=%s' % chbre
|
||||||
# sinon on ne fait rien et on recherche sur le champ prise
|
# sinon on ne fait rien et on recherche sur le champ prise
|
||||||
|
|
||||||
|
@ -1033,18 +1033,18 @@ def __recherche() :
|
||||||
if arg.count('=') == 1 and arg.split('=')[0] == 'chbre' :
|
if arg.count('=') == 1 and arg.split('=')[0] == 'chbre' :
|
||||||
# Affichage des infos de la chambre
|
# Affichage des infos de la chambre
|
||||||
chbre = arg.split('=')[1]
|
chbre = arg.split('=')[1]
|
||||||
print u"Chambre %s inoccupée ou invalide (%s)" % (chbre,prise_etat(chbre))
|
cprint(u"Chambre %s inoccupée ou invalide (%s)" % (chbre,prise_etat(chbre)))
|
||||||
else :
|
else :
|
||||||
print u"Aucun résultat trouvé."
|
cprint(u"Aucun résultat trouvé.")
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
# L'affichage souhaité a été précisé ?
|
# L'affichage souhaité a été précisé ?
|
||||||
elif only_bornes :
|
elif only_bornes :
|
||||||
if not res['machine'] :
|
if not res['machine'] :
|
||||||
print 'Aucun résultat à afficher'
|
cprint(u'Aucun résultat à afficher')
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
else :
|
else :
|
||||||
if len(res['machine']) > limit_aff_details :
|
if len(res['machine']) > limit_aff_details :
|
||||||
unicode_print(list_bornes(res['machine']))
|
cprint(list_bornes(res['machine']))
|
||||||
else :
|
else :
|
||||||
aff(res['machine'])
|
aff(res['machine'])
|
||||||
elif only_adh :
|
elif only_adh :
|
||||||
|
@ -1058,11 +1058,11 @@ def __recherche() :
|
||||||
traite.append(a.id())
|
traite.append(a.id())
|
||||||
to_aff.append(m.proprietaire())
|
to_aff.append(m.proprietaire())
|
||||||
if not(to_aff) :
|
if not(to_aff) :
|
||||||
print 'Aucun résultat à afficher'
|
cprint(u'Aucun résultat à afficher')
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
aff(to_aff)
|
aff(to_aff)
|
||||||
elif res['club'] :
|
elif res['club'] :
|
||||||
print 'Aucun résultat à afficher'
|
cprint(u'Aucun résultat à afficher')
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
elif only_mac :
|
elif only_mac :
|
||||||
if res['machine'] : aff(res['machine'],mtech)
|
if res['machine'] : aff(res['machine'],mtech)
|
||||||
|
@ -1083,22 +1083,22 @@ def __recherche() :
|
||||||
traite.append(a.id())
|
traite.append(a.id())
|
||||||
to_aff.append(m.proprietaire())
|
to_aff.append(m.proprietaire())
|
||||||
if not(to_aff) :
|
if not(to_aff) :
|
||||||
print 'Aucun résultat à afficher'
|
cprint(u'Aucun résultat à afficher')
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
aff(to_aff)
|
aff(to_aff)
|
||||||
elif res['adherent'] :
|
elif res['adherent'] :
|
||||||
print 'Aucun résultat à afficher'
|
cprint(u'Aucun résultat à afficher')
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
# Non : on affiche tout.
|
# Non : on affiche tout.
|
||||||
else :
|
else :
|
||||||
if res['adherent'] :
|
if res['adherent'] :
|
||||||
cprint("Résultats trouvés parmi les adhérents :",'cyan')
|
cprint(u"Résultats trouvés parmi les adhérents :", 'cyan')
|
||||||
aff(res['adherent'])
|
aff(res['adherent'])
|
||||||
if res['machine'] :
|
if res['machine'] :
|
||||||
cprint("Résultats trouvés parmi les machines :",'cyan')
|
cprint(u"Résultats trouvés parmi les machines :", 'cyan')
|
||||||
aff(res['machine'],mtech)
|
aff(res['machine'],mtech)
|
||||||
if res['club']:
|
if res['club']:
|
||||||
cprint("Résultats trouvés parmi les clubs :",'cyan')
|
cprint(u"Résultats trouvés parmi les clubs :", 'cyan')
|
||||||
aff(res['club'])
|
aff(res['club'])
|
||||||
|
|
||||||
if __name__ == '__main__' :
|
if __name__ == '__main__' :
|
||||||
|
@ -1112,19 +1112,20 @@ if __name__ == '__main__' :
|
||||||
try :
|
try :
|
||||||
__recherche()
|
__recherche()
|
||||||
except KeyboardInterrupt :
|
except KeyboardInterrupt :
|
||||||
print "Recherche interrompue par l'utilisateur."
|
cprint(u"Recherche interrompue par l'utilisateur.")
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
except SystemExit, c :
|
except SystemExit, c :
|
||||||
# Fin
|
# Fin
|
||||||
sys.exit(c)
|
sys.exit(c)
|
||||||
except :
|
except :
|
||||||
print """Une erreur fatale s'est produite durant l'exécution.
|
cprint(u"""Une erreur fatale s'est produite durant l'exécution.
|
||||||
Pour l'amélioration de ce programme merci de prévenir nounou en spécifiant la
|
Pour l'amélioration de ce programme merci de prévenir nounou en spécifiant la
|
||||||
marche à suivre pour reproduire cette erreur."""
|
marche à suivre pour reproduire cette erreur.""")
|
||||||
if debug :
|
if debug :
|
||||||
print '-'*40
|
cprint('-'*40)
|
||||||
print 'Détails techniques :'
|
cprint(u'Détails techniques :')
|
||||||
import traceback
|
import traceback
|
||||||
|
# On veut le traceback sur la sortie standard
|
||||||
|
sys.stderr = sys.stdout
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue