UPD: plugin: better size calculation for action screen after reverse lookup
[enigma2-plugins.git] / fritzcall / src / __init__.py
1 # -*- coding: utf-8 -*-
2 from Components.config import config #@UnresolvedImport
3 from Components.Language import language
4 from Tools.Directories import resolveFilename, SCOPE_LANGUAGE, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE #@UnresolvedImport
5 import gettext, os
6
7 lang = language.getLanguage()
8 os.environ["LANGUAGE"] = lang[:2]
9 gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
10 gettext.textdomain("enigma2")
11 gettext.bindtextdomain("FritzCall", "%s%s" % (resolveFilename(SCOPE_PLUGINS), "Extensions/FritzCall/locale/"))
12
13 def _(txt):
14         t = gettext.dgettext("FritzCall", txt)
15         if t == txt:
16                 t = gettext.gettext(txt)
17         return t
18
19 from time import localtime
20 def debug(message):
21         if config.plugins.FritzCall.debug.value:
22                 try:
23                         # ltim = localtime()
24                         # headerstr = u"%04d%02d%02d %02d:%02d " %(ltim[0],ltim[1],ltim[2],ltim[3],ltim[4])
25                         deb = open("/tmp/FritzDebug.log", "aw")
26                         # deb.write(headerstr + message.decode('utf-8') + u"\n")
27                         deb.write(message + "\n")
28                         deb.close()
29                 except:
30                         debug(repr(message) + " (retried debug)")
31                 
32
33 import re
34 def normalizePhoneNumber(intNo):
35         
36         found = re.match('^\+' + config.plugins.FritzCall.country.value.replace('00','') + '(.*)', intNo)
37         if found:
38                 intNo = '0' + found.group(1)
39         found = re.match('^\+(.*)', intNo)
40         if found:
41                 intNo = '00' + found.group(1)
42         intNo = intNo.replace('(', '').replace(')', '').replace(' ', '').replace('/', '').replace('-', '')
43         found = re.match('^49(.*)', intNo) # this is most probably an error
44         if found:
45                 intNo = '0' + found.group(1)
46         found = re.match('.*?([0-9]+)', intNo)
47         if found:
48                 return found.group(1)
49         else:
50                 return '0'