Fix transfers for linux
[pyTivo.git] / debug.py
blob4aef6f86b078bbd5bf65565b9e884889fef9d38d
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)+'\n')
14 print '___'+' '.join(debug_out)
15 fdebug.close()
17 def fn_attr():
18 "returns name of calling function and line number"
19 return sys._getframe(1).f_code.co_name, str(sys._getframe(1).f_lineno)
21 def print_conf(srcMod, fnAttr):
22 if config.getDebug():
23 debug_write(srcMod, fnAttr, ['----- begin pyTivo.conf -----'])
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 debug_write(srcMod, fnAttr, [line.strip()])
30 conf.close()
31 debug_write(srcMod, fnAttr, ['------- end pyTivo.conf -----'])
33 print_conf(__name__, fn_attr())