couple more vInfo corrections
[pyTivo/krkeegan.git] / debug.py
blob02c1610ce103c0853e147f5301ad1f059f985c59
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(0).lower() == 'true':
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 fpath = p
15 fname = []
16 fname.append('debug')
17 if not config.getDebug(1) == '' or not config.getDebug(2) == '':
18 if os.path.isdir(config.getDebug(1)):
19 fpath = config.getDebug(1)
20 fname.append(os.path.split(os.path.dirname(__file__))[-1])
21 if config.getDebug(2).lower() == 'split':
22 fname.append(modname)
23 fname.append('txt')
24 fdebug = open(os.path.join(fpath, '.'.join(fname)), 'a')
25 fdebug.write(' '.join(debug_out)+'\n')
26 print 'DEBUG:'+' '.join(debug_out)
27 fdebug.close()
29 def fn_attr():
30 "returns name of calling function and line number"
31 return sys._getframe(1).f_code.co_name, str(sys._getframe(1).f_lineno)
33 def print_conf(srcMod, fnAttr):
34 if config.getDebug(0).lower() == 'true':
35 debug_write(srcMod, fnAttr, ['********************************************************'])
36 debug_write(srcMod, fnAttr, ['** Begin pyTivo Session:', datetime.datetime.today(), ' **'])
37 debug_write(srcMod, fnAttr, ['********************************************************'])
38 debug_write(srcMod, fnAttr, ['----- begin pyTivo.conf -----'])
39 conf = open(os.path.join(p, 'pyTivo.conf'))
40 for line in conf.readlines():
41 if line.strip().startswith('#'):
42 continue
43 if len(line.strip()) != 0:
44 debug_write(srcMod, fnAttr, [line.strip()])
45 conf.close()
46 debug_write(srcMod, fnAttr, ['------- end pyTivo.conf -----'])
48 print_conf(__name__, fn_attr())