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

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/action.py

  • Committer: mattgiuca
  • Date: 2008-06-23 10:34:43 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:787
fileservice_lib/action.py:
    * Fixed TODOs, and comments.
    * putfile: Added "overwrite" optional parameter. If true, overwrites,
      otherwise error. Note: This changes the default behaviour (used to
      overwrite by default).
editor.js: Call to putfile has overwrite: true, as necessary to keep the old
    behaviour.
listing.js: Comment on "new file".

Note: This commit changes the behaviour of "new file" so it has an error if
the file already exists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#       to:     The path of the target filename. Error if the file already
42
42
#               exists.
43
43
#
44
 
# action=putfile: Upload a file to the student workspace, and optionally
45
 
#               accept zip files which will be unpacked.
46
 
#       path:   The path to the file to be written. If it exists, will
47
 
#               overwrite. Error if the target file is a directory.
 
44
# action=putfile: Upload a file to the student workspace.
 
45
#       path:   The path to the file to be written. Error if the target
 
46
#               file is a directory.
48
47
#       data:   Bytes to be written to the file verbatim. May either be
49
48
#               a string variable or a file upload.
50
 
#       unpack: Optional. If "true", and the data is a valid ZIP file,
51
 
#               will create a directory instead and unpack the ZIP file
52
 
#               into it.
 
49
#       overwrite: Optional. If supplied, the file will be overwritten.
 
50
#               Otherwise, error if path already exists.
53
51
#
54
52
# action=putfiles: Upload multiple files to the student workspace, and
55
53
#                 optionally accept zip files which will be unpacked.
58
56
#       data:   A file upload (may not be a simple string). The filename
59
57
#               will be used to determine the target filename within
60
58
#               the given path.
61
 
#       unpack: Optional. If "true", if any data is a valid ZIP file,
 
59
#       unpack: Optional. If supplied, if any data is a valid ZIP file,
62
60
#               will create a directory instead and unpack the ZIP file
63
61
#               into it.
64
62
#
67
65
#               does. The dir will be made with this name.
68
66
#
69
67
# The differences between putfile and putfiles are:
70
 
# * putfile can only accept a single file.
 
68
# * putfile can only accept a single file, and can't unpack zipfiles.
71
69
# * putfile can accept string data, doesn't have to be a file upload.
72
70
# * putfile ignores the upload filename, the entire filename is specified on
73
71
#       path. putfiles calls files after the name on the user's machine.
113
111
#               checked out.
114
112
115
113
# TODO: Implement the following actions:
116
 
#   putfiles, svnrevert, svnupdate, svncommit
117
 
# TODO: Implement ZIP unpacking in putfile and putfiles.
 
114
#   svnupdate (done?)
 
115
# TODO: Implement ZIP unpacking in putfiles (done?).
118
116
# TODO: svnupdate needs a digest to tell the user the files that were updated.
119
117
#   This can be implemented by some message passing between action and
120
118
#   listing, and having the digest included in the listing. (Problem if
315
313
    """Writes data to a file, overwriting it if it exists and creating it if
316
314
    it doesn't.
317
315
 
318
 
    Reads fields: 'path', 'data' (file upload)
 
316
    Reads fields: 'path', 'data' (file upload), 'overwrite'
319
317
    """
320
318
    # TODO: Read field "unpack".
321
319
    # Important: Data is "None" if the file submitted is empty.
332
330
    if data is not None:
333
331
        data = cStringIO.StringIO(data)
334
332
 
 
333
    overwrite = fields.getfirst('overwrite')
 
334
    if overwrite is None:
 
335
        overwrite = False
 
336
    else:
 
337
        overwrite = True
 
338
 
 
339
    if not overwrite:
 
340
        if os.path.exists(path):
 
341
            raise ActionError("A file with that name already exists")
 
342
 
335
343
    # Copy the contents of file object 'data' to the path 'path'
336
344
    try:
337
345
        dest = open(path, 'wb')