Commit 156f26ff authored by Lorenz Steinert's avatar Lorenz Steinert

added ldap server und base zu den optionen und dem ini-file

parent 4c189b5c
......@@ -31,12 +31,12 @@ def current_user():
class FsrLdap:
"""Class die die protokoll .tex datei erstellt"""
def __init__(self, debug=False, timeout=1):
def __init__(self, server, base, debug=False, timeout=1):
self.debug = debug
self.server = ldap.Server("rincewind.fs.physik.uni-kl.de",
self.server = ldap.Server(server,
connect_timeout=timeout)
self.base = "dc=fs,dc=physik,dc=uni-kl,dc=de"
self.base = base
def get_protokollant_ldap(self, protokollant):
"""search the LDAP for the current user"""
......@@ -270,3 +270,23 @@ def get_path(rundir, config=None, path=None):
print('No Protokoll Directory found at '
+ os.path.abspath(os.path.join(rundir, '../..')))
sys.exit(1)
def get_ldap_server(config=None, server=None):
"""get the ldap server for the fsr lookup"""
if server:
return server
elif config:
return config['SERVER']['NAME']
else:
print("No LDAP Server supplied. Triing to use \"rincwind.fs.physik.uni-kl.de\".")
return "rincewind.fs.physik.uni-kl.de"
def get_ldap_base(config=None, base=None):
"""get the search base for the ldap server"""
if base:
return base
elif config:
return config['SERVER']['BASE']
else:
print("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"
......@@ -12,7 +12,7 @@ import sys
import shutil
import codecs
import argparse
from module.esme import FsrLdap, get_date, get_sprecher, get_config, get_share, get_path
from module.esme import FsrLdap, get_date, get_sprecher, get_config, get_share, get_path, get_ldap_server, get_ldap_base
def build_parser():
......@@ -27,6 +27,8 @@ def build_parser():
parser.add_argument('-p', '--path', help='set the protokoll directory')
parser.add_argument('-c', '--config', help='set the config file')
parser.add_argument('-s', '--sharedir', help='set the share directory')
parser.add_argument('-S', '--Server', help='set the ldap Server')
parser.add_argument('-b', '--base', help='set the ldap Server search base')
return parser.parse_args()
......@@ -63,7 +65,7 @@ def gen_head(share_dir, reg, sprecher, protokollant, date):
f_acroname = ""
f_acro = ""
#look for teh head.tex and abort if it is not found
#look for teh head.tex and abort if it is not found
if os.path.isfile(os.path.join(share_dir, 'head.tex')):
with codecs.open(os.path.join(share_dir, 'head.tex'),
'r', 'utf-8') as fobj_head:
......@@ -84,6 +86,7 @@ def gen_head(share_dir, reg, sprecher, protokollant, date):
return f_head
def resort_fsr(fsr, num_cols=5):
"""resort list for pascal style sorting"""
fsr += [""] * (num_cols - len(fsr) % num_cols)
depth = len(fsr) // num_cols
......@@ -170,6 +173,8 @@ if __name__ == "__main__":
OPT = build_parser()
CONFIG = get_config(RUNDIR, OPT.config)
SHARE_DIR = get_share(RUNDIR, CONFIG, OPT.sharedir)
LDAP_SERVER = get_ldap_server(CONFIG, OPT.server)
LDAP_SERVER_BASE = get_ldap_base(CONFIG, OPT.base)
REG = {'SPR': re.compile('%%SPRECHER'),
'PRO': re.compile('%%PROTOKOLLANT'),
......@@ -187,10 +192,10 @@ if __name__ == "__main__":
#Set the timeout to 1 if we just want to test stuff
if OPT.test:
ESME = FsrLdap(OPT.debug,
ESME = FsrLdap(LDAP_SERVER, LDAP_SERVER_BASE, OPT.debug,
timeout=1)
else:
ESME = FsrLdap(OPT.debug,
ESME = FsrLdap(LDAP_SERVER, LDAP_SERVER_BASE, OPT.debug,
timeout=CONFIG['SERVER'].getint('connect_timeout'))
print("\n")
......
......@@ -8,3 +8,5 @@ share = /home/referate/protokoll/protokollskript/share
[SERVER]
connect_timeout = 10
name = rincewind.fs.phyisk.uni-kl.de
base = 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