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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: William Grant
  • Date: 2009-02-17 01:53:44 UTC
  • mto: (1099.1.143 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: grantw@unimelb.edu.au-20090217015344-nqw060fa6ysk3e9h
Convince serveservice not to mangle single paths when downloading.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
# and does not execute CGI scripts.
52
52
if options.download:
53
53
    download = True
54
 
 
55
 
    dir = os.path.dirname(args[0])
56
 
 
 
54
    # paths is filled later.
 
55
else:
 
56
    download = False
 
57
    assert len(args) == 1
 
58
 
 
59
default_mimetype = "application/octet-stream"
 
60
zip_mimetype = "application/zip"
 
61
 
 
62
zipmode = False
 
63
zipbasepath = None
 
64
zipfilename = None
 
65
 
 
66
# If multiple paths have been specified, zip them up.
 
67
if len(args) > 1:
57
68
    # Mangle the paths - we want the basename of their dirname in front.
58
69
    paths = []
59
70
    for path in args:
61
72
        paths.append(os.path.join(os.path.basename(dir),
62
73
                                  os.path.basename(path)))
63
74
    dir = os.path.dirname(dir)
64
 
else:
65
 
    download = False
66
 
    paths = args
67
 
    assert len(paths) == 1
68
 
 
69
 
default_mimetype = "application/octet-stream"
70
 
zip_mimetype = "application/zip"
71
 
 
72
 
zipmode = False
73
 
zipbasepath = None
74
 
zipfilename = None
75
 
 
76
 
# If multiple paths have been specified, zip them up.
77
 
if len(paths) > 1:
78
75
    zipmode = True
79
76
    zipbasepath = dir
80
77
    zipfilename = os.path.basename(zipbasepath)
81
78
else:
 
79
    paths = args
82
80
    filename = paths[0]
83
81
    if not os.access(filename, os.F_OK):
84
82
        # The given path doesn't exist. CGI lets us backtrack and put the path
136
134
    #    zipfilename) # TODO
137
135
    zipfile = StringIO.StringIO()
138
136
    zipmod.make_zip(zipbasepath, paths, zipfile)
139
 
        
 
137
 
140
138
    print cjson.encode({'type': zip_mimetype,
141
139
                        'name': zipfilename})
142
140
    print zipfile.getvalue()