patch by rjmitche, add to debug session start date/time
[pyTivo.git] / debug.py
blob0f523a53f5de03cce8d7366d925d1df4ecc1d479
1 import ConfigParser, os, re, sys
2 import config
3 import datetime
5 p = os.path.dirname(__file__)
7 def debug_write(srcMod, fnAttr, data):
8 if config.getDebug():
9 debug_out = []
10 modname=srcMod.split('.')[-1]
11 debug_out.append(modname+'.'+fnAttr[1]+' ['+fnAttr[0]+'] ')
12 for x in data:
13 debug_out.append(str(x))
14 fdebug = open(os.path.join(p, 'debug.txt'), 'a')
15 fdebug.write(' '.join(debug_out)+'\n')
16 print '___'+' '.join(debug_out)
17 fdebug.close()
19 def fn_attr():
20 "returns name of calling function and line number"
21 return sys._getframe(1).f_code.co_name, str(sys._getframe(1).f_lineno)
23 def print_conf(srcMod, fnAttr):
24 if config.getDebug():
25 debug_write(srcMod, fnAttr, ['********************************************************'])
26 debug_write(srcMod, fnAttr, ['** Begin pyTivo Session:', datetime.datetime.today(), ' **'])
27 debug_write(srcMod, fnAttr, ['********************************************************'])
28 debug_write(srcMod, fnAttr, ['----- begin pyTivo.conf -----'])
29 conf = open(os.path.join(p, 'pyTivo.conf'))
30 for line in conf.readlines():
31 if line.strip().startswith('#'):
32 continue
33 if len(line.strip()) != 0:
34 debug_write(srcMod, fnAttr, [line.strip()])
35 conf.close()
36 debug_write(srcMod, fnAttr, ['------- end pyTivo.conf -----'])
38 print_conf(__name__, fn_attr())