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

« back to all changes in this revision

Viewing changes to services/usrmgt-server

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import logging
6
6
 
7
7
import ivle.conf
8
 
import ivle.db
 
8
import ivle.database
9
9
import ivle.chat
10
10
import ivle.makeuser
11
11
 
27
27
#   - Rebuild svn auth file
28
28
#   - Rebuild passwd + push to nodes.
29
29
 
30
 
def activate_user(props):
 
30
def activate_user(store, props):
31
31
    """Create the on-disk stuff for the given user.
32
32
       Sets the state of the user in the db from pending to enabled.
33
33
       Expected properties:
40
40
 
41
41
    login = props['login']
42
42
 
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):
 
43
    # FIXME: check we're pending
 
44
 
 
45
    # Get the full User object from the db associated with this
 
46
    user = ivle.database.User.get_by_login(store, login)
 
47
 
 
48
    # make svn config/auth
 
49
    repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
 
50
    logging.debug("Creating user's Subversion repository")
 
51
    ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
 
52
 
 
53
    rebuild_svn_config(store, props)
 
54
 
 
55
    logging.debug("Adding Subversion authentication")
 
56
    passwd = ivle.makeuser.make_svn_auth(store, login,
 
57
                                         throw_on_error=True)
 
58
 
 
59
    logging.debug("Creating jail")
 
60
    ivle.makeuser.make_jail(user)
 
61
 
 
62
    logging.info("Enabling user")
 
63
    user.state = u'enabled'
 
64
 
 
65
    return {"response": "okay"}
 
66
 
 
67
def rebuild_svn_config(store, props):
75
68
    """Rebuilds the svn config file
76
69
    Return value:
77
70
        response (okay, failure)
78
71
    """
79
72
    try:
80
 
        ivle.makeuser.rebuild_svn_config()
 
73
        ivle.makeuser.rebuild_svn_config(store)
81
74
    except Exception, e:
82
75
        logging.warning('Rebuild of Subversion authorization config failed!')
83
76
        return{'response': 'failure', 'msg': repr(e)}
84
77
 
85
78
    return {'response': 'okay'}
86
79
 
87
 
def rebuild_svn_group_config(props):
 
80
def rebuild_svn_group_config(store, props):
88
81
    """Rebuilds the svn group config file
89
82
    Return value:
90
83
        response (okay, failure)
91
84
    """
92
85
    try:
93
 
        ivle.makeuser.rebuild_svn_group_config()
 
86
        ivle.makeuser.rebuild_svn_group_config(store)
94
87
    except Exception, e:
95
88
        logging.warning(
96
89
            'Rebuild of Subversion group authorization config failed!')
98
91
 
99
92
    return {'response': 'okay'}
100
93
 
101
 
def create_group_repository(props):
 
94
def create_group_repository(store, props):
102
95
    """Creates on disk repository for the given group
103
96
    Expected properties:
104
97
        subj_short_name, year, semester, groupnm
141
134
 
142
135
def dispatch(props):
143
136
    logging.debug(repr(props))
 
137
 
 
138
    store = ivle.database.get_store()
144
139
    action = props.keys()[0]
145
 
    return actions[action](props[action])
 
140
    res = actions[action](store, props[action])
 
141
 
 
142
    if res['response'] == 'okay':
 
143
        store.commit()
 
144
    else:
 
145
        store.rollback()
 
146
    store.close()
 
147
    return res
146
148
 
147
149
if __name__ == "__main__":
148
150
    pid = os.getpid()