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

« back to all changes in this revision

Viewing changes to ivle/studpath.py

  • Committer: Matt Giuca
  • Date: 2009-05-26 04:15:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090526041523-hsg5q2enlhvjb5y2
doc/man/architecture.rst: User management server.

Show diffs side-by-side

added added

removed removed

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