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

« back to all changes in this revision

Viewing changes to ivle/util.py

  • Committer: William Grant
  • Date: 2009-04-28 06:02:41 UTC
  • Revision ID: grantw@unimelb.edu.au-20090428060241-t4gnwl35maukfvfg
Move ivle.conf.mimetypes to ivle.mimetypes, and rename things in it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# Date: 12/12/2007
21
21
 
22
22
# Contains common utility functions.
23
 
# Also initialises mime types library. You must import util before using
24
 
# Python's builtin mimetypes module to make sure local settings are applied.
25
23
 
26
24
import os
27
 
import mimetypes
28
25
import datetime
29
26
 
30
27
import ivle.conf
31
 
import ivle.conf.mimetypes
32
28
 
33
29
class IVLEError(Exception):
34
30
    """
127
123
    else:
128
124
        return tuple(splitpath)
129
125
 
130
 
def nice_filetype(filename):
131
 
    """Given a filename or basename, returns a "friendly" name for that
132
 
    file's type.
133
 
    eg. nice_mimetype("file.py") == "Python source code".
134
 
        nice_filetype("file.bzg") == "BZG file".
135
 
        nice_filetype("directory/") == "Directory".
136
 
    """
137
 
    if filename[-1] == os.sep:
138
 
        return "Directory"
139
 
    else:
140
 
        try:
141
 
            return ivle.conf.mimetypes.nice_mimetypes[
142
 
                mimetypes.guess_type(filename)[0]]
143
 
        except KeyError:
144
 
            filename = os.path.basename(filename)
145
 
            try:
146
 
                return filename[filename.rindex('.')+1:].upper() + " file"
147
 
            except ValueError:
148
 
                return "File"
149
 
 
150
126
def incomplete_utf8_sequence(byteseq):
151
127
    """
152
128
    str -> int