Commit 02dd54df authored by Lorenz Steinert's avatar Lorenz Steinert

Restructured directory tree

Directory Tree:

bin/
    module/
        imported module files
    executable files
etc/
    config files
share/
    recource files

Die proto.ini enthält nun share und path damit auf diese unabhänig vom
current workingdirectory zugegriffen werden kann. Diese sollten auf die
absoluten Pfade von share/ und die dem protokolle Ordner gesetzt werden.

Weiterhin exsistieren für die generate_fallback.py und die proto.py nun
die folgenden Optionen:
-p, --path : setzt den pfad des Protokoll Ordners
-c, --config : setzt den pfad für die proto.ini Datei
-s, --share : setzt den pfad für den share ordner
parent ab9c5e01
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 24 15:35:04 2017
@author: lorico
"""
import os
import codecs
import argparse
from module.esme import fsr_ldap, get_config, get_share
if __name__ == "__main__":
RUNDIR = os.path.dirname(os.path.realpath(__file__))
PARSER = argparse.ArgumentParser(description="generate Fallback files for the protokollskript.")
PARSER.add_argument('-s', '--sharedir', help='set the share directory')
PARSER.add_argument('-c', '--config', help='set the config file')
OPT = PARSER.parse_args()
CONFIG = get_config(RUNDIR, OPT.config)
SHARE_DIR = get_share(RUNDIR, CONFIG, OPT.sharedir)
ESME = fsr_ldap(debug=True, timeout=30)
FSR = ESME.get_fsr_ldap([])
FSR_EXTERN = ESME.get_fsr_extern_ldap([])
fsr_out = ""
fsr_extern_out = ""
fsr_out = [i + "\n" for i in FSR]
fsr_extern_out = [i + "\n" for i in FSR_EXTERN]
with codecs.open(os.path.join(SHARE_DIR, 'fsr'),
'w', 'utf-8') as fobj_fsr_out:
fobj_fsr_out.write(''.join(fsr_out))
with codecs.open(os.path.join(SHARE_DIR, 'fsr_extern'),
'w', 'utf-8') as fobj_fsr_extern_out:
fobj_fsr_extern_out.write(''.join(fsr_extern_out))
......@@ -6,10 +6,10 @@ import configparser
if __name__ == "__main__":
CONFIG = configparser.ConfigParser()
CONFIG.read('./proto.ini.default')
CONFIG.read('../etc/proto.ini.default')
for i in CONFIG:
print('['+i+']')
for j in CONFIG[i]:
CONFIG[i][j] = input('Bitte gib ['+j+'] ein: ')
with open('proto.ini', 'w') as fobj:
with open('../etc/proto.ini', 'w') as fobj:
CONFIG.write(fobj)
......@@ -7,6 +7,8 @@ Created on Fri Nov 24 15:35:04 2017
"""
import os
import sys
import configparser
import ldap3 as ldap
try:
......@@ -29,7 +31,8 @@ class fsr_ldap:
def __init__(self, debug=False, timeout=1):
self.debug = debug
self.server = ldap.Server("rincewind.fs.physik.uni-kl.de", connect_timeout=timeout)
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):
......@@ -39,12 +42,14 @@ class fsr_ldap:
conn = ldap.Connection(self.server)
conn.bind()
fil = "(uid="+current_user()+")"
if conn.search('ou=people,'+self.base, fil, attributes=['displayName']):
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)
print("Couldn't Connect to ldap.\n \
Using fallback default.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback default.\n")
return protokollant
......@@ -69,7 +74,8 @@ class fsr_ldap:
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)
print("Couldn't Connect to ldap.\n \
Using fallback File.\n%s\n" % error_message)
else:
print("Couldn't Connect to ldap.\nUsing fallback File.\n")
return fsr
......@@ -94,11 +100,13 @@ class fsr_ldap:
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)
print("Couldn't Connect to ldap.\n \
Using 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+"]: ")
......@@ -106,6 +114,7 @@ def get_sprecher(sprecher):
return stmp
return sprecher
def get_protokollant(protokollant):
"""get protokollant from user input"""
ptmp = input("Protokollant ["+protokollant+"]: ")
......@@ -113,20 +122,82 @@ def get_protokollant(protokollant):
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
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
def get_config(rundir, config_path=None):
if config_path:
if os.path.isfile(config_path):
config = configparser.ConfigParser()
config.read(config_path)
return config
else:
print(config_path + ': Not a file')
sys.exit(2)
elif os.path.isfile(os.path.join(rundir, '../etc/proto.ini')):
config = configparser.ConfigParser()
config.read(os.path.join(rundir, '../etc/proto.ini'))
return config
else:
print('No ini file found. Using defaults.')
return None
def get_share(rundir, config=None, sharedir=None):
if sharedir:
if os.path.isdir(sharedir):
return sharedir
else:
print(sharedir + ': Not a Directory')
sys.exit(2)
elif config:
if os.path.isdir(config['DEFAULT']['share']):
return config['DEFAULT']['share']
else:
print(config['DEFAULT']['share'] + ': Not a Directory')
sys.exit(2)
elif os.path.isdir(os.path.join(rundir, '../share')):
return os.path.join(rundir, '../share')
else:
print('No share Directory found at ' + os.path.abspath(os.path.join(rundir, '../share')))
sys.exit(1)
def get_path(rundir, config=None, path=None):
if path:
if os.path.isdir(path):
return path
else:
print(path + ': Not a Directory')
sys.exit(2)
elif config:
if os.path.isdir(config['DEFAULT']['path']):
return config['DEFAULT']['path']
else:
print(config['DEFAULT']['path'] + ': Not a Directory')
sys.exit(2)
elif os.path.isdir(os.path.join(rundir, '../..')):
return os.path.join(rundir, '../..')
else:
print('No Protokoll Directory found at ' + os.path.abspath(os.path.join(rundir, '../..')))
sys.exit(1)
......@@ -8,15 +8,16 @@ Created on Fri Nov 24 15:35:04 2017
import re
import os
import shutil
import time
import argparse
import shutil
import codecs
import configparser
from src.esme import *
import argparse
from module.esme import fsr_ldap, get_date, get_sprecher, get_protokollant, get_config, get_share, get_path
if __name__ == "__main__":
RUNDIR = os.path.dirname(os.path.realpath(__file__))
PARSER = argparse.ArgumentParser(description="Create Protokoll")
PARSER.add_argument('-d', '--debug', '-v', '--verbose',
action='store_true', help='enable debug mode')
......@@ -24,10 +25,14 @@ if __name__ == "__main__":
action='store_true', help='gennerate VV Protokoll')
PARSER.add_argument('-t', '--test',
action='store_true', help='enable test mode')
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')
OPT = PARSER.parse_args()
CONFIG = configparser.ConfigParser()
CONFIG.read('./proto.ini')
CONFIG = get_config(RUNDIR, OPT.config)
SHARE_DIR = get_share(RUNDIR, CONFIG, OPT.sharedir)
REG = {'SPR': re.compile('%%SPRECHER'),
'PRO': re.compile('%%PROTOKOLLANT'),
......@@ -45,13 +50,17 @@ if __name__ == "__main__":
fsr[0] = sorted([re.sub(re.escape('\t'), ' ',
line.rstrip('\n'))
for line in codecs.open('./fsr', 'r',
for line in codecs.open(os.path.join(SHARE_DIR,
'fsr'),
'r',
'utf-8').readlines()],
key=lambda x: ''.join(x.split(' ')[::-1]))
fsr[1] = sorted([re.sub(re.escape('\t'), ' ',
line.rstrip('\n'))
for line in codecs.open('./fsr_extern', 'r',
for line in codecs.open(os.path.join(SHARE_DIR,
'fsr_extern'),
'r',
'utf-8').readlines()],
key=lambda x: ''.join(x.split(' ')[::-1]))
......@@ -72,59 +81,65 @@ if __name__ == "__main__":
day = str(time.localtime()[2])
if len(day) < 2:
day = "0"+day
date = (day+"."+mon+"."+year, year, mon, day)
date = (day + '.' + mon + '.' + year, year, mon, day)
print("\n")
protokollant = ESME.get_protokollant_ldap(CONFIG['DEFAULT']['Protokollant'])
PROTOKOLLANT = ESME.get_protokollant_ldap(CONFIG['DEFAULT']['Protokollant'])
fsr[0] = ESME.get_fsr_ldap(fsr[0])
fsr[1] = ESME.get_fsr_extern_ldap(fsr[1])
print("\n")
print("Wenn der Standardwert (in []) stimmt einfach Enter!\n")
# get data form user
sprecher = get_sprecher(CONFIG['DEFAULT']['Sprecher'])
protokollant = get_protokollant(protokollant)
SPRECHER = get_sprecher(CONFIG['DEFAULT']['Sprecher'])
PROTOKOLLANT = get_protokollant(PROTOKOLLANT)
date = get_date(date)
# self.editor = self.get_editor(self.editor)
OUTDIR = "../" + date[1] + "/fsr_physik_sitzung_" + date[1] + "-" \
+ date[2] + "-" + date[3] + "/"
OUTDIR = get_path(RUNDIR, CONFIG, OPT.path)
if not os.path.exists(OUTDIR):
os.makedirs(OUTDIR)
shutil.copyfile("./FS-Logo.pdf", OUTDIR + "FS-Logo.pdf")
shutil.copyfile(os.path.join(SHARE_DIR, "FS-Logo.pdf"),
os.path.join(OUTDIR, "FS-Logo.pdf"))
OUTFILE = OUTDIR + "/fsr_physik_protokoll_" + date[1] + "-" \
+ date[2] + "-" + date[3] + ".tex"
OUTFILE = os.path.join(OUTDIR, "fsr_physik_protokoll_"
+ '-'.join(date[1:]) + ".tex")
with codecs.open('name.tex', 'r', 'utf-8') as fobj_name:
f_name = fobj_name.read()
with codecs.open(os.path.join(SHARE_DIR, 'name.tex'),
'r', 'utf-8') as fobj_name:
F_NAME = fobj_name.read()
with codecs.open('acroname.tex', 'r', 'utf-8') as fobj_acroname:
f_acroname = fobj_acroname.read()
with codecs.open(os.path.join(SHARE_DIR, 'acroname.tex'),
'r', 'utf-8') as fobj_acroname:
F_ACRONAME = fobj_acroname.read()
with codecs.open('acro.tex', 'r', 'utf-8') as fobj_acro:
f_acro = fobj_acro.read()
with codecs.open(os.path.join(SHARE_DIR, 'acro.tex'),
'r', 'utf-8') as fobj_acro:
F_ACRO = fobj_acro.read()
with codecs.open('head.tex', 'r', 'utf-8') as fobj_head:
with codecs.open(os.path.join(SHARE_DIR, 'head.tex'),
'r', 'utf-8') as fobj_head:
f_head = fobj_head.read()
f_head = REG['FSRN'].sub(f_name, f_head)
f_head = REG['ACRON'].sub(f_acroname, f_head)
f_head = REG['ACRO'].sub(f_acro, f_head)
f_head = REG['SPR'].sub(sprecher, f_head)
f_head = REG['PRO'].sub(protokollant, f_head)
f_head = REG['FSRN'].sub(F_NAME, f_head)
f_head = REG['ACRON'].sub(F_ACRONAME, f_head)
f_head = REG['ACRO'].sub(F_ACRO, f_head)
f_head = REG['SPR'].sub(SPRECHER, f_head)
f_head = REG['PRO'].sub(PROTOKOLLANT, f_head)
f_head = REG['DATE'].sub(date[0], f_head)
if OPT.Vollversamlung:
with codecs.open('foot_VV.tex', 'r', 'utf-8') as fobj_foot:
with codecs.open(os.path.join(SHARE_DIR, 'foot_VV.tex'),
'r', 'utf-8') as fobj_foot:
f_foot = fobj_foot.read()
else:
with codecs.open('foot.tex', 'r', 'utf-8') as fobj_foot:
with codecs.open(os.path.join(SHARE_DIR, 'foot.tex'),
'r', 'utf-8') as fobj_foot:
f_foot = fobj_foot.read()
f_foot = REG['SPR'].sub(sprecher, f_foot)
f_foot = REG['PRO'].sub(protokollant, f_foot)
f_foot = REG['SPR'].sub(SPRECHER, f_foot)
f_foot = REG['PRO'].sub(PROTOKOLLANT, f_foot)
f_foot = REG['DATE'].sub(date[0], f_foot)
msg = ""
......
......@@ -3,6 +3,8 @@ num_cols = 4
num_cols_ext = 2
sprecher = SPRECHER
protokollant = PROTOKOLLANT
path = /home/referate/protokoll
share = /home/referate/protokoll/protokollskript/share
[SERVER]
connect_timeout = 10
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 24 15:35:04 2017
@author: lorico
"""
import codecs
import src.esme as esme
if __name__ == "__main__":
Esme = esme.fsr_ldap(debug=True, timeout=30)
fsr = Esme.get_fsr_ldap([])
fsr_extern = Esme.get_fsr_extern_ldap([])
fsr_out = ""
fsr_extern_out = ""
fsr_out = [i+"\n" for i in fsr]
fsr_extern_out = [i+"\n" for i in fsr_extern]
with codecs.open('fsr', 'w', 'utf-8') as fobj_fsr_out:
fobj_fsr_out.write(''.join(fsr_out))
with codecs.open('fsr_extern', 'w', 'utf-8') as fobj_fsr_extern_out:
fobj_fsr_extern_out.write(''.join(fsr_extern_out))
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