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

« back to all changes in this revision

Viewing changes to www/apps/fileservice/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-09 23:49:32 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:148
fileservice: Now dir listing returns a "type" field, the mime type guessed
(which is the same mime type that would be returned by fileservice if
this file was requested directly).
        Also directories no longer return a size (since this always returns
        the size of the inode; not something the client needs to know).

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
        req.headers_out['X-IVLE-Return'] = 'Dir'
162
162
        # Start by trying to do an SVN status, so we can report file version
163
163
        # status
164
 
        # TODO: Known bug:
165
 
        # Fatal error if any file is missing (deleted with rm instead of svn
166
 
        # rm)
167
 
        # Handle gracefully.
168
164
        try:
169
165
            status_list = svnclient.status(path, recurse=False, get_all=True,
170
166
                            update=False)
182
178
        # First get the mime type of this file
183
179
        # (Note that importing common.util has already initialised mime types)
184
180
        (type, _) = mimetypes.guess_type(path)
185
 
        if type is not None:
186
 
            req.content_type = type
187
 
        else:
188
 
            req.content_type = conf.mimetypes.default_mimetype
 
181
        if type is None:
 
182
            type = conf.mimetypes.default_mimetype
 
183
        req.content_type = type
189
184
        req.headers_out['X-IVLE-Return'] = 'File'
190
185
 
191
186
        req.sendfile(path)
198
193
    def ftf(filename):
199
194
        fullpath = os.path.join(path, filename)
200
195
        d = {"filename" : filename}
 
196
        (type, _) = mimetypes.guess_type(filename)
 
197
        if type is None:
 
198
            type = conf.mimetypes.default_mimetype
 
199
        d["type"] = type
201
200
        file_stat = os.stat(fullpath)
202
 
        d["isdir"] = stat.S_ISDIR(file_stat.st_mode)
203
 
        d["size"] = file_stat.st_size
 
201
        if stat.S_ISDIR(file_stat.st_mode):
 
202
            d["isdir"] = True
 
203
        else:
 
204
            d["isdir"] = False
 
205
            d["size"] = file_stat.st_size
204
206
        d["mtime"] = time.ctime(file_stat.st_mtime)
205
207
        return d
206
208
    return ftf
222
224
        d = {"filename" : os.path.basename(fullpath)}
223
225
        text_status = status.text_status
224
226
        d["svnstatus"] = str(text_status)
 
227
        (type, _) = mimetypes.guess_type(fullpath)
 
228
        if type is None:
 
229
            type = conf.mimetypes.default_mimetype
 
230
        d["type"] = type
225
231
        try:
226
232
            file_stat = os.stat(fullpath)
227
 
            d["isdir"] = stat.S_ISDIR(file_stat.st_mode)
228
 
            d["size"] = file_stat.st_size
 
233
            if stat.S_ISDIR(file_stat.st_mode):
 
234
                d["isdir"] = True
 
235
            else:
 
236
                d["isdir"] = False
 
237
                d["size"] = file_stat.st_size
229
238
            d["mtime"] = time.ctime(file_stat.st_mtime)
230
239
        except OSError:
231
240
            # Here if, eg, the file is missing.