~ubuntu-branches/ubuntu/raring/trac-accountmanager/raring

« back to all changes in this revision

Viewing changes to acct_mgr/svnserve.py

  • Committer: Bazaar Package Importer
  • Author(s): Leo Costela
  • Date: 2008-07-15 17:21:11 UTC
  • Revision ID: james.westby@ubuntu.com-20080715172111-ool7wmy573gqolfr
Tags: upstream-0.2.1~vcs20080715
ImportĀ upstreamĀ versionĀ 0.2.1~vcs20080715

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf8 -*-
 
2
#
 
3
# Copyright (C) 2005 Matthew Good <trac@matt-good.net>
 
4
#
 
5
# "THE BEER-WARE LICENSE" (Revision 42):
 
6
# <trac@matt-good.net> wrote this file.  As long as you retain this notice you
 
7
# can do whatever you want with this stuff. If we meet some day, and you think
 
8
# this stuff is worth it, you can buy me a beer in return.   Matthew Good
 
9
#
 
10
# Author: Matthew Good <trac@matt-good.net>
 
11
 
 
12
import os
 
13
 
 
14
from trac.core import *
 
15
from trac.config import Configuration
 
16
from trac.versioncontrol import RepositoryManager
 
17
 
 
18
from api import IPasswordStore
 
19
from util import EnvRelativePathOption
 
20
 
 
21
class SvnServePasswordStore(Component):
 
22
    """PasswordStore implementation for reading svnserve's password file format
 
23
    """
 
24
 
 
25
    implements(IPasswordStore)
 
26
 
 
27
    filename = EnvRelativePathOption('account-manager', 'password_file',
 
28
                                     doc='Path to the users file.  Leave '
 
29
                                         'blank to locate the users file '
 
30
                                         'by reading svnserve.conf')
 
31
 
 
32
    def __init__(self):
 
33
        repo_dir = RepositoryManager(self.env).repository_dir
 
34
        self._svnserve_conf = Configuration(os.path.join(repo_dir, 'svnserve.conf'))
 
35
        self._userconf = None
 
36
 
 
37
    def _config(self):
 
38
        filename = self.filename
 
39
        if not filename:
 
40
            self._svnserve_conf.parse_if_needed()
 
41
            filename = self._svnserve_conf['general'].getpath('password-db')
 
42
        if self._userconf is None or filename != self._userconf.filename:
 
43
            self._userconf = Configuration(filename)
 
44
        else:
 
45
            self._userconf.parse_if_needed()
 
46
        return self._userconf
 
47
    _config = property(_config)
 
48
 
 
49
    # IPasswordStore methods
 
50
 
 
51
    def get_users(self):
 
52
        return [user for (user,password) in self._config.options('users')]
 
53
 
 
54
    def has_user(self, user):
 
55
        return user in self._config['users']
 
56
 
 
57
    def set_password(self, user, password):
 
58
        cfg = self._config
 
59
        cfg.set('users', user, password)
 
60
        cfg.save()
 
61
 
 
62
    def check_password(self, user, password):
 
63
        return password == self._config.get('users', user)
 
64
 
 
65
    def delete_user(self, user):
 
66
        cfg = self._config
 
67
        cfg.remove('users', user)
 
68
        cfg.save()