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