3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-28 13:42:37 +01:00

core: Rehashable permissions; import coremods on start

This commit is contained in:
James Lu 2016-08-25 12:07:55 -07:00
parent 6af8e77ee1
commit 556b388a4e
3 changed files with 18 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import os
from pylinkirc import world, utils, conf, classes
from pylinkirc.log import log, makeFileLogger, stopFileLoggers
from . import permissions
def remove_network(ircobj):
"""Removes a network object from the pool."""
@ -55,6 +56,10 @@ def _rehash():
for filename, config in files.items():
makeFileLogger(filename, config.get('loglevel'))
# Reset permissions.
log.debug('rehash: resetting permissions.')
permissions.resetPermissions()
for network, ircobj in world.networkobjects.copy().items():
# Server was removed from the config file, disconnect them.
log.debug('rehash: checking if %r is in new conf still.', network)

View File

@ -24,11 +24,19 @@ def resetPermissions():
global permissions
log.debug('permissions.resetPermissions: old perm list: %s', permissions)
new_permissions = default_permissions.copy()
log.debug('permissions.resetPermissions: new_permissions %s', new_permissions)
if not conf.conf.get('permissions_merge_defaults', True):
log.debug('permissions.resetPermissions: clearing perm list due to permissions_merge_defaults set False.')
permissions.clear()
new_permissions.clear()
permissions.update(conf.conf.get('permissions', default_permissions))
# Convert all perm lists to sets.
for k, v in conf.conf.get('permissions', {}).items():
new_permissions[k] |= set(v)
log.debug('permissions.resetPermissions: new_permissions %s', new_permissions)
permissions.clear()
permissions.update(new_permissions)
log.debug('permissions.resetPermissions: new perm list: %s', permissions)
def addDefaultPermissions(perms):
@ -64,7 +72,3 @@ def checkPermissions(irc, uid, perms, also_show=[]):
return True
raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" %
(', '.join(perms+also_show)))
# This is called on first import.
resetPermissions()

3
pylink
View File

@ -69,3 +69,6 @@ if __name__ == '__main__':
world.started.set()
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))
from pylinkirc import coremods
coremods.permissions.resetPermissions()