shortened module name written to debug.txt
[pyTivo.git] / debug.py
blob0194d1bae79f96b9be6050ce58498e99091cb7a4
1 import ConfigParser, os, re, sys
2 import config
3 p = os.path.dirname(__file__)
5 def debug_write(srcMod, fnAttr, data):
6 if config.getDebug():
7 debug_out = []
8 modname=srcMod.split('.')[-1]
9 debug_out.append(modname+'.'+fnAttr[1]+' ['+fnAttr[0]+'] ')
10 for x in data:
11 debug_out.append(str(x))
12 fdebug = open('debug.txt', 'a')
13 fdebug.write(' '.join(debug_out))
14 fdebug.close()
16 def fn_attr():
17 "returns name of calling function and line number"
18 return sys._getframe(1).f_code.co_name, str(sys._getframe(1).f_lineno)
20 def print_conf(srcMod, fnAttr):
21 if config.getDebug():
22 print '----- begin pyTivo.conf -----:'
23 debug_write(srcMod, fnAttr, ['----- begin pyTivo.conf -----\n'])
24 conf = open(os.path.join(p, 'pyTivo.conf'))
25 for line in conf.readlines():
26 if line.strip().startswith('#'):
27 continue
28 if len(line.strip()) != 0:
29 print line.strip()
30 debug_write(srcMod, fnAttr, [line.strip(), '\n'])
31 print '------- end pyTivo.conf -----:'
32 conf.close()
33 debug_write(srcMod, fnAttr, ['------- end pyTivo.conf -----\n'])