1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# Module: common.studpath
22
# Provides functions for translating URLs into physical locations in the
23
# student directories in the local file system.
28
from common import util
30
def url_to_local(urlpath):
31
"""Given a URL path (part of a URL query string, see below), returns a
33
* the username of the student whose directory is being browsed
34
* the absolute path in the file system where that file will be
35
found within the student directories.
37
urlpath: Part of the URL, but only the part *after* the application. For
38
instance, given the URL "/ivle/browse/joe/home/mydir/myfile", urlpath will
39
be just "joe/home/mydir/myfile". The expected result is something like
40
("joe", "/home/informatics/jails/joe/home/svn/mydir/myfile").
41
Note that the actual location is not guaranteed by this interface (this
42
function serves as a single point of control as to how URLs map onto
45
Returns (None, None) if the path is empty.
47
See also: conf.student_dir
49
(user, subpath) = util.split_path(urlpath)
50
if user is None: return (None, None)
52
# Note: For now this just re-joins user and subpath
53
# But we plan to muddle this around a bit so it's good that they are
55
path = os.path.join(conf.student_dir, user, subpath)