[cimetiere] Le module cimetiere est stateless et ne dépend pas d'une connection ldap
On ajoute une fonction ppour chercher dans le cimetière à la classe lc_ldap : gravedig
This commit is contained in:
parent
2a6f5d6a9a
commit
c0054a070c
2 changed files with 15 additions and 9 deletions
13
cimetiere.py
13
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
|
||||
|
|
11
lc_ldap.py
11
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue