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

« back to all changes in this revision

Viewing changes to ivle/studpath.py

  • Committer: William Grant
  • Date: 2009-05-26 02:53:37 UTC
  • Revision ID: grantw@unimelb.edu.au-20090526025337-bok6syd4y9zpot8b
.. and one more

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(urlpath):
 
37
def url_to_local(config, 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
 
    See also: ivle.conf.jail_base
 
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')
55
59
    """
 
60
 
56
61
    # First normalise the path
57
62
    urlpath = os.path.normpath(urlpath)
58
63
    # Now if it begins with ".." or separator, then it's illegal
68
73
    # accordance with our directory scheme.
69
74
    # (The first time is the name of the jail, the second is the user's home
70
75
    # directory within the jail).
71
 
    path = os.path.join(ivle.conf.jail_base, user, 'home', urlpath)
 
76
    path = os.path.join(config['paths']['jails']['mounts'],
 
77
                        user, 'home', urlpath)
72
78
 
73
79
    return (user, path)
74
80
 
97
103
    if user is None: return (None, None, None)
98
104
 
99
105
    jail = os.path.join(ivle.conf.jail_base, user)
100
 
    path = os.path.join('/home', urlpath)
 
106
    path = to_home_path(urlpath)
101
107
 
102
108
    return (user, jail, path)
103
109
 
 
110
def to_home_path(urlpath):
 
111
    """Given a URL path (eg. joe/foo/bar/baz), returns a path within the home.
 
112
 
 
113
    >>> to_home_path('joe/foo/bar/baz')
 
114
    '/home/joe/foo/bar/baz'
 
115
    """
 
116
    return os.path.join('/home', urlpath)
 
117
 
104
118
def svnpublished(path):
105
119
    """Given a path on the LOCAL file system, determines whether the path has
106
120
    its "ivle:published" property active (in subversion). Returns True
162
176
    Same interface as "authorize" - None on success, HTTP_FORBIDDEN exception
163
177
    raised on failure.
164
178
    """
165
 
    _, path = url_to_local(req.path)
 
179
    _, path = url_to_local(req.config, req.path)
166
180
 
167
181
    # Walk up the tree, and find the deepest directory.
168
182
    while not os.path.isdir(path):