better error handling, does not crash any more on loss of connection to mail server
[enigma2-plugins.git] / emailclient / src / __init__.py
1 from Tools.Directories import resolveFilename, SCOPE_LANGUAGE, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
2 from Components.Language import language
3 from Components.config import config
4 import os, gettext
5
6 lang = language.getLanguage()
7 os.environ["LANGUAGE"] = lang[:2]
8 gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
9 gettext.textdomain("enigma2")
10 gettext.bindtextdomain("EmailClient", "%s%s" % (resolveFilename(SCOPE_PLUGINS), "Extensions/EmailClient/locale/"))
11
12 def _(txt):
13         t = gettext.dgettext("EmailClient", txt)
14         if t == txt:
15                 t = gettext.gettext(txt)
16         return t
17
18 def initLog():
19         try:
20                 os.remove("/tmp/EmailClient.log")
21         except:
22                 pass
23
24 def debug(message):
25         if config.plugins.emailimap.debug.value:
26                 try:
27                         deb = open("/tmp/EmailClient.log", "aw")
28                         deb.write(message + "\n")
29                         deb.close()
30                 except:
31                         debug(repr(message) + " (retried debug)")