Utilities/MimeTypes.py

Sun, 08 Feb 2015 13:09:00 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 08 Feb 2015 13:09:00 +0100
changeset 4101
68c26f72c0d1
parent 4097
ad2a6bd965d9
child 4631
5c1a96925da4
permissions
-rw-r--r--

Added the capability to show a file's mime type and to add it to the text mime types list to the project others browser and the file browser.

# -*- coding: utf-8 -*-

# Copyright (c) 2014 - 2015 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing mimetype dependent functions.
"""

from __future__ import unicode_literals

import mimetypes

import Preferences


def isTextFile(filename):
    """
    Function to test, if the given file is a text (i.e. editable) file.
    
    @param filename name of the file to be checked (string)
    @return flag indicating an editable file (boolean)
    """
    type_ = mimetypes.guess_type(filename)[0]
    if (type_ is None or
        type_.split("/")[0] == "text" or
            type_ in Preferences.getUI("TextMimeTypes")):
        return True
    else:
        return False


def mimeType(filename):
    """
    Function to get the mime type of a file.
    
    @param filename name of the file to be checked (string)
    @return mime type of the file (string)
    """
    return mimetypes.guess_type(filename)[0]

eric ide

mercurial