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

style changes

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