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

« back to all changes in this revision

Viewing changes to services/usrmgt-server

  • Committer: matt.giuca
  • Date: 2009-01-19 07:09:25 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1168
subjects/sample/subject.xml: Made the first worksheet assessable, so we can
    test out the "subject menu" page display of completion.

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
8
 
import ivle.database
 
7
import ivle.conf
 
8
import ivle.db
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(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
39
    os.umask(0022) # Bad, but start_server sets it worse.
43
40
 
44
41
    login = props['login']
45
42
 
46
 
    # FIXME: check we're pending
47
 
 
48
 
    # Get the full User object from the db associated with this
49
 
    user = ivle.database.User.get_by_login(store, login)
50
 
 
51
 
    # make svn config/auth
52
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
53
 
                            'users', login)
54
 
    logging.debug("Creating user's Subversion repository")
55
 
    ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
56
 
 
57
 
    rebuild_svn_config(store, props, config)
58
 
 
59
 
    logging.debug("Adding Subversion authentication")
60
 
    passwd = ivle.makeuser.make_svn_auth(store, login, config,
61
 
                                         throw_on_error=True)
62
 
 
63
 
    logging.debug("Creating jail")
64
 
    ivle.makeuser.make_jail(user, config)
65
 
 
66
 
    logging.info("Enabling user")
67
 
    user.state = u'enabled'
68
 
 
69
 
    return {"response": "okay"}
70
 
 
71
 
def rebuild_svn_config(store, props, config):
 
43
    db = ivle.db.DB()
 
44
 
 
45
    try:
 
46
 
 
47
        # FIXME: check we're pending
 
48
 
 
49
        details = db.get_user(login)
 
50
 
 
51
        # make svn config/auth
 
52
 
 
53
        repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
 
54
        logging.debug("Creating user's Subversion repository")
 
55
        ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
 
56
 
 
57
        rebuild_svn_config(props)
 
58
 
 
59
        logging.debug("Adding Subversion authentication")
 
60
        passwd = ivle.makeuser.make_svn_auth(login, throw_on_error=True)
 
61
        logging.debug("passwd: %s" % passwd)
 
62
 
 
63
        logging.debug("Creating jail")
 
64
        ivle.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
 
65
 
 
66
        logging.info("Enabling user")
 
67
        db.update_user(login, state='enabled')
 
68
 
 
69
        return {"response": "okay"}
 
70
 
 
71
    finally:
 
72
        db.close()
 
73
 
 
74
def rebuild_svn_config(props):
72
75
    """Rebuilds the svn config file
73
 
    @param config: An ivle.config.Config object.
74
 
    @return: response (okay, failure)
 
76
    Return value:
 
77
        response (okay, failure)
75
78
    """
76
79
    try:
77
 
        ivle.makeuser.rebuild_svn_config(store, config)
 
80
        ivle.makeuser.rebuild_svn_config()
78
81
    except Exception, e:
79
82
        logging.warning('Rebuild of Subversion authorization config failed!')
80
83
        return{'response': 'failure', 'msg': repr(e)}
81
84
 
82
85
    return {'response': 'okay'}
83
86
 
84
 
def rebuild_svn_group_config(store, props, config):
 
87
def rebuild_svn_group_config(props):
85
88
    """Rebuilds the svn group config file
86
 
    @param config: An ivle.config.Config object.
87
 
    @return: response (okay, failure)
 
89
    Return value:
 
90
        response (okay, failure)
88
91
    """
89
92
    try:
90
 
        ivle.makeuser.rebuild_svn_group_config(store, config)
 
93
        ivle.makeuser.rebuild_svn_group_config()
91
94
    except Exception, e:
92
95
        logging.warning(
93
96
            'Rebuild of Subversion group authorization config failed!')
95
98
 
96
99
    return {'response': 'okay'}
97
100
 
98
 
def create_group_repository(store, props, config):
 
101
def create_group_repository(props):
99
102
    """Creates on disk repository for the given group
100
 
    @param config: An ivle.config.Config object.
101
103
    Expected properties:
102
104
        subj_short_name, year, semester, groupnm
103
 
    @return: response (okay, failure)
 
105
    Return value:
 
106
        response (okay, failure)
104
107
    """
105
108
 
106
109
    subj_short_name = props['subj_short_name']
109
112
    groupnm = props['groupnm']
110
113
 
111
114
    namespace = "_".join([subj_short_name, year, semester, groupnm])
112
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
113
 
                            'groups', namespace)
 
115
    repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
114
116
    logging.debug("Creating Subversion repository %s"%repopath)
115
117
    try:
116
118
        ivle.makeuser.make_svn_repo(repopath)
129
131
    }
130
132
 
131
133
def initializer():
132
 
    logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
133
 
    logging.info("Starting usrmgt server on port %d (pid = %d)" %
134
 
                 (config['usrmgt']['port'], pid))
135
 
 
136
134
    try:
137
135
        pidfile = open('/var/run/usrmgt-server.pid', 'w')
138
136
        pidfile.write('%d\n' % os.getpid())
143
141
 
144
142
def dispatch(props):
145
143
    logging.debug(repr(props))
146
 
 
147
 
    store = ivle.database.get_store(config)
148
144
    action = props.keys()[0]
149
 
    res = actions[action](store, props[action], config)
150
 
 
151
 
    if res['response'] == 'okay':
152
 
        store.commit()
153
 
    else:
154
 
        store.rollback()
155
 
    store.close()
156
 
    return res
 
145
    return actions[action](props[action])
157
146
 
158
147
if __name__ == "__main__":
159
148
    pid = os.getpid()
160
149
 
161
 
    ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
 
150
    logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
 
151
    logging.info("Starting usrmgt server on port %d (pid = %d)" %
 
152
                 (ivle.conf.usrmgt_port, pid))
 
153
 
 
154
    ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
162
155
                           True, dispatch, initializer)