Commit 8735c2d5 authored by Lorenz Steinert's avatar Lorenz Steinert

beginging to move functions to own module

parent 231325f1
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 24 15:35:04 2017
@author: Lorenz Steinert
"""
import re
import os
import codecs
import ldap3 as ldap
try:
import pwd
except ImportError:
import getpass
pwd = None
def current_user():
"""get the current user"""
if pwd:
return pwd.getpwuid(os.geteuid()).pw_name
return getpass.getuser()
class esme:
"""Class die die protokoll .tex datei erstellt"""
def __init__(self, debug, timeout):
self.debug = debug
self.server = ldap.Server("rincewind.fs.physik.uni-kl.de", connect_timeout=timeout)
self.base = "dc=fs,dc=physik,dc=uni-kl,dc=de"
def get_protokollant_ldap(self, protokollant):
"""search the LDAP for the current user"""
print("Fetching Protokollant from LDAP ...")
try:
conn = ldap.Connection(self.server)
conn.bind()
fil = "(uid="+current_user()+")"
if conn.search('ou=people,'+self.base, fil, attributes=['displayName']):
return " ".join(str(conn.entries[0]['displayName']).split(", ")[::-1])
return protokollant
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
print("Couldn't Connect to ldap.\nUsing fallback default.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback default.\n")
return protokollant
def get_fsr_ldap(self, fsr):
"""get fsr from LDAP"""
print("Fetching FSR from LDAP ...")
try:
conn = ldap.Connection(self.server)
conn.bind()
fil = '(cn=intern)'
fsr_ = []
if conn.search('ou=group,'+self.base, fil,
attributes=['memberUid']):
for i in conn.entries[0]['memberUid']:
if conn.search('ou=people,' + self.base,
'(uid='+i+')', attributes=['displayName']):
fsr_ += [str(conn.entries[0]['displayName'])]
fsr_.sort()
fsr_ = [" ".join(i.split(', ')[::-1]) for i in fsr_]
return fsr_
return fsr
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
print("Couldn't Connect to ldap.\nUsing fallback File.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback File.\n")
return fsr
def get_fsr_extern_ldap(self, fsr_extern):
"""get the EFSR from LDAP"""
print("Fetching EFSR from LDAP ...")
try:
conn = ldap.Connection(self.server)
conn.bind()
fil = '(cn=extern)'
fsr_extern_ = []
if conn.search('ou=group,'+self.base, fil,
attributes=['memberUid']):
for i in conn.entries[0]['memberUid']:
if conn.search('ou=people,' + self.base,
'(uid='+i+')', attributes=['displayName']):
fsr_extern_ += [str(conn.entries[0]['displayName'])]
fsr_extern_.sort()
fsr_extern_ = [" ".join(i.split(', ')[::-1]) for i in fsr_extern_]
return fsr_extern_
return fsr_extern
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
print("Couldn't Connect to ldap.\nUsing fallback File.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback File.\n")
return fsr_extern
def get_sprecher(sprecher):
"""get sprecher from user input"""
stmp = input("Sprecher ["+sprecher+"]: ")
if stmp != "":
return stmp
return sprecher
def get_protokollant(protokollant):
"""get protokollant from user input"""
ptmp = input("Protokollant ["+protokollant+"]: ")
if ptmp != "":
return ptmp
return protokollant
def get_date(date):
"""get date from user input"""
dtmp = input("Datum ["+date[0]+"]: ")
if dtmp != "":
day, mon, year = dtmp.split('.')
if len(mon) < 2: mon = "0" + mon
if len(day) < 2: day = "0" + day
date = day + "." + mon + "." + year
return (date, year, mon, day)
return date
def get_editor(editor):
"""get the editor to use from user input"""
etmp = input("Editor ["+editor+"]: ")
if etmp != "":
return etmp
return editor
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