~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-25 06:20:32 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:313
test/test_framework: Updated examples, a bit of better descriptions, sample
    partial solutions, etc.

Added all sample subject material.
This has been copied from test/test_framework and modified slightly.
There is now a subject "sample" with 2 worksheets. The 1st worksheet has 3
exercises. These work in IVLE by default.

setup.py: Added code to install subjects into the designated directory. This
means that installing IVLE will result in the sample subjects being
immediately available.

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"