This is a list of Frequently Asked Questions for IVLE developers. It answers questions about common issues encountered when bludgeoning the system into behaving.
from ivle.config import Config
config = Config()
This makes config, a dictionary-tree containing the whole config hierarchy.
For example, to get the Subversion repository path, use config['paths']['svn']['repo_path'].
Note
For code running inside the jail, you will see different configuration variables than code running outside. It will be missing a lot of data, and will contain some user-specific data.
In all views derived from BaseView the authorize function is called to check if a user has access to a particular file. Often this is simply a check to ensure that the user is logged in (the value of ‘user’ is not None), but may be more complex such as checking if a user has a password hash set (to prevent clobbering of external auth) or checking if a user has permission to edit an Offering object.
IVLE exclusively uses the Storm API for database access. Do not write any SQL code yourself, or make use of low-level database libraries. The only exception is in preparing the database schema, which is stored as an SQL file.
Modify userdb/users.sql. Any changes also need to be made in to a migrations file, in userdb/migrations/.
TODO: More detail on migrations.
import ivle.database
# Typically, you import all database classes you want here
from ivle.database import User
You need a store object to perform any interactions with the database. If you are inside the web app, get a hold of the req (request) object, and use req.store. In other code, create a new store as follows (where config is a config object):
store = ivle.database.get_store(config)
You can read objects out of the database through the store. For example, to get a User object:
user = store.find(User, User.login==username).one()
(Note that store.find(User) just returns a sequence of all users.)
You can then treat user as a normal object, and read from its attributes. All of the classes are defined in ivle/database.py.
Note
The code must be executed outside of the jail. Jail code runs under user privileges and cannot access the database.
Note
For help with the database API, see the Storm documentation.
Get an object out of the database, as above, and simply write to the object’s attributes. This updates the in-memory copy of the data only.
To write the changes back to the database, simply use:
store.commit()
using the same store object as used to retrieve the object in the first place.
Create the new object using its constructor, as with any Python object. e.g.:
import ivle.database
user = ivle.database.User()
You can then set the attributes of the object as desired. As with writing, this only creates an in-memory object.
To add the object to the database, get a store, and use:
store.add(user)
store.commit()
User privileges are set by the get_permissions functions in ivle/database.py. Permissions are highly granular and can be set on almost every object in the database.
Most permissions are set on the Offering level with ProjectSet, Project and Worksheet simply delegating the check to Offering. Since Exercise may be shared between multiple Offerings, the permissions are calculated from the users active enrollments. Other objects such as User may only be modified by the user or an admin. If a user is not logged in (user is None) then they will typically receive no privileges at all.
All of the classes are defined in ivle/database.py.
All string data going into and out of Storm (i.e., the IVLE database classes) must be a Unicode string (type unicode), not a regular byte string (type str). If you have a regular string, convert it to Unicode by wrapping it in the unicode() function. For example:
username = unicode(username)
Get a config object, and use
repopath = os.path.join(config['paths']['svn']['repo_path'],
'users', username)
(This should probably be abstracted.)
Get a config object, and use
repourl = config['urls']['svn_addr'] + '/users/' + username
(This should probably be abstracted.)
import ivle.svn
svnclient = ivle.svn.create_auth_svn_client(username, password)
If you don’t have any auth credentials and you just want to do SVN things which don’t require auth (though I don’t see why this situation would arise), you can get an auth-less SVN client, which will raise exceptions if you try to do authy things (e.g., commit, update or checkout):
import pysvn
svnclient = pysvn.Client()
In either case, the client object will raise pysvn.ClientError objects, so you should be handling those.
You may wish to make error messages simpler using this line:
svnclient.exception_style = 0
A good example of Subversion client code is in ivle/fileservice_lib/action.py.