Merge branch 'master' of git+ssh://scm.schwerkraft.elitedvb.net/scmrepos/git/enigma2...
[enigma2-plugins.git] / fritzcall / src / __init__.py
1 # -*- coding: utf-8 -*-
2 '''
3 general functions for FritzCall plugin
4 '''
5 from Components.config import config #@UnresolvedImport
6 from Components.Language import language
7 from Tools.Directories import resolveFilename, SCOPE_LANGUAGE, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE #@UnresolvedImport
8 import gettext, os
9 from enigma import eBackgroundFileEraser
10
11 lang = language.getLanguage()
12 os.environ["LANGUAGE"] = lang[:2]
13 gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
14 gettext.textdomain("enigma2")
15 gettext.bindtextdomain("FritzCall", "%s%s" % (resolveFilename(SCOPE_PLUGINS), "Extensions/FritzCall/locale/"))
16
17 def _(txt): # pylint: disable-msg=C0103
18         td = gettext.dgettext("FritzCall", txt)
19         if td == txt:
20                 td = gettext.gettext(txt)
21         return td
22
23 # scramble text
24 def __(text, front=True):
25         #===========================================================================
26         # if len(text) > 5:
27         #       if front:
28         #               return '.....' + text[5:]
29         #       else:
30         #               return text[:-5] + '.....'
31         # else:
32         #       return '.....' 
33         #===========================================================================
34         out =""
35         for i in range(len(text)/2):
36                 out = out + text[i*2] + '.'
37         return out
38
39 def initDebug():
40         try:
41                 # os.remove("/tmp/FritzDebug.log")
42                 eBackgroundFileEraser.getInstance().erase("/tmp/FritzDebug.log")
43         except OSError:
44                 pass
45
46 from time import localtime
47 def debug(message):
48         if config.plugins.FritzCall.debug.value:
49                 try:
50                         # ltim = localtime()
51                         # headerstr = u"%04d%02d%02d %02d:%02d " %(ltim[0],ltim[1],ltim[2],ltim[3],ltim[4])
52                         deb = open("/tmp/FritzDebug.log", "aw")
53                         # deb.write(headerstr + message.decode('utf-8') + u"\n")
54                         deb.write(message + "\n")
55                         deb.close()
56                 except Exception, e:
57                         debug("%s (retried debug: %s)" % (repr(message), str(e)))
58                 
59
60 import re
61 def normalizePhoneNumber(intNo):
62         
63         found = re.match('^\+' + config.plugins.FritzCall.country.value.replace('00','') + '(.*)', intNo)
64         if found:
65                 intNo = '0' + found.group(1)
66         found = re.match('^\+(.*)', intNo)
67         if found:
68                 intNo = '00' + found.group(1)
69         intNo = intNo.replace('(', '').replace(')', '').replace(' ', '').replace('/', '').replace('-', '')
70         found = re.match('^49(.*)', intNo) # this is most probably an error
71         if found:
72                 intNo = '0' + found.group(1)
73         found = re.match('.*?([0-9]+)', intNo)
74         if found:
75                 return found.group(1)
76         else:
77                 return '0'