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