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

« back to all changes in this revision

Viewing changes to services/usrmgt-server

  • Committer: Matt Giuca
  • Date: 2009-12-01 04:27:58 UTC
  • mfrom: (1164.2.46 sphinx-docs)
  • Revision ID: matt.giuca@gmail.com-20091201042758-wuxd9bdec00c283i
Merged sphinx-docs branch. This adds Sphinx documentation for the entire IVLE system (for system administrators and developers), and removes all of our random old document files (all either irrelevant, or moved into the Sphinx docs nicely). Currently incomplete, but ready to merge.

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