From c0054a070c568ea0068d866da4dbeb40d15320eb Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Mon, 18 Nov 2013 00:44:48 +0100 Subject: [PATCH] =?UTF-8?q?[cimetiere]=20Le=20module=20cimetiere=20est=20s?= =?UTF-8?q?tateless=20et=20ne=20d=C3=A9pend=20pas=20d'une=20connection=20l?= =?UTF-8?q?dap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On ajoute une fonction ppour chercher dans le cimetière à la classe lc_ldap : gravedig --- cimetiere.py | 13 +++++-------- lc_ldap.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cimetiere.py b/cimetiere.py index ae25cf1..0029684 100644 --- a/cimetiere.py +++ b/cimetiere.py @@ -1,12 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import os - -import shortcuts +import lc_ldap import filter2 as filter -conn=shortcuts.lc_ldap_admin() - cimetiere_root = '/home/cimetiere_lc' def find_in_filter(lf, key): @@ -24,9 +21,9 @@ def find_in_filter(lf, key): def valide_filter(lf, ldif): if lf: if lf[0] == '=': - return True if [i for i in ldif.get(lf[1], [lf[2]]) if lf[2] in i] else False + return True if [i for i in ldif.get(lf[1], [lf[2]]) if lf[2].lower() in i.lower()] else False elif lf[0] == '!=': - return False if [i for i in ldif.get(lf[1], []) if lf[2] in i] else True + return False if [i for i in ldif.get(lf[1], []) if lf[2].lower() in i.lower()] else True elif lf[0] == '|': return reduce(lambda x,y: x or y, [valide_filter(i, ldif) for i in lf[1:]] + [False, False]) elif lf[0] == '&': @@ -47,7 +44,7 @@ def condition((fdate, ftime, fdn, path), date=None, aid=None, mid=None, fl=None) if not ("mid=%s," % mid) in fdn: return False if fl: - (dn, ldif)= conn.ressuscite_build_ldif(path) + (dn, ldif)= lc_ldap.lc_ldap.ressuscite_build_ldif(path) return valide_filter(fl, ldif) return True @@ -68,5 +65,5 @@ def find(type, fl=None, date=None): name=os.path.basename(file) (fdate, time, dn) = name.split('_') if condition((fdate, time, dn, file), fl=fl, aid=aid, mid=mid, date=date): - valid.append(conn.ressuscite(file)) + valid.append(file) return valid diff --git a/lc_ldap.py b/lc_ldap.py index bb30a42..b0a5d06 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -44,6 +44,7 @@ import ldap ## import locaux import crans_utils import attributs +import cimetiere import objets import ldap_locks import variables @@ -124,7 +125,15 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): self.droits = [] self._username_given = user - def ressuscite_build_ldif(self, ldif_file): + def gravedig(self, type, filter=None, date=None): + """Cherche dans le cimetière un objet de type ``type``, + correspondant au filtre ``filter`` entre les dates ``date[0]`` et ``date[1]`` + où la date est de la forme YYYY-MM-JJ ou - pour l'infini""" + valid=cimetiere.find(type, filter, date) + return [self.ressuscite(item) for item in valid] + + @staticmethod + def ressuscite_build_ldif(ldif_file): ldif={} for line in open(ldif_file).readlines(): line = line.split(':',1)