Dans affich_tools, tableau_ng remplace dornavant tableau.
darcs-hash:20060326160011-68412-d87c57d6e2edf22dd78fd5c78e07793a19421ff5.gz
This commit is contained in:
parent
821905a295
commit
7428178ab9
5 changed files with 101 additions and 123 deletions
|
@ -86,62 +86,17 @@ ERREUR = coul('ERREUR','rouge')
|
|||
def cprint(txt,col):
|
||||
print coul(txt,col)
|
||||
|
||||
def tableau(largeurs,data) :
|
||||
"""
|
||||
retourne une chaine formatée repésentant un tableau
|
||||
largeur est la liste des largeurs des colones
|
||||
data est une liste de tuples :
|
||||
[ ( données entète), (données ligne1), .... ]
|
||||
"""
|
||||
sep_col = u'|'
|
||||
|
||||
# Si l'une des largeurs est '*', alors on la met la plus grande possible
|
||||
if '*' in largeurs:
|
||||
rows, cols = get_screen_size()
|
||||
nlargeurs = []
|
||||
for n in largeurs:
|
||||
if n != '*':
|
||||
nlargeurs.append(n)
|
||||
else:
|
||||
nlargeurs.append(max(cols - sum(filter(lambda x:x!='*',largeurs)) - len(largeurs) - 1, 3))
|
||||
largeurs = nlargeurs
|
||||
|
||||
# Ligne de séparation entète corps
|
||||
s=u'\n'
|
||||
for l in largeurs :
|
||||
s+= sep_col + u'-'*l
|
||||
s += sep_col + u'\n'
|
||||
|
||||
nb_cols = len(largeurs)
|
||||
|
||||
# Remplissage tableau
|
||||
f=u''
|
||||
for ligne in data :
|
||||
for i in range(0, nb_cols) :
|
||||
f+= sep_col
|
||||
# Centrage
|
||||
l = len(sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',ligne[i])) # Longeur sans les chaines de formatage
|
||||
if l >= largeurs[i] :
|
||||
f += ligne[i]
|
||||
else :
|
||||
n = largeurs[i] - l
|
||||
f += u' '*(n/2) + ligne[i] + u' '*(n/2 + n%2)
|
||||
f+= sep_col + u'\n'
|
||||
|
||||
# Final
|
||||
f = f.replace(u'\n',s,1) # Insertion du séparateur entète - corps
|
||||
return f[:-1] # Supression du \n final
|
||||
|
||||
def tableau_ng(data,titre=None,largeur=None,alignement=None,format=None) :
|
||||
def tableau(data, titre=None, largeur=None, alignement=None, format=None):
|
||||
"""
|
||||
Retourne une chaine formatée repésentant un tableau
|
||||
Retourne une chaine formatée repésentant un tableau.
|
||||
|
||||
data : liste de listes, chacune contenant les valeurs d'une ligne
|
||||
data : liste de listes, chacune contenant les valeurs d'une ligne
|
||||
|
||||
titre : liste des titres
|
||||
titre : liste des titres
|
||||
Si none, n'affiche pas de ligne de titre
|
||||
|
||||
largeur : liste des largeurs des colonnes, '*' met la plus grande
|
||||
largeur : liste des largeurs des colonnes, '*' met la plus grande
|
||||
largeur possible.
|
||||
Si None, réduit aux max chaque colonne
|
||||
|
||||
|
@ -150,7 +105,7 @@ def tableau_ng(data,titre=None,largeur=None,alignement=None,format=None) :
|
|||
d = droit
|
||||
Si None, met c pour chaque colonne
|
||||
|
||||
format : liste des formats : s = string
|
||||
format : liste des formats : s = string
|
||||
o = octet
|
||||
Si None, s pour chaque colonne
|
||||
"""
|
||||
|
@ -167,20 +122,20 @@ def tableau_ng(data,titre=None,largeur=None,alignement=None,format=None) :
|
|||
if not format :
|
||||
format = ['s'] * nbcols
|
||||
|
||||
def reformate (data, format) :
|
||||
if format == 's' :
|
||||
return str(data)
|
||||
def reformate(data, format):
|
||||
if format == 's':
|
||||
return unicode(data)
|
||||
|
||||
elif format == 'o' :
|
||||
data = float(data)
|
||||
if data > 1024**3 :
|
||||
return str(round(data/1024**3,1))+'Go'
|
||||
elif data > 1024**2 :
|
||||
return str(round(data/1024**2,1))+'Mo'
|
||||
elif data > 1024 :
|
||||
return str(round(data/1024,1))+'ko'
|
||||
else :
|
||||
return str(round(data,1))+'o'
|
||||
if data > 1024**3:
|
||||
return str(round(data/1024**3, 1)) + 'Go'
|
||||
elif data > 1024**2:
|
||||
return str(round(data/1024**2, 1)) + 'Mo'
|
||||
elif data > 1024:
|
||||
return str(round(data/1024, 1)) + 'ko'
|
||||
else:
|
||||
return str(round(data, 1)) + 'o'
|
||||
|
||||
data = [ [ reformate(ligne[i],format[i]) for i in range(nbcols) ] for ligne in data ]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue