Commit bc8b47da authored by Lorenz Steinert's avatar Lorenz Steinert

fixed some bugs

parent 1b840d2e
......@@ -26,13 +26,13 @@ if __name__ == "__main__":
SHARE_DIR = get_share(RUNDIR, CONFIG, OPT.sharedir)
LDAP_SERVER = get_ldap_server(CONFIG, OPT.server)
LDAP_SERVER = get_ldap_server(CONFIG, OPT.Server)
LDAP_SERVER_BASE = get_ldap_base(CONFIG, OPT.base)
ESME = FsrLdap(LDAP_SERVER, LDAP_SERVER_BASE, debug=True, timeout=30)
FSR = ESME.get_fsr_ldap([])
FSR_EXTERN = ESME.get_fsr_extern_ldap([])
FSR = ESME.get_fsr_ldap(gen_fallback=True)
FSR_EXTERN = ESME.get_fsr_extern_ldap(gen_fallback=True)
fsr_out = ""
fsr_extern_out = ""
......
......@@ -57,7 +57,7 @@ class FsrLdap:
print("Couldn't Connect to ldap.\nUsing fallback default.\n")
return get_protokollant(config)
def get_fsr_ldap(self, share_dir):
def get_fsr_ldap(self, share_dir=None, gen_fallback=False):
"""get fsr from LDAP"""
print("Fetching FSR from LDAP ...")
try:
......@@ -74,16 +74,20 @@ class FsrLdap:
fsr.sort()
fsr = [" ".join(i.split(', ')[::-1]) for i in fsr]
return fsr
return get_fallback_fsr(share_dir)
if not gen_fallback:
return get_fallback_fsr(share_dir)
print("Could not fetch from LDAP Server. Aborting.")
sys.exit(1)
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
print("Couldn't Connect to ldap.\n \
Using fallback File.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback File.\n")
return get_fallback_fsr(share_dir)
if not gen_fallback:
return get_fallback_fsr(share_dir)
def get_fsr_extern_ldap(self, share_dir):
def get_fsr_extern_ldap(self, share_dir=None, gen_fallback=False):
"""get the EFSR from LDAP"""
print("Fetching EFSR from LDAP ...")
try:
......@@ -100,14 +104,18 @@ class FsrLdap:
fsr_extern.sort()
fsr_extern = [" ".join(i.split(', ')[::-1]) for i in fsr_extern]
return fsr_extern
return get_fallback_fsr_extern(share_dir)
if not gen_fallback:
return get_fallback_fsr_extern(share_dir)
print("Could not fetch from LDAP Server. Aborting")
sys.exit(1)
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
print("Couldn't Connect to ldap.\n \
Using fallback File.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback File.\n")
return get_fallback_fsr_extern(share_dir)
if not gen_fallback:
return get_fallback_fsr_extern(share_dir)
def get_fallback_fsr(share_dir):
......
......@@ -174,7 +174,7 @@ if __name__ == "__main__":
CONFIG = get_config(RUNDIR, OPT.config)
SHARE_DIR = get_share(RUNDIR, CONFIG, OPT.sharedir)
LDAP_SERVER = get_ldap_server(CONFIG, OPT.server)
LDAP_SERVER = get_ldap_server(CONFIG, OPT.Server)
LDAP_SERVER_BASE = get_ldap_base(CONFIG, OPT.base)
SERVER_TIMEOUT = get_server_timeout(CONFIG, OPT.test)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment