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

« back to all changes in this revision

Viewing changes to ivle/studpath.py

  • Committer: Matt Giuca
  • Date: 2009-03-24 08:03:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090324080353-1w4oduwp7elujgs8
Fleshed out the documentation structure a bit.
Added a high-level description of the system on the front page, and 'dev' and
'man' sections.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# Make a Subversion client object (for published)
35
35
svnclient = pysvn.Client()
36
36
 
37
 
def url_to_local(config, urlpath):
 
37
def url_to_local(urlpath):
38
38
    """Given a URL path (part of a URL query string, see below), returns a
39
39
    tuple of
40
40
        * the username of the student whose directory is being browsed
51
51
 
52
52
    Returns (None, None) if the path is empty.
53
53
 
54
 
    >>> stubconfig = {'paths': {'jails': {'mounts': '/jails'}}}
55
 
    >>> url_to_local(stubconfig, '')
56
 
    (None, None)
57
 
    >>> url_to_local(stubconfig, 'joe/foo/bar/baz')
58
 
    ('joe', '/jails/joe/home/joe/foo/bar/baz')
 
54
    See also: ivle.conf.jail_base
59
55
    """
60
 
 
61
56
    # First normalise the path
62
57
    urlpath = os.path.normpath(urlpath)
63
58
    # Now if it begins with ".." or separator, then it's illegal
73
68
    # accordance with our directory scheme.
74
69
    # (The first time is the name of the jail, the second is the user's home
75
70
    # directory within the jail).
76
 
    path = os.path.join(config['paths']['jails']['mounts'],
77
 
                        user, 'home', urlpath)
 
71
    path = os.path.join(ivle.conf.jail_base, user, 'home', urlpath)
78
72
 
79
73
    return (user, path)
80
74
 
103
97
    if user is None: return (None, None, None)
104
98
 
105
99
    jail = os.path.join(ivle.conf.jail_base, user)
106
 
    path = url_path_to_jail_path(urlpath)
 
100
    path = os.path.join('/home', urlpath)
107
101
 
108
102
    return (user, jail, path)
109
103
 
110
 
def url_path_to_jail_path(urlpath):
111
 
    """Given a URL path (eg. joe/foo/bar/baz), returns a path within the jail.
112
 
 
113
 
    >>> url_path_to_jail_path('joe/foo/bar/baz')
114
 
    '/home/joe/foo/bar/baz'
115
 
    """
116
 
    return os.path.join('/home', urlpath)
117
 
 
118
104
def svnpublished(path):
119
105
    """Given a path on the LOCAL file system, determines whether the path has
120
106
    its "ivle:published" property active (in subversion). Returns True
176
162
    Same interface as "authorize" - None on success, HTTP_FORBIDDEN exception
177
163
    raised on failure.
178
164
    """
179
 
    _, path = url_to_local(req.config, req.path)
 
165
    _, path = url_to_local(req.path)
180
166
 
181
167
    # Walk up the tree, and find the deepest directory.
182
168
    while not os.path.isdir(path):