Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Blanc
scripts
Commits
f991a7c0
Commit
f991a7c0
authored
Sep 28, 2014
by
Daniel STAN
Browse files
whosthere: affichage plus conçu
parent
ece940a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
gestion/tools/whosthere.py
View file @
f991a7c0
...
...
@@ -10,10 +10,11 @@ import collections
import
os
import
xml.dom.minidom
from
gestion.ldap_crans
import
crans_ldap
from
gestion.ldap_crans
import
crans_ldap
,
MachineWifi
from
gestion.hptools
import
hpswitch
,
ConversationError
from
gestion.affich_tools
import
coul
,
cprint
from
gestion.whos
import
aff
import
gestion.affichage
as
affichage
# Constantes pour munin.
# L'ordre est important : il détermine comment sont empilées les valeurs
...
...
@@ -29,6 +30,36 @@ STATE_DESCR = collections.OrderedDict([
CLUB_CRANS
=
35
CLUB_BDE
=
1
def
pretty_name
(
item
):
v
=
""
if
hasattr
(
item
,
'nom'
):
v
=
item
.
nom
()
if
hasattr
(
item
,
'prenom'
):
v
=
item
.
prenom
()
+
" "
+
v
v
=
v
.
replace
(
'.wifi.crans.org'
,
' (WiFi)'
)
v
=
v
.
replace
(
'.crans.org'
,
''
)
return
v
def
show_liste_by_prop
(
liste
):
by_owner
=
dict
()
for
machine
in
liste
:
# ldap_crans or lc_ldap
owner
=
(
getattr
(
machine
,
'proprietaire'
,
None
)
or
\
getattr
(
machine
,
'proprio'
,
None
))()
if
owner
.
dn
not
in
by_owner
:
by_owner
[
owner
.
dn
]
=
[
pretty_name
(
owner
),
[]]
by_owner
[
owner
.
dn
][
1
].
append
(
pretty_name
(
machine
))
for
items
in
by_owner
.
itervalues
():
items
[
1
]
=
", "
.
join
(
items
[
1
])
print
affichage
.
tableau
(
by_owner
.
values
(),
largeur
=
[
None
,
'*'
],
alignement
=
[
'g'
,
'g'
]).
rstrip
()
def
show_liste
(
liste
):
print
", "
.
join
(
pretty_name
(
m
)
for
m
in
liste
)
def
_mucode
(
u
):
"""Sad but true: munin ne fait pas d'utf-8 …"""
return
u
.
encode
(
'iso-8859-15'
,
errors
=
'ignore'
)
...
...
@@ -120,7 +151,7 @@ class WhosThere(object):
current
=
self
.
query
()
if
current
[
'ma'
]:
cprint
(
'---=== Machines des membres actifs ===---'
,
'bleu'
)
aff
(
current
[
'ma'
])
show_liste_by_prop
(
current
[
'ma'
])
cprint
(
"---=== Il y a du monde ===---"
,
'vert'
)
else
:
cprint
(
"---=== Il semble n'y avoir personne ... ===---"
,
'rouge'
)
...
...
@@ -128,13 +159,13 @@ class WhosThere(object):
cprint
(
"Machine inconnue: %s"
%
mac
,
'rouge'
)
if
current
[
'crans'
]:
cprint
(
"---=== Machines Cr@ns ===---"
,
'bleu'
)
aff
(
current
[
'crans'
])
show_liste
(
current
[
'crans'
])
if
current
[
'bde'
]:
cprint
(
"---=== Machines du BDE ===---"
,
'bleu'
)
aff
(
current
[
'bde'
])
show_liste
(
current
[
'bde'
])
if
current
[
'adh'
]:
cprint
(
"---=== Machines d'adhérents ===---"
,
'bleu'
)
aff
(
current
[
'adh'
])
show_liste_by_prop
(
current
[
'adh'
])
def
munin_config
(
self
):
"""Donne la configuration du graphe munin"""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment