~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-10 21:47:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:169
Added global common css file (media/common/ivle.css).
dispatch.request: Added 2 new attributes: scripts and styles, which let apps
    specify arbitrary numbers of custom CSS and JavaScript files.
dispatch.html: Added media/common/ivle.css to the HTML header.
               Prints out all request custom CSS and JS files in the header.
apps.dummy: Test use of scripts and styles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    root = os.path.normpath(root_dir)
53
53
 
54
54
    if path.startswith(root):
55
 
        path = path[len(root):]
56
 
        # Take out the slash as well
57
 
        if path[0] == os.sep:
58
 
            path = path[1:]
59
 
 
60
 
    return path
 
55
        # +1 to take out the slash as well
 
56
        return path[len(root)+1:]
 
57
    else:
 
58
        return path
61
59
 
62
60
def split_path(path):
63
61
    """Given a path, returns a tuple consisting of the top-level directory in
99
97
for (ext, mimetype) in conf.mimetypes.additional_mime_types.items():
100
98
    mimetypes.add_type(mimetype, ext)
101
99
 
102
 
def nice_filetype(filename):
103
 
    """Given a filename or basename, returns a "friendly" name for that
104
 
    file's type.
105
 
    eg. nice_mimetype("file.py") == "Python source code".
106
 
        nice_filetype("file.bzg") == "BZG file".
107
 
        nice_filetype("directory/") == "Directory".
108
 
    """
109
 
    if filename[-1] == os.sep:
110
 
        return "Directory"
111
 
    else:
112
 
        try:
113
 
            return conf.mimetypes.nice_mimetypes[
114
 
                mimetypes.guess_type(filename)[0]]
115
 
        except KeyError:
116
 
            filename = os.path.basename(filename)
117
 
            try:
118
 
                return filename[filename.rindex('.')+1:].upper() + " file"
119
 
            except ValueError:
120
 
                return "File"