mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 17:34:21 +01:00
many pep8 fixes thanks to pep8ify
This commit is contained in:
parent
2d12335030
commit
3712bb85cb
@ -32,6 +32,7 @@ from sets import Set
|
|||||||
|
|
||||||
SESSION_KEY = '_cp_username'
|
SESSION_KEY = '_cp_username'
|
||||||
|
|
||||||
|
|
||||||
# Custom log function to overrige weird error.log function
|
# Custom log function to overrige weird error.log function
|
||||||
# of cherrypy
|
# of cherrypy
|
||||||
def syslog_error(msg='', context='',
|
def syslog_error(msg='', context='',
|
||||||
@ -44,18 +45,20 @@ def syslog_error(msg='', context='',
|
|||||||
else:
|
else:
|
||||||
cherrypy.log.error_log.log(severity,
|
cherrypy.log.error_log.log(severity,
|
||||||
' '.join((context, msg)))
|
' '.join((context, msg)))
|
||||||
|
import traceback
|
||||||
if traceback:
|
if traceback:
|
||||||
try:
|
try:
|
||||||
exc = sys.exc_info()
|
exc = sys.exc_info()
|
||||||
if exc == (None, None, None):
|
if exc == (None, None, None):
|
||||||
cherrypy.log.error_log.log(severity, msg)
|
cherrypy.log.error_log.log(severity, msg)
|
||||||
import traceback
|
|
||||||
# log each line of the exception
|
# log each line of the exception
|
||||||
|
# in a separate log for lisibility
|
||||||
for l in traceback.format_exception(*exc):
|
for l in traceback.format_exception(*exc):
|
||||||
cherrypy.log.error_log.log(severity, l)
|
cherrypy.log.error_log.log(severity, l)
|
||||||
finally:
|
finally:
|
||||||
del exc
|
del exc
|
||||||
|
|
||||||
|
|
||||||
class LdapCherry(object):
|
class LdapCherry(object):
|
||||||
|
|
||||||
def _handle_exception(self, e):
|
def _handle_exception(self, e):
|
||||||
@ -206,7 +209,6 @@ class LdapCherry(object):
|
|||||||
)
|
)
|
||||||
self.roles = Roles(self.roles_file)
|
self.roles = Roles(self.roles_file)
|
||||||
|
|
||||||
|
|
||||||
def _set_access_log(self, config, level):
|
def _set_access_log(self, config, level):
|
||||||
""" Configure access logs
|
""" Configure access logs
|
||||||
"""
|
"""
|
||||||
@ -556,7 +558,6 @@ class LdapCherry(object):
|
|||||||
severity=logging.DEBUG
|
severity=logging.DEBUG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _modify_attrs(self, params, attr_list, username):
|
def _modify_attrs(self, params, attr_list, username):
|
||||||
badd = {}
|
badd = {}
|
||||||
for attr in attr_list:
|
for attr in attr_list:
|
||||||
|
@ -16,6 +16,7 @@ import yaml
|
|||||||
|
|
||||||
types = ['string', 'email', 'int', 'stringlist', 'fix', 'password']
|
types = ['string', 'email', 'int', 'stringlist', 'fix', 'password']
|
||||||
|
|
||||||
|
|
||||||
class Attributes:
|
class Attributes:
|
||||||
|
|
||||||
def __init__(self, attributes_file):
|
def __init__(self, attributes_file):
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
from ldapcherry.exceptions import MissingParameter
|
from ldapcherry.exceptions import MissingParameter
|
||||||
|
|
||||||
|
|
||||||
class Backend:
|
class Backend:
|
||||||
|
|
||||||
def __init__(self, config, logger, name, attrslist, key):
|
def __init__(self, config, logger, name, attrslist, key):
|
||||||
@ -46,4 +47,3 @@ class Backend:
|
|||||||
return default
|
return default
|
||||||
else:
|
else:
|
||||||
raise MissingParameter('backends', self.backend_name + '.' + param)
|
raise MissingParameter('backends', self.backend_name + '.' + param)
|
||||||
|
|
||||||
|
@ -13,11 +13,13 @@ import ldapcherry.backend
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class DelUserDontExists(Exception):
|
class DelUserDontExists(Exception):
|
||||||
def __init__(self, user):
|
def __init__(self, user):
|
||||||
self.user = user
|
self.user = user
|
||||||
self.log = "cannot remove user, user <%(user)s> does not exist" % {'user': user}
|
self.log = "cannot remove user, user <%(user)s> does not exist" % {'user': user}
|
||||||
|
|
||||||
|
|
||||||
class CaFileDontExist(Exception):
|
class CaFileDontExist(Exception):
|
||||||
def __init__(self, cafile):
|
def __init__(self, cafile):
|
||||||
self.cafile = cafile
|
self.cafile = cafile
|
||||||
@ -28,6 +30,7 @@ DISPLAYED_ATTRS = 1
|
|||||||
LISTED_ATTRS = 2
|
LISTED_ATTRS = 2
|
||||||
ALL_ATTRS = 3
|
ALL_ATTRS = 3
|
||||||
|
|
||||||
|
|
||||||
class Backend(ldapcherry.backend.Backend):
|
class Backend(ldapcherry.backend.Backend):
|
||||||
|
|
||||||
def __init__(self, config, logger, name, attrslist, key):
|
def __init__(self, config, logger, name, attrslist, key):
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import ldapcherry.backend
|
import ldapcherry.backend
|
||||||
|
|
||||||
|
|
||||||
class Backend(ldapcherry.backend.Backend):
|
class Backend(ldapcherry.backend.Backend):
|
||||||
|
|
||||||
def __init__(self, config, logger, name, attrslist, key):
|
def __init__(self, config, logger, name, attrslist, key):
|
||||||
|
@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
|
||||||
class MissingParameter(Exception):
|
class MissingParameter(Exception):
|
||||||
def __init__(self, section, key):
|
def __init__(self, section, key):
|
||||||
self.section = section
|
self.section = section
|
||||||
self.key = key
|
self.key = key
|
||||||
self.log = "missing parameter '%(key)s' in section '%(section)s'" % {'key': key, 'section': section}
|
self.log = "missing parameter '%(key)s' in section '%(section)s'" % {'key': key, 'section': section}
|
||||||
|
|
||||||
|
|
||||||
class MissingKey(Exception):
|
class MissingKey(Exception):
|
||||||
def __init__(self, key, section, ymlfile):
|
def __init__(self, key, section, ymlfile):
|
||||||
self.key = key
|
self.key = key
|
||||||
@ -20,57 +22,68 @@ class MissingKey(Exception):
|
|||||||
self.ymlfile = ymlfile
|
self.ymlfile = ymlfile
|
||||||
self.log = "missing key '%(key)s' in section '%(section)s' inside file '%(ymlfile)s'" % {'key': key, 'section': section, '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):
|
class DumplicateRoleKey(Exception):
|
||||||
def __init__(self, role):
|
def __init__(self, role):
|
||||||
self.role = role
|
self.role = role
|
||||||
self.log = "duplicate role key '%(role)s' in role file" % {'role': role}
|
self.log = "duplicate role key '%(role)s' in role file" % {'role': role}
|
||||||
|
|
||||||
|
|
||||||
class MissingRole(Exception):
|
class MissingRole(Exception):
|
||||||
def __init__(self, role):
|
def __init__(self, role):
|
||||||
self.role = role
|
self.role = role
|
||||||
self.log = "role '%(role)s' does not exist in role file" % {'role': role}
|
self.log = "role '%(role)s' does not exist in role file" % {'role': role}
|
||||||
|
|
||||||
|
|
||||||
class MissingBackend(Exception):
|
class MissingBackend(Exception):
|
||||||
def __init__(self, backend):
|
def __init__(self, backend):
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
self.log = "backend '%(backend)s' does not exist in main config file" % {'backend': backend}
|
self.log = "backend '%(backend)s' does not exist in main config file" % {'backend': backend}
|
||||||
|
|
||||||
|
|
||||||
class WrongBackend(Exception):
|
class WrongBackend(Exception):
|
||||||
def __init__(self, backend):
|
def __init__(self, backend):
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
self.log = "backend '%(backend)s' does not exist" % {'backend': backend}
|
self.log = "backend '%(backend)s' does not exist" % {'backend': backend}
|
||||||
|
|
||||||
|
|
||||||
class DumplicateRoleContent(Exception):
|
class DumplicateRoleContent(Exception):
|
||||||
def __init__(self, role1, role2):
|
def __init__(self, role1, role2):
|
||||||
self.role1 = role1
|
self.role1 = role1
|
||||||
self.role2 = role2
|
self.role2 = role2
|
||||||
self.log = "role '%(role1)s' and '%(role2)s' are identical" % {'role1': role1, 'role2': role2}
|
self.log = "role '%(role1)s' and '%(role2)s' are identical" % {'role1': role1, 'role2': role2}
|
||||||
|
|
||||||
|
|
||||||
class MissingRolesFile(Exception):
|
class MissingRolesFile(Exception):
|
||||||
def __init__(self, rolefile):
|
def __init__(self, rolefile):
|
||||||
self.rolefile = rolefile
|
self.rolefile = rolefile
|
||||||
self.log = "fail to open role file '%(rolefile)s'" % {'rolefile': rolefile}
|
self.log = "fail to open role file '%(rolefile)s'" % {'rolefile': rolefile}
|
||||||
|
|
||||||
|
|
||||||
class MissingMainFile(Exception):
|
class MissingMainFile(Exception):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.rolefile = rolefile
|
self.rolefile = rolefile
|
||||||
self.log = "fail to open main file '%(config)s'" % {'rolefile': rolefile}
|
self.log = "fail to open main file '%(config)s'" % {'rolefile': rolefile}
|
||||||
|
|
||||||
|
|
||||||
class MissingAttributesFile(Exception):
|
class MissingAttributesFile(Exception):
|
||||||
def __init__(self, attributesfile):
|
def __init__(self, attributesfile):
|
||||||
self.attributesfile = attributesfile
|
self.attributesfile = attributesfile
|
||||||
self.log = "fail to open attributes file '%(attributesfile)s'" % {'attributesfile': attributesfile}
|
self.log = "fail to open attributes file '%(attributesfile)s'" % {'attributesfile': attributesfile}
|
||||||
|
|
||||||
|
|
||||||
class BackendModuleLoadingFail(Exception):
|
class BackendModuleLoadingFail(Exception):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
self.log = "module '%(module)s' not in python path" % {'module': module}
|
self.log = "module '%(module)s' not in python path" % {'module': module}
|
||||||
|
|
||||||
|
|
||||||
class BackendModuleInitFail(Exception):
|
class BackendModuleInitFail(Exception):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
self.log = "fail to init module '%(module)s'" % {'module': module}
|
self.log = "fail to init module '%(module)s'" % {'module': module}
|
||||||
|
|
||||||
|
|
||||||
class WrongParamValue(Exception):
|
class WrongParamValue(Exception):
|
||||||
def __init__(self, param, section, possible_values):
|
def __init__(self, param, section, possible_values):
|
||||||
self.possible_values = possible_values
|
self.possible_values = possible_values
|
||||||
@ -79,16 +92,19 @@ class WrongParamValue(Exception):
|
|||||||
possible_values_str = string.join(possible_values, ', ')
|
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}
|
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):
|
class DumplicateUserKey(Exception):
|
||||||
def __init__(self, attrid1, attrid2):
|
def __init__(self, attrid1, attrid2):
|
||||||
self.attrid1 = attrid1
|
self.attrid1 = attrid1
|
||||||
self.attrid2 = attrid2
|
self.attrid2 = attrid2
|
||||||
self.log = "duplicate key in '%(attrid1)s' and '%(attrid2)s'" % {'attrid1': attrid1, 'attrid2': attrid2}
|
self.log = "duplicate key in '%(attrid1)s' and '%(attrid2)s'" % {'attrid1': attrid1, 'attrid2': attrid2}
|
||||||
|
|
||||||
|
|
||||||
class MissingUserKey(Exception):
|
class MissingUserKey(Exception):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.log = "missing key"
|
self.log = "missing key"
|
||||||
|
|
||||||
|
|
||||||
class WrongAttributeType(Exception):
|
class WrongAttributeType(Exception):
|
||||||
def __init__(self, key, section, ymlfile):
|
def __init__(self, key, section, ymlfile):
|
||||||
self.key = key
|
self.key = key
|
||||||
|
@ -17,6 +17,7 @@ class RelationError(Exception):
|
|||||||
self.key = key
|
self.key = key
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
|
|
||||||
class DumplicatedKey(Exception):
|
class DumplicatedKey(Exception):
|
||||||
def __init__(self, host, key):
|
def __init__(self, host, key):
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -29,6 +30,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from yaml import Loader, Dumper
|
from yaml import Loader, Dumper
|
||||||
|
|
||||||
|
|
||||||
# PyYaml wrapper that loads yaml files throwing an exception
|
# PyYaml wrapper that loads yaml files throwing an exception
|
||||||
#if a key is dumplicated
|
#if a key is dumplicated
|
||||||
class MyLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver):
|
class MyLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver):
|
||||||
|
@ -15,12 +15,14 @@ from ldapcherry.pyyamlwrapper import DumplicatedKey
|
|||||||
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile, MissingRole
|
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile, MissingRole
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class CustomDumper(yaml.SafeDumper):
|
class CustomDumper(yaml.SafeDumper):
|
||||||
"A custom YAML dumper that never emits aliases"
|
"A custom YAML dumper that never emits aliases"
|
||||||
|
|
||||||
def ignore_aliases(self, _data):
|
def ignore_aliases(self, _data):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Roles:
|
class Roles:
|
||||||
|
|
||||||
def __init__(self, role_file):
|
def __init__(self, role_file):
|
||||||
|
Loading…
Reference in New Issue
Block a user