Commit 17c37f29 authored by Antoine Millet's avatar Antoine Millet
Browse files

Better implementation of the locking decorator.

parent d4984fec
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
@@ -46,6 +46,19 @@ import os
import re
from functools import wraps

def writer(func):
        '''
        Decorator used to threadsafize methods that made write operations on
        client configuration tree.
        '''

        @wraps(func)
        def f(self, *args, **kwargs):
            with self._lock:
                return func(self, *args, **kwargs)

        return f

class CCConf(object):
    '''
    Create a new configuration interface.
@@ -70,19 +83,6 @@ class CCConf(object):
    def __exit__(self, *args, **kwargs):
        return self._lock.__exit__(*args, **kwargs)    

    def _writer(func):
        '''
        Decorator used to threadsafize methods that made write operations on
        client configuration tree.
        '''

        @wraps(func)
        def f(self, *args, **kwargs):
            with self._lock:
                return func(self, *args, **kwargs)

        return f

    def _get_conf(self, login):
        '''
        Return the configuration of a client by its login.
@@ -233,7 +233,7 @@ class CCConf(object):
        else:
            return None

    @_writer
    @writer
    def set_password(self, login, password, method='ssha'):
        '''
        Update the client's password in the configuration.
@@ -249,7 +249,7 @@ class CCConf(object):
        conf['password'] = password
        self._set_conf(login, conf)

    @_writer
    @writer
    def add_tag(self, login, tag_name, tag_value):
        '''
        Add the tag to the user.
@@ -266,7 +266,7 @@ class CCConf(object):
        conf['tags'][tag_name] = tag_value
        self._set_conf(login, conf)

    @_writer
    @writer
    def remove_tag(self, login, tag):
        '''
        Remove the tag to the user.
@@ -282,7 +282,7 @@ class CCConf(object):
            del conf['tags'][tag]
        self._set_conf(login, conf)

    @_writer
    @writer
    def remove_account(self, login):
        '''
        Remove the configuration of the account.
@@ -298,7 +298,7 @@ class CCConf(object):
        else:
            raise CCConf.UnknownAccount('%s is not a file' % filename)

    @_writer
    @writer
    def create_account(self, login, role, password):
        '''
        Create a new account.
@@ -321,7 +321,7 @@ class CCConf(object):
                conf['password'] = self._hash_password(password)
            self._set_conf(login, conf, create=True)

    @_writer
    @writer
    def add_right(self, login, tql, method=None, target='allow', index=None):
        '''
        Add a right rule to the provided account.
@@ -346,7 +346,7 @@ class CCConf(object):
        rights.insert(index, rule)
        self._set_conf(login, conf)

    @_writer
    @writer
    def remove_right(self, login, index):
        '''
        Remove a right rule from the provided account.