~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-10 00:10:11 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:149
fileservice:
    * Both subversion and OS mode listings now output "." as one of the files.
        This is deliberate in order for the client to see (by the presence or
        absence of the "svnstatus" attribute) whether this directory is
        under version control.
    * Directories no longer display a "type" attribute (since this was always
        just the default type, it's meaningless).
    * Fixed bug where unversioned directories inside a versioned directory
        output an empty listing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
            # Fallback to just an OS file listing.
172
172
            filenames = os.listdir(path)
173
173
            list = map(file_to_fileinfo(path), filenames)
 
174
            # The subversion one includes "." while the OS one does not.
 
175
            # Add "." to the output, so the caller can see we are
 
176
            # unversioned.
 
177
            list.append({"filename" : ".", "isdir" : True,
 
178
                "mtime" : time.ctime(os.path.getmtime(path))})
174
179
 
175
180
        req.write(cjson.encode(list))
176
181
    else:
193
198
    def ftf(filename):
194
199
        fullpath = os.path.join(path, filename)
195
200
        d = {"filename" : filename}
196
 
        (type, _) = mimetypes.guess_type(filename)
197
 
        if type is None:
198
 
            type = conf.mimetypes.default_mimetype
199
 
        d["type"] = type
200
201
        file_stat = os.stat(fullpath)
201
202
        if stat.S_ISDIR(file_stat.st_mode):
202
203
            d["isdir"] = True
203
204
        else:
204
205
            d["isdir"] = False
205
206
            d["size"] = file_stat.st_size
 
207
            (type, _) = mimetypes.guess_type(filename)
 
208
            if type is None:
 
209
                type = conf.mimetypes.default_mimetype
 
210
            d["type"] = type
206
211
        d["mtime"] = time.ctime(file_stat.st_mtime)
207
212
        return d
208
213
    return ftf
211
216
    """Given a PysvnStatus object, gets all the info "ls"
212
217
    needs to display about the filename. Returns a dict mapping a number of
213
218
    fields which are returned.
214
 
 
215
 
    May return None.
216
219
    """
217
220
    # Note: curried so it can be used with map
218
221
    path = os.path.normcase(path)
219
222
    def ftf(status):
220
223
        fullpath = status.path
221
 
        # For some reason it returns the dir itself. Exclude that.
 
224
        # If this is "." (the directory itself)
222
225
        if path == os.path.normcase(fullpath):
223
 
            return None
224
 
        d = {"filename" : os.path.basename(fullpath)}
 
226
            # If this directory is unversioned, then we aren't
 
227
            # looking at any interesting files, so throw
 
228
            # an exception and default to normal OS-based listing. 
 
229
            if status.text_status == pysvn.wc_status_kind.unversioned:
 
230
                raise pysvn.ClientError
 
231
            # We actually want to return "." because we want its
 
232
            # subversion status.
 
233
            filename = "."
 
234
        else:
 
235
            filename = os.path.basename(fullpath)
 
236
        d = {"filename" : filename}
225
237
        text_status = status.text_status
226
238
        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
231
239
        try:
232
240
            file_stat = os.stat(fullpath)
233
241
            if stat.S_ISDIR(file_stat.st_mode):
235
243
            else:
236
244
                d["isdir"] = False
237
245
                d["size"] = file_stat.st_size
 
246
                (type, _) = mimetypes.guess_type(fullpath)
 
247
                if type is None:
 
248
                    type = conf.mimetypes.default_mimetype
 
249
                d["type"] = type
238
250
            d["mtime"] = time.ctime(file_stat.st_mtime)
239
251
        except OSError:
240
252
            # Here if, eg, the file is missing.