MCPcopy
hub / github.com/iBaa/PlexConnect / dprint

Function dprint

Debug.py:55–91  ·  view source on GitHub ↗
(src, dlevel, *args)

Source from the content-addressed store, hash-verified

53
54
55def dprint(src, dlevel, *args):
56 logToTerminal = not (src in dlevels) or dlevel <= dlevels[src]
57 logToFile = not g_loglevel==-1 and not g_logfile=='' and dlevel <= g_loglevel
58
59 if logToTerminal or logToFile:
60 asc_args = list(args)
61
62 for i,arg in enumerate(asc_args):
63 if etree.iselement(asc_args[i]):
64 asc_args[i] = prettyXML(asc_args[i])
65
66 if isinstance(asc_args[i], str):
67 asc_args[i] = asc_args[i].decode('utf-8', 'replace') # convert as utf-8 just in case
68 if isinstance(asc_args[i], unicode):
69 asc_args[i] = asc_args[i].encode('ascii', 'replace') # back to ascii
70
71 # print to file (if filename defined)
72 if logToFile:
73 f = open(g_logfile, 'a')
74 f.write(time.strftime("%b %d,%Y %H:%M:%S "))
75 if len(asc_args)==0:
76 f.write(src+":\n")
77 elif len(asc_args)==1:
78 f.write(src+": "+asc_args[0]+"\n")
79 else:
80 f.write(src+": "+asc_args[0].format(*asc_args[1:])+"\n")
81 f.close()
82
83 # print to terminal window
84 if logToTerminal:
85 print(time.strftime("%b %d,%Y %H:%M:%S")),
86 if len(asc_args)==0:
87 print src+":"
88 elif len(asc_args)==1:
89 print src+": "+str(asc_args[0])
90 else:
91 print src+": "+asc_args[0].format(*asc_args[1:])
92
93
94

Callers 15

__init__Method · 0.85
loadSettingsMethod · 0.85
saveSettingsMethod · 0.85
checkSectionMethod · 0.85
getSettingMethod · 0.85
checkSettingMethod · 0.85
setOptionsMethod · 0.85
PlexGDMFunction · 0.85
discoverPMSFunction · 0.85
getPMSListFromMyPlexFunction · 0.85
getXMLFromPMSFunction · 0.85
getXMLFromMultiplePMSFunction · 0.85

Calls 1

prettyXMLFunction · 0.85

Tested by

no test coverage detected