Commit afceae75 authored by Lorenz Steinert's avatar Lorenz Steinert

rewrote the get_protokollant functions

parent c81840c9
......@@ -24,6 +24,7 @@ except ImportError:
class Error(Flag):
"""Error constants for the FsrLdap class"""
UNSEC_SEARCH = auto()
NO_FILE = auto()
LDAP_FAIL = auto()
......@@ -52,7 +53,7 @@ class FsrLdap:
"""Class die die protokoll .tex datei erstellt"""
def __init__(self, server, base, share_dir, debug=False, timeout=1, testing=None):
def __init__(self, server, base, share_dir, config, debug=False, timeout=1, testing=None):
self.debug = debug
self.server = ldap.Server(server,
......@@ -64,8 +65,9 @@ class FsrLdap:
self.conn.bind()
self.base = base
self.share_dir = share_dir
self.config = config
def get_protokollant_ldap(self, config):
def _get_protokollant_ldap(self):
"""search the LDAP for the current user"""
logging.info("Fetching Protokollant from LDAP ...")
try:
......@@ -74,14 +76,40 @@ class FsrLdap:
attributes=['displayName']):
logging.info("Done")
return " ".join(str(self.conn.entries[0]['displayName']).split(", ")[::-1])
return get_protokollant(config)
return Error.UNSEC_SEARCH
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
logging.warning("Couldn't Connect to ldap. \
Using fallback default.%s" % error_message)
Using fallback default. %s" % error_message)
else:
logging.warning("Couldn't Connect to ldap. Using fallback default.")
return get_protokollant(config)
return Error.LDAP_FAIL
@staticmethod
def _get_fallback_protokollant(config=None):
"""get protokollant from user input or config"""
protokollant = ''
if config:
protokollant = config['PROTOKOLL']['Protokollant']
ptmp = input("Protokollant ["+protokollant+"]: ")
if ptmp != "":
return ptmp
return protokollant
def get_protokollant(self, config=None):
"""get protokollant"""
if not config:
config = self.config
protokollant = self._get_protokollant_ldap()
if isinstance(protokollant, tuple):
pass
protokollant = protokollant[0]
if protokollant == Error.UNSEC_SEARCH | Error.LDAP_FAIL:
protokollant = self._get_fallback_protokollant(config)
if protokollant == Error.NO_FILE:
protokollant = ""
return protokollant
def _get_fsr_ldap(self):
"""get fsr from LDAP"""
......@@ -199,15 +227,6 @@ def get_sprecher(config=None):
return sprecher
def get_protokollant(config=None):
"""get protokollant from user input or config"""
protokollant = ''
if config:
protokollant = config['PROTOKOLL']['Protokollant']
ptmp = input("Protokollant ["+protokollant+"]: ")
if ptmp != "":
return ptmp
return protokollant
def get_date(test=False):
......@@ -331,7 +350,8 @@ def get_ldap_base(config=None, base=None):
return base
if config:
return config['SERVER']['BASE']
logging.warning('No LDAP search base supplied. Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".')
logging.warning('No LDAP search base supplied. ' \
'Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".')
return "dc=fs,dc=physik,dc=uni-kl,dc=de"
......
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