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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: mattgiuca
  • Date: 2008-02-15 04:45:12 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:472
db.py: No longer exceptions if password is not supplied.
makeuser: Converted explicit args into kwargs which are simply forwarded along
    to db. Makeuser db NO LONGER accepts "force" argument (which used to
    delete and replace login rows). This is dangerous, and we have removed the
    delete user functionality altogether - because we never delete users.
makeuser.py (script): Major change. Replaced the command-line interface so it
    now only takes 3 required arguments, and a bunch of optional arguments
    getopts style.
    All the arguments are specified at the top; the rest of the code works
    with these data structures so they are only specified in one place
    (including all the work of putting them into a dict and passing it to the
    database).
    Note that makeuser.py is a *second* point of control for the list of the
    login fields (the other is in db.DB.login_fields_list). This is by design,
    because there is a semantic difference between "what fields are in the db"
    and "what arguments should we accept on the command line".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
# IVLE - Informatics Virtual Learning Environment
4
 
# Copyright (C) 2007-2008 The University of Melbourne
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 2 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 
20
 
# Script: serveservice
21
 
# Author: Thomas Conway
22
 
# Date:   6/3/2007
23
 
 
24
 
# A CGI script for serving files.
25
 
 
26
 
import mimetypes
27
 
import os
28
 
import StringIO
29
 
import urlparse
30
 
 
31
 
from ivle import (cgirequest, studpath)
32
 
from ivle import zip as zipmod
33
 
 
34
 
req = cgirequest.CGIRequest()
35
 
req.install_error_handler()
36
 
 
37
 
# Work out the parts of the URL
38
 
url = urlparse.urlparse(req.path)
39
 
querystr = url[4]
40
 
urlpath = url[2]
41
 
filename = studpath.url_to_jailpaths(urlpath)[2]
42
 
 
43
 
default_mimetype = "application/octet-stream"
44
 
zip_mimetype = "application/zip"
45
 
 
46
 
zipmode = False
47
 
zipbasepath = None
48
 
zipfilename = None
49
 
path = None
50
 
 
51
 
# If any "path=" variables have been supplied, bring these into a list and
52
 
# make a zip file instead.
53
 
fields = req.get_fieldstorage()
54
 
paths = fields.getlist("path")
55
 
if len(paths) > 0:
56
 
    zipmode = True
57
 
    zipbasepath = filename
58
 
    zipfilename = os.path.basename(zipbasepath)
59
 
    #for i in range(0, len(paths)):
60
 
        #paths[i] = paths[i].value
61
 
else:
62
 
    if filename is None:
63
 
        req.throw_error(req.HTTP_NOT_FOUND,
64
 
            "The path specified is invalid.")
65
 
    elif not os.access(filename, os.R_OK):
66
 
        req.throw_error(req.HTTP_NOT_FOUND,
67
 
            "The specified file (%s) does not exist." % urlpath)
68
 
     # If it's a directory, serve as a zip file
69
 
    if os.path.isdir(filename):
70
 
        zipmode = True
71
 
        # Zip it from the perspective of its own parent.
72
 
        # That way it will be a directory in the top level of the zip
73
 
        # file.
74
 
        if filename[-1] == os.sep: filename = filename[:-1]
75
 
        splitpath = filename.rsplit(os.sep, 1)
76
 
        if len(splitpath) == 1:
77
 
            zipbasepath = ''
78
 
            paths = [filename]
79
 
        else:
80
 
            zipbasepath = splitpath[0]
81
 
            paths = [splitpath[1]]
82
 
        zipfilename = paths[0]
83
 
 
84
 
if zipmode:
85
 
    req.content_type = zip_mimetype
86
 
    # zipfilename is some filename. Strip trailing slash or extension,
87
 
    # and add ".zip".
88
 
    if zipfilename == '':
89
 
        zipfilename = "files"
90
 
    elif zipfilename[-1] == '/':
91
 
        zipfilename = zipfilename[:-1]
92
 
    elif '.' in zipfilename:
93
 
        zipfilename = zipfilename[:zipfilename.rindex('.')]
94
 
    zipfilename += ".zip"
95
 
    req.headers_out["Content-Disposition"] = ("attachment; filename=" +   
96
 
        zipfilename)
97
 
    zipfile = StringIO.StringIO()
98
 
    zipmod.make_zip(zipbasepath, paths, zipfile)
99
 
        
100
 
    req.write(zipfile.getvalue())
101
 
else:
102
 
    #req.content_type = default_mimetype
103
 
    req.sendfile(filename)