~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to services/usrmgt-server

  • Committer: William Grant
  • Date: 2009-02-27 05:07:09 UTC
  • Revision ID: grantw@unimelb.edu.au-20090227050709-k16kvhyl50nzjbwm
Subject URLs now contain the short name (eg. info1) rather than the code
(eg. 600151).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import sys
5
5
import logging
6
6
 
7
 
import ivle.config
 
7
import ivle.conf
8
8
import ivle.database
9
9
import ivle.chat
10
10
import ivle.makeuser
11
11
 
12
 
config = ivle.config.Config()
13
 
 
14
12
# usage:
15
13
#   usrmgt-server <port> <magic>
16
14
 
29
27
#   - Rebuild svn auth file
30
28
#   - Rebuild passwd + push to nodes.
31
29
 
32
 
def activate_user(store, props, config):
 
30
def activate_user(store, props):
33
31
    """Create the on-disk stuff for the given user.
34
32
       Sets the state of the user in the db from pending to enabled.
35
 
    @param config: An ivle.config.Config object.
36
33
       Expected properties:
37
34
        login       - the user name for the jail
38
35
                      STRING REQUIRED
39
 
    @return: None
 
36
       Return Value: None
40
37
    """
41
38
 
42
 
    if not os.path.exists(config['paths']['jails']['template']):
43
 
        return {
44
 
            'response': 'error',
45
 
            'message': 'Template jail has not been built -- '
46
 
                       'do you need to run ivle-buildjail?'}
47
 
 
48
39
    os.umask(0022) # Bad, but start_server sets it worse.
49
40
 
50
41
    login = props['login']
55
46
    user = ivle.database.User.get_by_login(store, login)
56
47
 
57
48
    # make svn config/auth
58
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
59
 
                            'users', login)
 
49
    repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
60
50
    logging.debug("Creating user's Subversion repository")
61
51
    ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
62
52
 
63
 
    rebuild_svn_config(store, props, config)
 
53
    rebuild_svn_config(store, props)
64
54
 
65
55
    logging.debug("Adding Subversion authentication")
66
 
    passwd = ivle.makeuser.make_svn_auth(store, login, config,
 
56
    passwd = ivle.makeuser.make_svn_auth(store, login,
67
57
                                         throw_on_error=True)
68
58
 
69
59
    logging.debug("Creating jail")
70
 
    ivle.makeuser.make_jail(user, config)
 
60
    ivle.makeuser.make_jail(user)
71
61
 
72
62
    logging.info("Enabling user")
73
63
    user.state = u'enabled'
74
64
 
75
65
    return {"response": "okay"}
76
66
 
77
 
def rebuild_svn_config(store, props, config):
 
67
def rebuild_svn_config(store, props):
78
68
    """Rebuilds the svn config file
79
 
    @param config: An ivle.config.Config object.
80
 
    @return: response (okay, failure)
 
69
    Return value:
 
70
        response (okay, failure)
81
71
    """
82
72
    try:
83
 
        ivle.makeuser.rebuild_svn_config(store, config)
 
73
        ivle.makeuser.rebuild_svn_config(store)
84
74
    except Exception, e:
85
75
        logging.warning('Rebuild of Subversion authorization config failed!')
86
76
        return{'response': 'failure', 'msg': repr(e)}
87
77
 
88
78
    return {'response': 'okay'}
89
79
 
90
 
def rebuild_svn_group_config(store, props, config):
 
80
def rebuild_svn_group_config(store, props):
91
81
    """Rebuilds the svn group config file
92
 
    @param config: An ivle.config.Config object.
93
 
    @return: response (okay, failure)
 
82
    Return value:
 
83
        response (okay, failure)
94
84
    """
95
85
    try:
96
 
        ivle.makeuser.rebuild_svn_group_config(store, config)
 
86
        ivle.makeuser.rebuild_svn_group_config(store)
97
87
    except Exception, e:
98
88
        logging.warning(
99
89
            'Rebuild of Subversion group authorization config failed!')
101
91
 
102
92
    return {'response': 'okay'}
103
93
 
104
 
def create_group_repository(store, props, config):
 
94
def create_group_repository(store, props):
105
95
    """Creates on disk repository for the given group
106
 
    @param config: An ivle.config.Config object.
107
96
    Expected properties:
108
97
        subj_short_name, year, semester, groupnm
109
 
    @return: response (okay, failure)
 
98
    Return value:
 
99
        response (okay, failure)
110
100
    """
111
101
 
112
102
    subj_short_name = props['subj_short_name']
115
105
    groupnm = props['groupnm']
116
106
 
117
107
    namespace = "_".join([subj_short_name, year, semester, groupnm])
118
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
119
 
                            'groups', namespace)
 
108
    repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
120
109
    logging.debug("Creating Subversion repository %s"%repopath)
121
110
    try:
122
111
        ivle.makeuser.make_svn_repo(repopath)
137
126
def initializer():
138
127
    logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
139
128
    logging.info("Starting usrmgt server on port %d (pid = %d)" %
140
 
                 (config['usrmgt']['port'], pid))
 
129
                 (ivle.conf.usrmgt_port, pid))
141
130
 
142
131
    try:
143
132
        pidfile = open('/var/run/usrmgt-server.pid', 'w')
150
139
def dispatch(props):
151
140
    logging.debug(repr(props))
152
141
 
153
 
    store = ivle.database.get_store(config)
 
142
    store = ivle.database.get_store()
154
143
    action = props.keys()[0]
155
 
    res = actions[action](store, props[action], config)
 
144
    res = actions[action](store, props[action])
156
145
 
157
146
    if res['response'] == 'okay':
158
147
        store.commit()
164
153
if __name__ == "__main__":
165
154
    pid = os.getpid()
166
155
 
167
 
    ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
 
156
    ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
168
157
                           True, dispatch, initializer)