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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/media.py

  • Committer: mattgiuca
  • Date: 2008-02-05 02:18:01 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:412
lib/common/makeuser: Removed function makeuser. This top-level function is too
    specific. Callers can decide how to call the various make-user functions.
    make_jail: Added "uid" argument. The caller needs to pass the UID who will
    own the jail. This unties the username from the uid.
    Now chowns and chmods 700 the user's home directory within the jail IF it
    is being created. If the jail already exists it is assumed the user has it
    set up the way they like and it is not disturbed.
makeuser.py: Script now performs top-level actions without calling
    makeuser.makeuser. This script currently creates the unix user itself
    (because the lib version doesn't support that anymore).
    It also checks for root, then calls make_user_db and make_jail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE
2
 
# Copyright (C) 2007-2009 The University of Melbourne
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
 
18
 
import os.path
19
 
 
20
 
from ivle.database import Subject
21
 
from ivle.webapp.media import MediaFileView
22
 
from ivle.webapp.publisher import INF
23
 
from ivle.webapp.publisher.decorators import forward_route
24
 
 
25
 
 
26
 
class SubjectMediaFile(object):
27
 
    """A subject content media file.
28
 
 
29
 
    Subject media can be dropped in
30
 
    /var/lib/ivle/content/subjects/$shortname/media,
31
 
    and will be served up at http://.../subjects/$shortname/+media.
32
 
    """
33
 
 
34
 
    def __init__(self, context, path):
35
 
        self.context = context
36
 
        self.path = path
37
 
        self.version = None
38
 
 
39
 
    @property
40
 
    def filename(self):
41
 
        """Calculate just the path under the subject content directory.
42
 
 
43
 
        The view will work out the rest of the path from the config.
44
 
        """
45
 
        subjectdir = os.path.join(self.context.short_name, 'media')
46
 
        return os.path.join(subjectdir, self.path)
47
 
 
48
 
    def get_permissions(self, user, config):
49
 
        return self.context.get_permissions(user, config)
50
 
 
51
 
 
52
 
class SubjectMediaView(MediaFileView):
53
 
    '''The view of subject media files.
54
 
 
55
 
    URIs pointing here will just be served directly, from the subject's
56
 
    media directory.
57
 
    '''
58
 
    permission = 'view'
59
 
 
60
 
    def get_filename(self, req):
61
 
        return os.path.join(
62
 
            req.config['paths']['data'],
63
 
            'content/subjects', self.context.filename)
64
 
 
65
 
    def get_permissions(self, user, config):
66
 
        return self.context.get_permissions(user, config)
67
 
 
68
 
 
69
 
@forward_route(Subject, '+media', argc=INF)
70
 
def subject_to_media(subject, *segments):
71
 
    path = os.path.normpath(os.path.join(*segments))
72
 
 
73
 
    return SubjectMediaFile(subject, path)
74