Commit 640f2c73 authored by Lorenz Steinert's avatar Lorenz Steinert

style changes

parent 2e25a038
...@@ -6,4 +6,4 @@ test: ...@@ -6,4 +6,4 @@ test:
syntax: syntax:
before_script: before_script:
- pacman -Sy --noconfirm flake8 - pacman -Sy --noconfirm flake8
script: flake8 script: flake8 --exclude .git,__pycache__,bin/module/test.py
...@@ -9,7 +9,7 @@ Created on Fri Nov 24 15:35:04 2017 ...@@ -9,7 +9,7 @@ Created on Fri Nov 24 15:35:04 2017
import os import os
import codecs import codecs
import argparse import argparse
from module.esme import FsrLdap, get_config, get_share, get_ldap_server, get_ldap_base from module.esme import FsrLdap, get_config, get_share, get_ldap_server, get_ldap_base # noqa: E501
if __name__ == "__main__": if __name__ == "__main__":
RUNDIR = os.path.dirname(os.path.realpath(__file__)) RUNDIR = os.path.dirname(os.path.realpath(__file__))
......
...@@ -26,7 +26,7 @@ if __name__ == "__main__": ...@@ -26,7 +26,7 @@ if __name__ == "__main__":
for j in CONFIG[i]: for j in CONFIG[i]:
tmp = input('Bitte gib [' + j tmp = input('Bitte gib [' + j
+ '] ein [' + CONFIG[i][j] + ']: ') + '] ein [' + CONFIG[i][j] + ']: ')
if tmp!="": if tmp:
CONFIG[i][j] = tmp CONFIG[i][j] = tmp
if OPT.config: if OPT.config:
......
...@@ -8,7 +8,6 @@ Created on Fri Nov 24 15:35:04 2017 ...@@ -8,7 +8,6 @@ Created on Fri Nov 24 15:35:04 2017
import os import os
import re import re
import sys
import time import time
import codecs import codecs
import logging import logging
...@@ -56,7 +55,8 @@ def resort_fsr(fsr, num_cols=5): ...@@ -56,7 +55,8 @@ def resort_fsr(fsr, num_cols=5):
class FsrLdap: class FsrLdap:
"""Class die die protokoll .tex datei erstellt""" """Class die die protokoll .tex datei erstellt"""
def __init__(self, server, base, share_dir, config, debug=False, timeout=1, testing=None): def __init__(self, server, base, share_dir, config, debug=False,
timeout=1, testing=None):
self.debug = debug self.debug = debug
self.server = ldap.Server(server, self.server = ldap.Server(server,
...@@ -64,7 +64,8 @@ class FsrLdap: ...@@ -64,7 +64,8 @@ class FsrLdap:
if not testing: if not testing:
self.conn = ldap.Connection(self.server) self.conn = ldap.Connection(self.server)
else: else:
self.conn = ldap.Connection(self.server, client_strategy=ldap.MOCK_SYNC) self.conn = ldap.Connection(self.server,
client_strategy=ldap.MOCK_SYNC)
try: try:
self.conn.bind() self.conn.bind()
...@@ -83,14 +84,14 @@ class FsrLdap: ...@@ -83,14 +84,14 @@ class FsrLdap:
if self.conn.search('ou=people,' + self.base, fil, if self.conn.search('ou=people,' + self.base, fil,
attributes=['displayName']): attributes=['displayName']):
logging.info("Done") logging.info("Done")
return " ".join(str(self.conn.entries[0]['displayName']).split(", ")[::-1]) return " ".join(str(self.conn.entries[0]['displayName']).split(", ")[::-1]) # noqa: E501
return Error.UNSEC_SEARCH return Error.UNSEC_SEARCH
except ldap.core.exceptions.LDAPException as error_message: except ldap.core.exceptions.LDAPException as error_message:
if self.debug: if self.debug:
logging.warning("Couldn't Connect to ldap. \ logging.warning("Couldn't Connect to ldap. \
Using fallback default. %s" % error_message) Using fallback default. %s" % error_message)
else: else:
logging.warning("Couldn't Connect to ldap. Using fallback default.") logging.warning("Couldn't Connect to ldap. Using fallback default.") # noqa: E501
return Error.LDAP_FAIL return Error.LDAP_FAIL
@staticmethod @staticmethod
...@@ -110,7 +111,7 @@ class FsrLdap: ...@@ -110,7 +111,7 @@ class FsrLdap:
config = self.config config = self.config
protokollant = self._get_protokollant_ldap() protokollant = self._get_protokollant_ldap()
if isinstance(protokollant, tuple): if isinstance(protokollant, tuple):
pass pass
protokollant = protokollant[0] protokollant = protokollant[0]
elif isinstance(protokollant, Flag): elif isinstance(protokollant, Flag):
...@@ -130,7 +131,8 @@ class FsrLdap: ...@@ -130,7 +131,8 @@ class FsrLdap:
attributes=['memberUid']): attributes=['memberUid']):
for i in self.conn.entries[0]['memberUid']: for i in self.conn.entries[0]['memberUid']:
if self.conn.search('ou=people,' + self.base, if self.conn.search('ou=people,' + self.base,
'(uid='+i+')', attributes=['displayName']): '(uid='+i+')',
attributes=['displayName']):
fsr += [str(self.conn.entries[0]['displayName'])] fsr += [str(self.conn.entries[0]['displayName'])]
fsr.sort() fsr.sort()
fsr = [" ".join(i.split(', ')[::-1]) for i in fsr] fsr = [" ".join(i.split(', ')[::-1]) for i in fsr]
...@@ -142,14 +144,15 @@ class FsrLdap: ...@@ -142,14 +144,15 @@ class FsrLdap:
logging.warning("Couldn't Connect to ldap. \ logging.warning("Couldn't Connect to ldap. \
Using fallback File. %s" % error_message) Using fallback File. %s" % error_message)
else: else:
logging.warning("Couldn't Connect to ldap. Using fallback File.") logging.warning("Couldn't Connect to ldap. Using fallback File.") # noqa: E501
return (Error.LDAP_FAIL, error_message) return (Error.LDAP_FAIL, error_message)
@staticmethod @staticmethod
def _get_fallback_fsr(share_dir): def _get_fallback_fsr(share_dir):
"""get fsr form fallback file""" """get fsr form fallback file"""
if os.path.isfile(os.path.join(share_dir, 'fsr')): if os.path.isfile(os.path.join(share_dir, 'fsr')):
with codecs.open(os.path.join(share_dir, 'fsr'), 'r', 'utf-8') as fobj: with codecs.open(os.path.join(share_dir, 'fsr'),
'r', 'utf-8') as fobj:
fsr = sorted([re.sub(re.escape('\t'), ' ', fsr = sorted([re.sub(re.escape('\t'), ' ',
line.rstrip('\n')) line.rstrip('\n'))
for line in fobj.readlines()], for line in fobj.readlines()],
...@@ -163,10 +166,11 @@ class FsrLdap: ...@@ -163,10 +166,11 @@ class FsrLdap:
share_dir = self.share_dir share_dir = self.share_dir
fsr = self._get_fsr_ldap() fsr = self._get_fsr_ldap()
if isinstance(fsr, tuple): if isinstance(fsr, tuple):
fsr = fsr[0] fsr = fsr[0]
if isinstance(fsr, Error): if isinstance(fsr, Error):
if fsr & (Error.UNSEC_SEARCH | Error.LDAP_FAIL) and not gen_fallback: if fsr & (Error.UNSEC_SEARCH | Error.LDAP_FAIL) \
and not gen_fallback:
fsr = self._get_fallback_fsr(share_dir) fsr = self._get_fallback_fsr(share_dir)
if isinstance(fsr, Error): if isinstance(fsr, Error):
if fsr & (Error.NO_FILE | Error.UNSEC_SEARCH): if fsr & (Error.NO_FILE | Error.UNSEC_SEARCH):
...@@ -183,10 +187,11 @@ class FsrLdap: ...@@ -183,10 +187,11 @@ class FsrLdap:
attributes=['memberUid']): attributes=['memberUid']):
for i in self.conn.entries[0]['memberUid']: for i in self.conn.entries[0]['memberUid']:
if self.conn.search('ou=people,' + self.base, if self.conn.search('ou=people,' + self.base,
'(uid='+i+')', attributes=['displayName']): '(uid='+i+')',
fsr_extern += [str(self.conn.entries[0]['displayName'])] attributes=['displayName']):
fsr_extern += [str(self.conn.entries[0]['displayName'])] # noqa: E501
fsr_extern.sort() fsr_extern.sort()
fsr_extern = [" ".join(i.split(', ')[::-1]) for i in fsr_extern] fsr_extern = [" ".join(i.split(', ')[::-1]) for i in fsr_extern] # noqa: E501
logging.info("Done") logging.info("Done")
return fsr_extern return fsr_extern
return Error.UNSEC_SEARCH return Error.UNSEC_SEARCH
...@@ -195,14 +200,15 @@ class FsrLdap: ...@@ -195,14 +200,15 @@ class FsrLdap:
logging.warning("Couldn't Connect to ldap. \ logging.warning("Couldn't Connect to ldap. \
Using fallback File. %s" % error_message) Using fallback File. %s" % error_message)
else: else:
logging.warning("Couldn't Connect to ldap. Using fallback File.") logging.warning("Couldn't Connect to ldap. Using fallback File.") # noqa: E501
return (Error.LDAP_FAIL, error_message) return (Error.LDAP_FAIL, error_message)
@staticmethod @staticmethod
def _get_fallback_fsr_extern(share_dir): def _get_fallback_fsr_extern(share_dir):
"""get fsr_extern from fallback file""" """get fsr_extern from fallback file"""
if os.path.isfile(os.path.join(share_dir, 'fsr_extern')): if os.path.isfile(os.path.join(share_dir, 'fsr_extern')):
with codecs.open(os.path.join(share_dir, 'fsr_extern'), 'r', 'utf-8') as fobj: with codecs.open(os.path.join(share_dir, 'fsr_extern'),
'r', 'utf-8') as fobj:
fsr_extern = sorted([re.sub(re.escape('\t'), ' ', fsr_extern = sorted([re.sub(re.escape('\t'), ' ',
line.rstrip('\n')) line.rstrip('\n'))
for line in fobj.readlines()], for line in fobj.readlines()],
...@@ -220,7 +226,8 @@ class FsrLdap: ...@@ -220,7 +226,8 @@ class FsrLdap:
pass pass
fsr_extern = fsr_extern[0] fsr_extern = fsr_extern[0]
if isinstance(fsr_extern, Error): if isinstance(fsr_extern, Error):
if fsr_extern & (Error.UNSEC_SEARCH | Error.LDAP_FAIL) and not gen_fallback: if fsr_extern & (Error.UNSEC_SEARCH | Error.LDAP_FAIL) \
and not gen_fallback:
fsr_extern = self._get_fallback_fsr_extern(share_dir) fsr_extern = self._get_fallback_fsr_extern(share_dir)
if isinstance(fsr_extern, Error): if isinstance(fsr_extern, Error):
if fsr_extern & (Error.NO_FILE | Error.UNSEC_SEARCH): if fsr_extern & (Error.NO_FILE | Error.UNSEC_SEARCH):
...@@ -290,7 +297,7 @@ def get_config(rundir, config_path=None, default=False): ...@@ -290,7 +297,7 @@ def get_config(rundir, config_path=None, default=False):
return config return config
logging.warning('No default File found at ' logging.warning('No default File found at '
+ os.path.abspath(os.path.join(rundir, + os.path.abspath(os.path.join(rundir,
'../etc/proto.ini.default'))) '../etc/proto.ini.default'))) # noqa: E501
return Error.NO_DEFAULT_FILE return Error.NO_DEFAULT_FILE
elif os.path.isfile(os.path.join(rundir, elif os.path.isfile(os.path.join(rundir,
'../etc/proto.ini')) and not default: '../etc/proto.ini')) and not default:
...@@ -350,7 +357,7 @@ def get_ldap_server(config=None, server=None): ...@@ -350,7 +357,7 @@ def get_ldap_server(config=None, server=None):
return server return server
if config: if config:
return config['SERVER']['NAME'] return config['SERVER']['NAME']
logging.warning('No LDAP Server supplied. Triing to use "rincwind.fs.physik.uni-kl.de".') logging.warning('No LDAP Server supplied. Triing to use "rincwind.fs.physik.uni-kl.de".') # noqa: E501
return "rincewind.fs.physik.uni-kl.de" return "rincewind.fs.physik.uni-kl.de"
...@@ -360,7 +367,7 @@ def get_ldap_base(config=None, base=None): ...@@ -360,7 +367,7 @@ def get_ldap_base(config=None, base=None):
return base return base
if config: if config:
return config['SERVER']['BASE'] return config['SERVER']['BASE']
logging.warning('No LDAP search base supplied. ' \ logging.warning('No LDAP search base supplied. '
'Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".') 'Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".')
return "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 ...@@ -12,7 +12,7 @@ import sys
import shutil import shutil
import codecs import codecs
import argparse import argparse
from module.esme import FsrLdap, get_date, get_sprecher, get_config, get_share, get_path, get_ldap_server, get_ldap_base, get_server_timeout, Error from module.esme import FsrLdap, get_date, get_sprecher, get_config, get_share, get_path, get_ldap_server, get_ldap_base, get_server_timeout, Error # noqa: E501
def build_parser(): def build_parser():
...@@ -35,7 +35,7 @@ def build_parser(): ...@@ -35,7 +35,7 @@ def build_parser():
def gen_head(share_dir, reg, sprecher, protokollant, date): def gen_head(share_dir, reg, sprecher, protokollant, date):
"""generate the head of the protokoll""" """generate the head of the protokoll"""
#look for the name.tex and if not found ignore it # look for the name.tex and if not found ignore it
if os.path.isfile(os.path.join(share_dir, 'name.tex')): if os.path.isfile(os.path.join(share_dir, 'name.tex')):
with codecs.open(os.path.join(share_dir, 'name.tex'), with codecs.open(os.path.join(share_dir, 'name.tex'),
'r', 'utf-8') as fobj_name: 'r', 'utf-8') as fobj_name:
...@@ -45,8 +45,8 @@ def gen_head(share_dir, reg, sprecher, protokollant, date): ...@@ -45,8 +45,8 @@ def gen_head(share_dir, reg, sprecher, protokollant, date):
+ " not found. Ignoring") + " not found. Ignoring")
f_name = "" f_name = ""
#look for the acroname.tex and the acro.tex if one is not found # look for the acroname.tex and the acro.tex if one is not found
#ignore both # ignore both
if (os.path.isfile(os.path.join(share_dir, 'acroname.tex')) if (os.path.isfile(os.path.join(share_dir, 'acroname.tex'))
and os.path.isfile(os.path.join(share_dir, 'acro.tex'))): and os.path.isfile(os.path.join(share_dir, 'acro.tex'))):
...@@ -65,7 +65,7 @@ def gen_head(share_dir, reg, sprecher, protokollant, date): ...@@ -65,7 +65,7 @@ def gen_head(share_dir, reg, sprecher, protokollant, date):
f_acroname = "" f_acroname = ""
f_acro = "" 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')): if os.path.isfile(os.path.join(share_dir, 'head.tex')):
with codecs.open(os.path.join(share_dir, 'head.tex'), with codecs.open(os.path.join(share_dir, 'head.tex'),
'r', 'utf-8') as fobj_head: 'r', 'utf-8') as fobj_head:
...@@ -75,7 +75,7 @@ def gen_head(share_dir, reg, sprecher, protokollant, date): ...@@ -75,7 +75,7 @@ def gen_head(share_dir, reg, sprecher, protokollant, date):
+ " not found. Aborting!") + " not found. Aborting!")
sys.exit(1) sys.exit(1)
#Replace the paceholder strings with the files # Replace the paceholder strings with the files
f_head = reg['FSRN'].sub(f_name, f_head) f_head = reg['FSRN'].sub(f_name, f_head)
f_head = reg['ACRON'].sub(f_acroname, f_head) f_head = reg['ACRON'].sub(f_acroname, f_head)
f_head = reg['ACRO'].sub(f_acro, f_head) f_head = reg['ACRO'].sub(f_acro, f_head)
...@@ -125,7 +125,7 @@ def gen_attendance_tab(fsr, num_cols=5, ext=False): ...@@ -125,7 +125,7 @@ def gen_attendance_tab(fsr, num_cols=5, ext=False):
def gen_foot(share_dir, vollversamlung, reg, sprecher, protokollant, date): def gen_foot(share_dir, vollversamlung, reg, sprecher, protokollant, date):
"""generate the foot of the protokoll""" """generate the foot of the protokoll"""
#look for the foot*.tex skripts # look for the foot*.tex skripts
# if not found abort # if not found abort
if vollversamlung: if vollversamlung:
if os.path.isfile(os.path.join(share_dir, 'foot_VV.tex')): if os.path.isfile(os.path.join(share_dir, 'foot_VV.tex')):
...@@ -146,7 +146,7 @@ def gen_foot(share_dir, vollversamlung, reg, sprecher, protokollant, date): ...@@ -146,7 +146,7 @@ def gen_foot(share_dir, vollversamlung, reg, sprecher, protokollant, date):
+ " not found. Aborting") + " not found. Aborting")
sys.exit(1) sys.exit(1)
#replace the placeholder strings in f_foot # replace the placeholder strings in f_foot
f_foot = reg['SPR'].sub(sprecher, f_foot) f_foot = reg['SPR'].sub(sprecher, f_foot)
f_foot = reg['PRO'].sub(protokollant, f_foot) f_foot = reg['PRO'].sub(protokollant, f_foot)
f_foot = reg['DATE'].sub(date[0], f_foot) f_foot = reg['DATE'].sub(date[0], f_foot)
...@@ -202,22 +202,23 @@ if __name__ == "__main__": ...@@ -202,22 +202,23 @@ if __name__ == "__main__":
DATE = get_date(OPT.test) DATE = get_date(OPT.test)
#Fetch the FSR from the Server # Fetch the FSR from the Server
#and if not able to connect fall back to the textfiles # and if not able to connect fall back to the textfiles
FSR = [ESME.get_fsr(), ESME.get_fsr_extern()] FSR = [ESME.get_fsr(), ESME.get_fsr_extern()]
#Generate the Path for the Protokoll in depandance of OPT.VV # Generate the Path for the Protokoll in depandance of OPT.VV
#and make the directory # and make the directory
if OPT.Vollversamlung: if OPT.Vollversamlung:
OUTDIR = os.path.join(get_path(RUNDIR, CONFIG, OPT.path), DATE[1], OUTDIR = os.path.join(get_path(RUNDIR, CONFIG, OPT.path), DATE[1],
"fsr_physik_vollversamlung_" + '-'.join(DATE[1:])) "fsr_physik_vollversamlung_"
+ '-'.join(DATE[1:]))
else: else:
OUTDIR = os.path.join(get_path(RUNDIR, CONFIG, OPT.path), DATE[1], OUTDIR = os.path.join(get_path(RUNDIR, CONFIG, OPT.path), DATE[1],
"fsr_physik_sitzung_" + '-'.join(DATE[1:])) "fsr_physik_sitzung_" + '-'.join(DATE[1:]))
if not os.path.exists(OUTDIR): if not os.path.exists(OUTDIR):
os.makedirs(OUTDIR) os.makedirs(OUTDIR)
#Generate the path of the .tex file # Generate the path of the .tex file
OUTFILE = os.path.join(OUTDIR, "fsr_physik_protokoll_" OUTFILE = os.path.join(OUTDIR, "fsr_physik_protokoll_"
+ '-'.join(DATE[1:]) + ".tex") + '-'.join(DATE[1:]) + ".tex")
......
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