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

« back to all changes in this revision

Viewing changes to www/common/util.py

  • Committer: mattgiuca
  • Date: 2008-01-13 23:38:58 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:213
Fileservice / Files (Python and JS files):
    Added code to handle "nice filetypes" and "nice svn status".
    New JSON value for dir listings, "type_nice" which contains the nice
    filetype calculated by the server.
    The client calculates the nice svn status.
    Added new icons for svn status for added, deleted, missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
for (ext, mimetype) in conf.mimetypes.additional_mime_types.items():
98
98
    mimetypes.add_type(mimetype, ext)
99
99
 
 
100
def nice_filetype(filename):
 
101
    """Given a filename or basename, returns a "friendly" name for that
 
102
    file's type.
 
103
    eg. nice_mimetype("file.py") == "Python source code".
 
104
        nice_filetype("file.bzg") == "BZG file".
 
105
        nice_filetype("directory/") == "Directory".
 
106
    """
 
107
    if filename[-1] == os.sep:
 
108
        return "Directory"
 
109
    else:
 
110
        try:
 
111
            return conf.mimetypes.nice_mimetypes[
 
112
                mimetypes.guess_type(filename)[0]]
 
113
        except KeyError:
 
114
            filename = os.path.basename(filename)
 
115
            try:
 
116
                return filename[filename.rindex('.')+1:].upper() + " file"
 
117
            except ValueError:
 
118
                return "File"