1
0
mirror of https://github.com/kakwa/ldapcherry synced 2025-02-16 15:43:19 +01:00

many pep8 fixes thanks to pep8ify

This commit is contained in:
kakwa 2015-07-10 21:06:28 +02:00
parent 2d12335030
commit 3712bb85cb
9 changed files with 178 additions and 152 deletions

View File

@ -32,6 +32,7 @@ from sets import Set
SESSION_KEY = '_cp_username'
# Custom log function to overrige weird error.log function
# of cherrypy
def syslog_error(msg='', context='',
@ -44,18 +45,20 @@ def syslog_error(msg='', context='',
else:
cherrypy.log.error_log.log(severity,
' '.join((context, msg)))
import traceback
if traceback:
try:
exc = sys.exc_info()
if exc == (None, None, None):
cherrypy.log.error_log.log(severity, msg)
import traceback
# log each line of the exception
# in a separate log for lisibility
for l in traceback.format_exception(*exc):
cherrypy.log.error_log.log(severity, l)
finally:
del exc
class LdapCherry(object):
def _handle_exception(self, e):
@ -206,7 +209,6 @@ class LdapCherry(object):
)
self.roles = Roles(self.roles_file)
def _set_access_log(self, config, level):
""" Configure access logs
"""
@ -556,7 +558,6 @@ class LdapCherry(object):
severity=logging.DEBUG
)
def _modify_attrs(self, params, attr_list, username):
badd = {}
for attr in attr_list:

View File

@ -16,6 +16,7 @@ import yaml
types = ['string', 'email', 'int', 'stringlist', 'fix', 'password']
class Attributes:
def __init__(self, attributes_file):

View File

@ -7,6 +7,7 @@
from ldapcherry.exceptions import MissingParameter
class Backend:
def __init__(self, config, logger, name, attrslist, key):
@ -46,4 +47,3 @@ class Backend:
return default
else:
raise MissingParameter('backends', self.backend_name + '.' + param)

View File

@ -13,11 +13,13 @@ import ldapcherry.backend
import os
import re
class DelUserDontExists(Exception):
def __init__(self, user):
self.user = user
self.log = "cannot remove user, user <%(user)s> does not exist" % {'user': user}
class CaFileDontExist(Exception):
def __init__(self, cafile):
self.cafile = cafile
@ -28,6 +30,7 @@ DISPLAYED_ATTRS = 1
LISTED_ATTRS = 2
ALL_ATTRS = 3
class Backend(ldapcherry.backend.Backend):
def __init__(self, config, logger, name, attrslist, key):

View File

@ -7,6 +7,7 @@
import ldapcherry.backend
class Backend(ldapcherry.backend.Backend):
def __init__(self, config, logger, name, attrslist, key):

View File

@ -7,12 +7,14 @@
import string
class MissingParameter(Exception):
def __init__(self, section, key):
self.section = section
self.key = key
self.log = "missing parameter '%(key)s' in section '%(section)s'" % {'key': key, 'section': section}
class MissingKey(Exception):
def __init__(self, key, section, ymlfile):
self.key = key
@ -20,57 +22,68 @@ class MissingKey(Exception):
self.ymlfile = ymlfile
self.log = "missing key '%(key)s' in section '%(section)s' inside file '%(ymlfile)s'" % {'key': key, 'section': section, 'ymlfile': ymlfile}
class DumplicateRoleKey(Exception):
def __init__(self, role):
self.role = role
self.log = "duplicate role key '%(role)s' in role file" % {'role': role}
class MissingRole(Exception):
def __init__(self, role):
self.role = role
self.log = "role '%(role)s' does not exist in role file" % {'role': role}
class MissingBackend(Exception):
def __init__(self, backend):
self.backend = backend
self.log = "backend '%(backend)s' does not exist in main config file" % {'backend': backend}
class WrongBackend(Exception):
def __init__(self, backend):
self.backend = backend
self.log = "backend '%(backend)s' does not exist" % {'backend': backend}
class DumplicateRoleContent(Exception):
def __init__(self, role1, role2):
self.role1 = role1
self.role2 = role2
self.log = "role '%(role1)s' and '%(role2)s' are identical" % {'role1': role1, 'role2': role2}
class MissingRolesFile(Exception):
def __init__(self, rolefile):
self.rolefile = rolefile
self.log = "fail to open role file '%(rolefile)s'" % {'rolefile': rolefile}
class MissingMainFile(Exception):
def __init__(self, config):
self.rolefile = rolefile
self.log = "fail to open main file '%(config)s'" % {'rolefile': rolefile}
class MissingAttributesFile(Exception):
def __init__(self, attributesfile):
self.attributesfile = attributesfile
self.log = "fail to open attributes file '%(attributesfile)s'" % {'attributesfile': attributesfile}
class BackendModuleLoadingFail(Exception):
def __init__(self, module):
self.module = module
self.log = "module '%(module)s' not in python path" % {'module': module}
class BackendModuleInitFail(Exception):
def __init__(self, module):
self.module = module
self.log = "fail to init module '%(module)s'" % {'module': module}
class WrongParamValue(Exception):
def __init__(self, param, section, possible_values):
self.possible_values = possible_values
@ -79,16 +92,19 @@ class WrongParamValue(Exception):
possible_values_str = string.join(possible_values, ', ')
self.log = "wrong value for param '%(param)s' in section '%(section)s', possible values are [%(values)s]" % {'param': param, 'section': section, 'values': possible_values_str}
class DumplicateUserKey(Exception):
def __init__(self, attrid1, attrid2):
self.attrid1 = attrid1
self.attrid2 = attrid2
self.log = "duplicate key in '%(attrid1)s' and '%(attrid2)s'" % {'attrid1': attrid1, 'attrid2': attrid2}
class MissingUserKey(Exception):
def __init__(self):
self.log = "missing key"
class WrongAttributeType(Exception):
def __init__(self, key, section, ymlfile):
self.key = key

View File

@ -17,6 +17,7 @@ class RelationError(Exception):
self.key = key
self.value = value
class DumplicatedKey(Exception):
def __init__(self, host, key):
self.host = host
@ -29,6 +30,7 @@ try:
except ImportError:
from yaml import Loader, Dumper
# PyYaml wrapper that loads yaml files throwing an exception
#if a key is dumplicated
class MyLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver):

View File

@ -15,12 +15,14 @@ from ldapcherry.pyyamlwrapper import DumplicatedKey
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile, MissingRole
import yaml
class CustomDumper(yaml.SafeDumper):
"A custom YAML dumper that never emits aliases"
def ignore_aliases(self, _data):
return True
class Roles:
def __init__(self, role_file):