File: fixroles.py

package info (click to toggle)
roundup 1.4.20-1.1
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 8,312 kB
  • sloc: python: 34,917; sh: 353; perl: 23; makefile: 19
file content (40 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys

from roundup import admin

class AdminTool(admin.AdminTool):
    def __init__(self):
        self.commands = admin.CommandDict()
        for k in AdminTool.__dict__.keys():
            if k[:3] == 'do_':
                self.commands[k[3:]] = getattr(self, k)
        self.help = {}
        for k in AdminTool.__dict__.keys():
            if k[:5] == 'help_':
                self.help[k[5:]] = getattr(self, k)
        self.instance_home = ''
        self.db = None

    def do_fixroles(self, args):
        '''Usage: fixroles
        Set the roles property for all users to reasonable defaults.

        The admin user gets "Admin", the anonymous user gets "Anonymous"
        and all other users get "User".
        '''
        # get the user class
        cl = self.get_class('user')
        for userid in cl.list():
            username = cl.get(userid, 'username')
            if username == 'admin':
                roles = 'Admin'
            elif username == 'anonymous':
                roles = 'Anonymous'
            else:
                roles = 'User'
            cl.set(userid, roles=roles)
        return 0

if __name__ == '__main__':
    tool = AdminTool()
    sys.exit(tool.main())