
il ne faut pas utiliser les balises dans le contenu darcs-hash:20060514195706-72cb0-46d7af235b40b334380067ed96672a543f0908dd.gz
87 lines
2.9 KiB
Python
87 lines
2.9 KiB
Python
# -*- encoding: iso-8859-15 -*-
|
|
|
|
import os
|
|
|
|
class account:
|
|
"""Classe représentant la page perso d'une personne"""
|
|
|
|
home = "/home"
|
|
www = "/www"
|
|
|
|
def __init__(self, login):
|
|
"""Instanciation avec le `login' de la personne"""
|
|
self.login = login
|
|
self.home = "%s/%s" % (self.home, login)
|
|
|
|
_info = None
|
|
def info(self, champ):
|
|
"""Retourne le contenu du champ `champ' dans le fichier info"""
|
|
if self._info == None:
|
|
try:
|
|
lignes = file("%s/.info" % self.home)
|
|
except IOError:
|
|
lignes = []
|
|
|
|
# self._info est un dictionnaire qui reprend le contenu du .info
|
|
self._info = dict(map(lambda z: (unicode(z[0].lower(),"iso-8859-15"),
|
|
unicode(z[1],"iso-8859-15")),
|
|
filter(lambda w: len(w) == 2 and len(w[1]),
|
|
map(lambda x: map(lambda y: y.strip(),
|
|
x.split(":")),
|
|
lignes))))
|
|
print self._info
|
|
|
|
if self._info.has_key(champ.lower()):
|
|
return self._info[champ.lower()]
|
|
else:
|
|
return u""
|
|
|
|
def chemin(self):
|
|
"""Chemin vers le www"""
|
|
return u"%s%s" % (self.home, self.www)
|
|
|
|
def url(self):
|
|
"""URL vers la page perso"""
|
|
return u"http://perso.crans.org/%s/" % self.login
|
|
|
|
def logo(self):
|
|
"""URL du logo s'il y en a un"""
|
|
if self.info("logo"):
|
|
# Le logo peut être en absolu ou en relatif
|
|
if self.info("logo").startswith(self.chemin()):
|
|
logo = self.info("logo").replace("%s/" % self.chemin(), "")
|
|
else:
|
|
logo = self.info("logo")
|
|
if os.path.isfile("%s/%s" % (self.chemin(), logo)):
|
|
return u"%s%s" % (self.url(), logo)
|
|
return u"http://perso.crans.org/pageperso.png"
|
|
|
|
def __str__(self):
|
|
"""Renvoie le code HTML correspondant au fichier .info"""
|
|
html = [ u'<div class="vignetteperso">',
|
|
u'<a href="%s">' % self.url(),
|
|
u'<img src="%s" alt="%s">' % (self.logo(), self.login),
|
|
u'</a><br>',
|
|
self.info("nom") and u'<b>%s</b><br>' % self.info("nom") or u'%s<br>' % self.login,
|
|
self.info("devise") and u'<i>%s</i>' % self.info("devise") or u'',
|
|
u'</div>' ]
|
|
return u'\n'.join(html)
|
|
|
|
def comptes():
|
|
"""Retourne la liste des comptes"""
|
|
return filter(lambda x: os.path.isdir(u"/home/%s/www" % x) and not os.path.islink(u"/home/%s/www" % x),
|
|
os.listdir(u"/home"))
|
|
|
|
|
|
def execute(macro, args):
|
|
dirs = comptes()
|
|
dirs.sort()
|
|
|
|
html = u""
|
|
|
|
|
|
for d in dirs:
|
|
html = u"%s\n%s" % (html, account(d).__str__())
|
|
|
|
html += u'<br style="clear: both">'
|
|
return html
|