Commit 9f5c5b07 authored by Lorenz Steinert's avatar Lorenz Steinert

refractord code and added proto.ini

parent bd55a52b
[DEFAULT]
num_cols = 4
num_cols_ext = 2
Sprecher = Silvia Hiebel
Protokollant = Lorenz Steinert
Editor = vim
......@@ -33,20 +33,21 @@ class Protokollskript:
"""Class die die protokoll .tex datei erstellt"""
def __init__(self, opt):
config = configparser.ConfigParser()
config.read('./proto.ini')
self.config = configparser.ConfigParser()
self.config.read('./proto.ini')
self.server = ldap.Server("rincewind.fs.physik.uni-kl.de")
self.base = "dc=fs,dc=physik,dc=uni-kl,dc=de"
self.year = str(time.localtime()[0])
self.mon = str(time.localtime()[1])
self.day = str(time.localtime()[2])
if len(self.mon) < 2:
self.mon = "0"+self.mon
if len(self.day) < 2:
self.day = "0"+self.day
self.date = self.day+"."+self.mon+"."+self.year
self.userid = current_user()
year = str(time.localtime()[0])
mon = str(time.localtime()[1])
day = str(time.localtime()[2])
if len(mon) < 2: mon = "0"+mon
if len(day) < 2: day = "0"+day
self.date = (day+"."+mon+"."+year, year, mon, day)
self.reg = {'"a': re.compile('\"a'),
'"o': re.compile('\"o'),
'"u': re.compile('\"u'),
......@@ -77,13 +78,15 @@ class Protokollskript:
key=lambda x: ''.join(x.split(' ')[::-1]))
self.opt = {'-d': False, '-VV': False}
for i in opt[1:]:
if i in self.opt.keys():
self.opt[i] = True
print(self.opt)
else:
print(i + ' ist keine Option für das Protokollskript. \
\nVerfügbare Optionen sind: \n' + str(list(self.opt.keys())))
\nVerfügbare Optionen sind: \n' +
str(list(self.opt.keys())))
raise SystemExit(0)
def clean_string(self, data):
......@@ -103,7 +106,7 @@ class Protokollskript:
try:
conn = ldap.Connection(self.server)
conn.bind()
fil = "(uid="+self.userid+")"
fil = "(uid="+current_user()+")"
if conn.search('ou=people,'+self.base, fil, attributes=['gecos']):
return self.clean_string(" ".join(str(conn.entries[0]['gecos']).split(", ")[::-1]))
return protokollant
......@@ -165,35 +168,38 @@ class Protokollskript:
print("Couldn't Connect to ldap.\nUsing fallback File.")
return fsr_extern
def get_sprecher(self, sprecher):
@staticmethod
def get_sprecher(sprecher):
"""get sprecher from user input"""
stmp = input("Sprecher ["+self.sprecher+"]: ")
stmp = input("Sprecher ["+sprecher+"]: ")
if stmp != "":
return stmp
return sprecher
def get_protokollant(self, protokollant):
@staticmethod
def get_protokollant(protokollant):
"""get protokollant from user input"""
ptmp = input("Protokollant ["+self.protokollant+"]: ")
ptmp = input("Protokollant ["+protokollant+"]: ")
if ptmp != "":
return ptmp
return protokollant
def get_date(self, date):
@staticmethod
def get_date(date):
"""get date from user input"""
dtmp = input("Datum ["+self.date+"]: ")
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, day, mon, year
return date, self.day, self.mon, self.year
return date
def get_editor(self, editor):
@staticmethod
def get_editor(editor):
"""get the editor to use from user input"""
etmp = input("Editor ["+self.editor+"]: ")
etmp = input("Editor ["+editor+"]: ")
if etmp != "":
return etmp
return editor
......@@ -205,7 +211,7 @@ class Protokollskript:
num_cols_ext = self.config['DEFAULT'].getint('num_cols_ext')
print("\n")
protokollant = self.get_protokollant_ldap(self.config['DEFAULT']['Sprecher'])
protokollant = self.get_protokollant_ldap(self.config['DEFAULT']['Protokollant'])
self.fsr = self.get_fsr_ldap(self.fsr)
self.fsr_extern = self.get_fsr_extern_ldap(self.fsr_extern)
print("\n")
......@@ -214,18 +220,18 @@ class Protokollskript:
# get data form user
sprecher = self.get_sprecher(self.config['DEFAULT']['Sprecher'])
protokollant = self.get_protokollant(protokollant)
self.date, self.day, self.mon, self.year = self.get_date(self.date)
self.date = self.get_date(self.date)
# self.editor = self.get_editor(self.editor)
outdir = "../" + self.year + "/fsr_physik_sitzung_" + self.year + "-" \
+ self.mon + "-" + self.day + "/"
outdir = "../" + self.date[1] + "/fsr_physik_sitzung_" + self.date[1] + "-" \
+ self.date[2] + "-" + self.date[3] + "/"
if not os.path.exists(outdir):
os.makedirs(outdir)
shutil.copyfile("./FS-Logo.pdf", outdir + "FS-Logo.pdf")
outfile = outdir + "/fsr_physik_protokoll_" + self.year + "-" \
+ self.mon + "-" + self.day + ".tex"
outfile = outdir + "/fsr_physik_protokoll_" + self.date[1] + "-" \
+ self.date[2] + "-" + self.date[3] + ".tex"
with codecs.open('name.tex', 'r', 'utf-8') as fobj_name:
f_name = fobj_name.read()
......@@ -244,7 +250,7 @@ class Protokollskript:
f_head = self.reg['ACRO'].sub(f_acro, f_head)
f_head = self.reg['SPR'].sub(sprecher, f_head)
f_head = self.reg['PRO'].sub(protokollant, f_head)
f_head = self.reg['DATE'].sub(self.date, f_head)
f_head = self.reg['DATE'].sub(self.date[0], f_head)
if self.opt['-VV']:
with codecs.open('foot_VV.tex', 'r', 'utf-8') as fobj_foot:
......@@ -255,15 +261,13 @@ class Protokollskript:
f_foot = self.reg['SPR'].sub(sprecher, f_foot)
f_foot = self.reg['PRO'].sub(protokollant, f_foot)
f_foot = self.reg['DATE'].sub(self.date, f_foot)
f_foot = self.reg['DATE'].sub(self.date[0], f_foot)
msg = ""
msg += f_head
#fobj_out.write(f_head)
msg += "~\\newline\n"
#fobj_out.write("~\\newline\n")
if not self.opt['-VV']:
tabdef = "||"
......@@ -271,42 +275,30 @@ class Protokollskript:
tabdef += "c|l||"
msg += "FSR-Mitglieder\\\\\n\\\\\n\\scriptsize{\\begin{tabular}{" \
+ tabdef + "}\n\\hline\n"
#fobj_out.write("FSR-Mitglieder\\\\\n\\\\\n\\scriptsize{\\begin{tabular}{"
#+ tabdef + "}\n\\hline\n")
for i in zip(self.fsr, range(len(self.fsr))):
if i[1] % num_cols == 0:
msg += " "
#fobj_out.write(" ")
else:
msg += "&"
#fobj_out.write("&")
if "Sarah" in i[0]:
msg += r" &Sarah Anna Kova\v{c}"
#fobj_out.write(r" &Sarah Anna Kova\v{c}")
else:
msg += " &" + i[0]
#fobj_out.write(" &" + i[0])
if i[1] % num_cols == num_cols - 1:
msg += "\\\\\\hline\n"
#fobj_out.write("\\\\\\hline\n")
else:
msg += "\n"
#fobj_out.write("\n")
if not len(self.fsr)%num_cols == 0:
for i in range(num_cols - len(self.fsr)%num_cols):
msg += "& &\n"
#fobj_out.write("& &\n")
msg += "\\\\\\hline\n"
#fobj_out.write("\\\\\\hline\n")
msg += r"\end{tabular}}\normalsize\vspace{1em}"
msg += "\n\\newline\n"
#fobj_out.write(r"\end{tabular}}\normalsize\vspace{1em}")
#fobj_out.write("\n\\newline\n")
tabdef = "||"
for i in range(num_cols_ext):
......@@ -314,36 +306,25 @@ class Protokollskript:
msg += "Externe Referenten\\\\\n\\\\\n" \
+ r"\scriptsize{\begin{tabular}{" \
+ tabdef + "}\n\\hline\n"
#fobj_out.write("Externe Referenten\\\\\n\\\\\n"
#+ r"\scriptsize{\begin{tabular}{"
#+ tabdef + "}\n\\hline\n")
for i in zip(self.fsr_extern, range(len(self.fsr_extern))):
if i[1] % num_cols_ext == 0:
msg += " "
#fobj_out.write(" ")
else:
msg += "&"
#fobj_out.write("&")
if "Sarah" in i[0]:
msg += r" &Sarah Anna Kova\v{c}"
#fobj_out.write(r" &Sarah Anna Kova\v{c}")
else:
msg += " &" +i[0]
#fobj_out.write(" &" + i[0])
if i[1] % num_cols_ext == num_cols_ext - 1:
msg += "\\\\\\hline\n"
#fobj_out.write("\\\\\\hline\n")
else:
msg += "\n"
#fobj_out.write("\n")
msg += "\\end{tabular}}\\normalsize"
#fobj_out.write("\\end{tabular}}\\normalsize")
msg += f_foot
#fobj_out.write(f_foot)
with codecs.open(outfile, 'w', 'utf-8') as fobj_out:
fobj_out.write(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