From 20a6ee6afb6a1243a62d4b30b6fb43e141efbc89 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Sun, 24 Aug 2014 17:56:19 +0200 Subject: [PATCH] =?UTF-8?q?homes:=20plus=20de=20g=C3=A9n=C3=A9ricit=C3=A9?= =?UTF-8?q?=20&=20/home-adh/x/xlogin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/forward.py | 4 ++-- gestion/ldap_crans.py | 5 ++--- gestion/whos.py | 2 +- utils/robots_perso.py | 7 ++++--- wiki/macro/PagesClubs.py | 4 ++-- wiki/macro/PagesPerso.py | 7 ++++--- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/gestion/forward.py b/gestion/forward.py index fb7376d1..34c8d9fa 100755 --- a/gestion/forward.py +++ b/gestion/forward.py @@ -32,13 +32,13 @@ import lc_ldap.filter2 as filter if __name__ == '__main__': # Lecture de la redirection courante def redirection_read(uid): - forward = open('/home/%s/.forward' %uid ,'r') + forward = open(os.path.expanduser('~%s/.forward' %uid) ,'r') print forward.read() forward.close() return # Modification de la redirection def redirection_write(ligne,uid): - forward = open('/home/%s/.forward' %uid ,'w') + forward = open(os.path.expanduser('~%s/.forward' %uid),'w') forward.write('%s' %ligne) forward.close() return diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 6934fdd7..2a27fdc6 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -2538,8 +2538,7 @@ class Adherent(BaseProprietaire): if mailexist(login): raise ValueError(u"Login existant ou correspondant à un alias mail.", 1) - # b2moo: à fixer pour les homes - home = '/home/' + login + home = '/home/%s/%s' % (login[0], login) if os.path.exists(home): raise ValueError(u'Création du compte impossible : home existant', 1) @@ -2877,7 +2876,7 @@ class Club(BaseProprietaire): # la 2ème vérif est pour vérifier que ce n'est pas la ML du club raise ValueError(u"Login existant ou correspondant à un alias mail.", 1) - home = '/home/' + login.replace('-', '/', 1) + home = '/home/%s/%s' % (login[0], login.replace('-', '/', 1)) if os.path.exists(home): raise ValueError(u'Création du compte impossible : home existant', 1) diff --git a/gestion/whos.py b/gestion/whos.py index d9fda381..6de6f2c8 100755 --- a/gestion/whos.py +++ b/gestion/whos.py @@ -488,7 +488,7 @@ def adher_details(adher) : if len(adher.gpgFingerprint()) > 0: f += u"\n".join([coul(u'Fingerprint GPG : ', 'gras') + u"%s" % (i) for i in adher.gpgFingerprint()])+"\n" try: - forward = file("/home/%s/.forward" % adher.compte()).readlines() + forward = file(os.path.join(adher.home(), ".forward")).readlines() if len(forward) > 1: forward = forward[0].strip() + u" ...\n" elif len(forward) == 1: diff --git a/utils/robots_perso.py b/utils/robots_perso.py index 63f4f0bb..32a5e4f8 100755 --- a/utils/robots_perso.py +++ b/utils/robots_perso.py @@ -11,9 +11,10 @@ robots_file = '/usr/scripts/var/perso/robots.txt' robots = collections.defaultdict(lambda:collections.defaultdict(list)) def add_robots(user, robots): - if os.path.exists('/home/%s/www/robots.txt' % user): + robots_path = os.expanduser('~%s/www/robots.txt' % user) + if os.path.exists(robots_path): rp = robotparser.RobotFileParser() - rp.parse(open('/home/%s/www/robots.txt' % user)) + rp.parse(open(robots_path)) for entry in ([rp.default_entry] if rp.default_entry else []) + rp.entries: for user_agent in entry.useragents: for rule in entry.rulelines: @@ -31,7 +32,7 @@ def write_robots(file, robots): f.write("\n") def get_users(): - return os.listdir('/home/') + return os.listdir('/home/mail') if __name__ == '__main__': diff --git a/wiki/macro/PagesClubs.py b/wiki/macro/PagesClubs.py index 603cdabf..a3e47d0d 100644 --- a/wiki/macro/PagesClubs.py +++ b/wiki/macro/PagesClubs.py @@ -10,8 +10,8 @@ class ClubList(PagesPerso.AccountList): def comptes(self): """Retourne la liste des comptes""" - return filter(lambda x: os.path.isdir(u"/home/club/%s" % x) and not os.path.islink(u"/home/club/%s" % x), - os.listdir(u"/home/club")) + return filter(lambda x: os.path.isdir(u"/home/c/club/%s" % x) and not os.path.islink(u"/home/c/club/%s" % x), + os.listdir(u"/home/c/club")) def execute(macro, args): return macro.formatter.rawHTML(ClubList().to_html()) diff --git a/wiki/macro/PagesPerso.py b/wiki/macro/PagesPerso.py index 0f0a6421..aadd678b 100644 --- a/wiki/macro/PagesPerso.py +++ b/wiki/macro/PagesPerso.py @@ -12,8 +12,9 @@ class AccountList: def comptes(self): """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), + return filter(lambda x: os.path.isdir(os.path.expanduser(u"~%s/www" % x)) and not os.path.islink(os.path.expanduser(u"~%s/www" % x)), os.listdir(u"/home/mail")) + ### ^^^^^^ le code m'a tuer def makeAnchor(self,letter): @@ -50,7 +51,7 @@ class Account: def __init__(self, home, login, www, url): """Instanciation avec le `login' de la personne""" self.login = login - self.home = "%s/%s" % (home, login) + self.home = os.path.expanduser("~%s" % login) self.www = www self.url = url @@ -78,7 +79,7 @@ class Account: def chemin(self): """Chemin vers le www""" - return u"%s%s" % (self.home, self.www) + return os.path.join(self.home, self.www) def logo(self): """URL du logo s'il y en a un"""