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

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/listing.py

  • Committer: wagrant
  • Date: 2008-07-16 01:01:07 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:883
fileservice_lib: Partially factor out some triplicated file statting
                 functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
246
246
    
247
247
    return listing
248
248
 
249
 
def file_to_fileinfo(path, filename):
250
 
    """Given a filename (relative to a given path), gets all the info "ls"
251
 
    needs to display about the filename. Returns a dict containing a number
252
 
    of fields related to the file (excluding the filename itself)."""
253
 
    fullpath = path if len(filename) == 0 else os.path.join(path, filename)
254
 
    d = {}
 
249
def _fullpath_stat_fileinfo(fullpath, ind):
 
250
    d = ind.copy()
255
251
    file_stat = os.stat(fullpath)
256
252
    if stat.S_ISDIR(file_stat.st_mode):
257
253
        d["isdir"] = True
271
267
    d["mtime_short"] = make_date_nice_short(file_stat.st_mtime)
272
268
    return d
273
269
 
 
270
def file_to_fileinfo(path, filename):
 
271
    """Given a filename (relative to a given path), gets all the info "ls"
 
272
    needs to display about the filename. Returns a dict containing a number
 
273
    of fields related to the file (excluding the filename itself)."""
 
274
    fullpath = path if len(filename) == 0 else os.path.join(path, filename)
 
275
    return _fullpath_stat_fileinfo(fullpath, {})
 
276
 
274
277
def PysvnStatus_to_fileinfo(path, status):
275
278
    """Given a PysvnStatus object, gets all the info "ls"
276
279
    needs to display about the filename. Returns a pair mapping filename to
293
296
    text_status = status.text_status
294
297
    d["svnstatus"] = str(text_status)
295
298
    try:
296
 
        file_stat = os.stat(fullpath)
297
 
        if stat.S_ISDIR(file_stat.st_mode):
298
 
            d["isdir"] = True
299
 
            d["type_nice"] = util.nice_filetype("/")
300
 
            # Only directories can be published
301
 
            d["published"] = studpath.published(fullpath)
302
 
        else:
303
 
            d["isdir"] = False
304
 
            d["size"] = file_stat.st_size
305
 
            (type, _) = mimetypes.guess_type(fullpath)
306
 
            if type is None:
307
 
                type = conf.mimetypes.default_mimetype
308
 
            d["type"] = type
309
 
            d["type_nice"] = util.nice_filetype(filename)
310
 
        d["mtime"] = file_stat.st_mtime
311
 
        d["mtime_nice"] = make_date_nice(file_stat.st_mtime)
312
 
        d["mtime_short"] = make_date_nice_short(file_stat.st_mtime)
 
299
        d = _fullpath_stat_fileinfo(fullpath, d)
313
300
    except OSError:
314
301
        # Here if, eg, the file is missing.
315
302
        # Can't get any more information so just return d