Commit 3e3af191 authored by Lorenz Steinert's avatar Lorenz Steinert

put re.compile in a dictionary

parent e3afa750
......@@ -11,8 +11,8 @@ import os
import sys
import shutil
import time
import ldap3 as ldap
import codecs
import ldap3 as ldap
try:
import pwd
......@@ -51,19 +51,18 @@ class Protokollskript:
self.day = "0"+self.day
self.date = self.day+"."+self.mon+"."+self.year
self.userid = current_user()
self.reg_a = re.compile('\"a')
self.reg_o = re.compile('\"o')
self.reg_u = re.compile('\"u')
self.reg_A = re.compile('\"A')
self.reg_O = re.compile('\"O')
self.reg_U = re.compile('\"U')
self.reg_Kovac = re.compile('Kovac')
self.reg_spr = re.compile("%%SPRECHER")
self.reg_prot = re.compile("%%PROTOKOLLANT")
self.reg_date = re.compile("%%DATE")
self.reg_acro = re.compile("%%ACRO")
self.reg_acroname = re.compile("%%ACRONAME")
self.reg_fsrname = re.compile("%%FSRNAME")
self.reg = {'"a': re.compile('\"a'),
'"o': re.compile('\"o'),
'"u': re.compile('\"u'),
'"A': re.compile('\"A'),
'"O': re.compile('\"U'),
'Kovac': re.compile('Kovac'),
'SPR': re.compile('%%SPRECHER'),
'PRO': re.compile('%%PROTOKOLLANT'),
'DATE': re.compile('%%DATE'),
'ACRO': re.compile('%%ACRO'),
'ACRON': re.compile('%%ACRONAME'),
'FSRN': re.compile('%%FSRNAME')}
self.fsr = sorted([re.sub(re.escape('\t'), ' ', line.rstrip('\n'))
for line in codecs.open('./fsr', 'r', 'utf-8').readlines()], key=lambda x: ''.join(x.split(' ')[::-1]))
......@@ -81,13 +80,13 @@ class Protokollskript:
def clean_string(self, data):
"""remove "A, "O, "U, "a, "o, "u from input"""
data = self.reg_Kovac.sub("Kova"+r"\v"+"{c}", data)
data = self.reg_A.sub('Ä', data)
data = self.reg_O.sub('Ö', data)
data = self.reg_U.sub('Ü', data)
data = self.reg_a.sub('ä', data)
data = self.reg_o.sub('ö', data)
data = self.reg_u.sub('ü', data)
data = self.reg['Kovac'].sub("Kova"+r"\v"+"{c}", data)
data = self.reg['"A'].sub('Ä', data)
data = self.reg['"O'].sub('Ö', data)
data = self.reg['"U'].sub('Ü', data)
data = self.reg['"a'].sub('ä', data)
data = self.reg['"o'].sub('ö', data)
data = self.reg['"u'].sub('ü', data)
return data
def get_protokollant_ldap(self, protokollant):
......@@ -98,7 +97,7 @@ class Protokollskript:
conn.bind()
fil = "(uid="+self.userid+")"
if conn.search('ou=people,'+self.base, fil, attributes=['gecos']):
return " ".join(str(conn.entries[0]['gecos']).split(", ")[::-1])
return self.clean_string(" ".join(str(conn.entries[0]['gecos']).split(", ")[::-1]))
return protokollant
except ldap.core.exceptions.LDAPException as error_message:
if self.opt['-d'] == 1:
......@@ -227,19 +226,19 @@ class Protokollskript:
with codecs.open('head.tex', 'r', 'utf-8') as fobj_head:
f_head = fobj_head.read()
f_head = self.reg_fsrname.sub(f_name, f_head)
f_head = self.reg_acroname.sub(f_acroname, f_head)
f_head = self.reg_acro.sub(f_acro, f_head)
f_head = self.reg_spr.sub(self.sprecher, f_head)
f_head = self.reg_prot.sub(self.protokollant, f_head)
f_head = self.reg_date.sub(self.date, f_head)
f_head = self.reg['FSRN'].sub(f_name, f_head)
f_head = self.reg['ACRON'].sub(f_acroname, f_head)
f_head = self.reg['ACRO'].sub(f_acro, f_head)
f_head = self.reg['SPR'].sub(self.sprecher, f_head)
f_head = self.reg['PRO'].sub(self.protokollant, f_head)
f_head = self.reg['DATE'].sub(self.date, f_head)
with codecs.open('foot.tex', 'r', 'utf-8') as fobj_foot:
f_foot = fobj_foot.read()
f_foot = self.reg_spr.sub(self.sprecher, f_foot)
f_foot = self.reg_prot.sub(self.protokollant, f_foot)
f_foot = self.reg_date.sub(self.date, f_foot)
f_foot = self.reg['SPR'].sub(self.sprecher, f_foot)
f_foot = self.reg['PRO'].sub(self.protokollant, f_foot)
f_foot = self.reg['DATE'].sub(self.date, f_foot)
msg = ""
......
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