Sun, 08 Feb 2015 13:09:00 +0100
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.
3565
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
4021
195a471c327b
Updated copyright for 2015.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3619
diff
changeset
|
3 | # Copyright (c) 2014 - 2015 Detlev Offenbach <detlev@die-offenbachs.de> |
3565
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing mimetype dependent functions. |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | from __future__ import unicode_literals |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | import mimetypes |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
4097
ad2a6bd965d9
Added a configuration page to edit the list of mime types to be opened in an eric editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4090
diff
changeset
|
14 | import Preferences |
3565
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | def isTextFile(filename): |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | """ |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | Function to test, if the given file is a text (i.e. editable) file. |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | @param filename name of the file to be checked (string) |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | @return flag indicating an editable file (boolean) |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | """ |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | type_ = mimetypes.guess_type(filename)[0] |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | if (type_ is None or |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | type_.split("/")[0] == "text" or |
4097
ad2a6bd965d9
Added a configuration page to edit the list of mime types to be opened in an eric editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4090
diff
changeset
|
27 | type_ in Preferences.getUI("TextMimeTypes")): |
3565
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | return True |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | else: |
8e1cd7721515
Added a utility function to handle mime types other than 'text' that are editable text files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | return False |
4101
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
31 | |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
32 | |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
33 | def mimeType(filename): |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
34 | """ |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
35 | Function to get the mime type of a file. |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
36 | |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
37 | @param filename name of the file to be checked (string) |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
38 | @return mime type of the file (string) |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
39 | """ |
68c26f72c0d1
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.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4097
diff
changeset
|
40 | return mimetypes.guess_type(filename)[0] |