diff --git a/default.py b/default.py index 89e4bd2..c6e58c2 100644 --- a/default.py +++ b/default.py @@ -56,6 +56,13 @@ BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'li sys.path.append(BASE_RESOURCE_PATH) PLUGINPATH = xbmc.translatePath( os.path.join( __cwd__) ) +ProfileCode = __settings__.getSetting('profile') == "true" + +if(ProfileCode): + xbmcgui.Dialog().ok(__language__(30201), __language__(30202), __language__(30203)) + pr = cProfile.Profile() + pr.enable() + from DownloadUtils import DownloadUtils from ItemInfo import ItemInfo from Utils import PlayUtils @@ -102,7 +109,11 @@ downloadUtils = DownloadUtils() def printDebug( msg, level = 1): if(logLevel >= level): if(logLevel == 2): - xbmc.log("MBCon " + str(level) + " -> " + inspect.stack()[1][3] + " : " + str(msg)) + stackline = "" + stack = inspect.stack() + for frame in stack: + stackline = stackline + "." + frame[3] + xbmc.log("MBCon " + str(level) + " -> (" + stackline + ") : " + str(msg)) else: xbmc.log("MBCon " + str(level) + " -> " + str(msg)) @@ -1841,42 +1852,10 @@ else: displaySections() elif mode == _MODE_GETCONTENT: - if __settings__.getSetting('profile') == "true": - - xbmcgui.Dialog().ok(__language__(30201), __language__(30202), __language__(30203)) - - pr = cProfile.Profile() - pr.enable() - getContent(param_url) - pr.disable() - ps = pstats.Stats(pr) - - fileTimeStamp = time.strftime("%Y-%m-%d %H-%M-%S") - tabFileName = __addondir__ + "profile_(" + fileTimeStamp + ").tab" - f = open(tabFileName, 'wb') - f.write("NumbCalls\tTotalTime\tCumulativeTime\tFunctionName\tFileName\r\n") - for (key, value) in ps.stats.items(): - (filename, count, func_name) = key - (ccalls, ncalls, total_time, cumulative_time, callers) = value - try: - f.write(str(ncalls) + "\t" + "{:10.4f}".format(total_time) + "\t" + "{:10.4f}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n") - except ValueError: - f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n") - f.close() - - else: - getContent(param_url) + getContent(param_url) elif mode == _MODE_BASICPLAY: PLAY(param_url, pluginhandle) - elif mode == _MODE_SEARCH: - searchString=urllib.quote(xbmcgui.Dialog().input(__language__(30138))) - printDebug("Search String : " + searchString) - if searchString == "": - sys.exit() - param_url=param_url.replace("Search/Hints?","Search/Hints?SearchTerm="+searchString + "&UserId=") - param_url=param_url + "&Fields=" + getDetailsString() + "&format=json" - getContent(param_url) elif mode == _MODE_SETVIEWS: showViewList(param_url, pluginhandle) @@ -1884,5 +1863,24 @@ WINDOW = xbmcgui.Window( 10000 ) WINDOW.clearProperty("MB3.Background.Item.FanArt") xbmc.log ("===== MBCon STOP =====") +if(ProfileCode): + pr.disable() + ps = pstats.Stats(pr) + + fileTimeStamp = time.strftime("%Y-%m-%d %H-%M-%S") + tabFileName = __addondir__ + "profile_(" + fileTimeStamp + ").tab" + f = open(tabFileName, 'wb') + f.write("NumbCalls\tTotalTime\tCumulativeTime\tFunctionName\tFileName\r\n") + for (key, value) in ps.stats.items(): + (filename, count, func_name) = key + (ccalls, ncalls, total_time, cumulative_time, callers) = value + try: + f.write(str(ncalls) + "\t" + "{:10.4f}".format(total_time) + "\t" + "{:10.4f}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n") + except ValueError: + f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n") + f.close() + #clear done and exit. -sys.modules.clear() +sys.modules.clear() + + diff --git a/resources/lib/DownloadUtils.py b/resources/lib/DownloadUtils.py index f976480..3a1e619 100644 --- a/resources/lib/DownloadUtils.py +++ b/resources/lib/DownloadUtils.py @@ -9,6 +9,7 @@ import hashlib import StringIO import gzip import sys +import inspect import json as json from random import randrange from uuid import getnode as get_mac @@ -48,7 +49,6 @@ class DownloadUtils(): xbmc.log (error) return "" - self.logMsg("GETUSER_JSONDATA_01:" + str(jsonData)) result = [] @@ -199,7 +199,7 @@ class DownloadUtils(): server=url.split('/')[serversplit] urlPath="/"+"/".join(url.split('/')[urlsplit:]) - self.logMsg("url = " + url) + self.logMsg("DOWNLOAD_URL = " + url) self.logMsg("server = "+str(server), level=2) self.logMsg("urlPath = "+str(urlPath), level=2) conn = httplib.HTTPConnection(server, timeout=20) @@ -217,19 +217,18 @@ class DownloadUtils(): if int(data.status) == 200: retData = data.read() contentType = data.getheader('content-encoding') - self.logMsg("Data Len Before : " + str(len(retData))) + self.logMsg("Data Len Before : " + str(len(retData)), level=2) if(contentType == "gzip"): retData = StringIO.StringIO(retData) gzipper = gzip.GzipFile(fileobj=retData) link = gzipper.read() else: link = retData - - self.logMsg("Data Len After : " + str(len(link))) - self.logMsg("====== 200 returned =======") - self.logMsg("Content-Type : " + str(contentType)) - self.logMsg(link) - self.logMsg("====== 200 finished ======") + self.logMsg("Data Len After : " + str(len(link)), level=2) + self.logMsg("====== 200 returned =======", level=2) + self.logMsg("Content-Type : " + str(contentType), level=2) + self.logMsg(link, level=2) + self.logMsg("====== 200 finished ======", level=2) elif ( int(data.status) == 301 ) or ( int(data.status) == 302 ): try: conn.close() @@ -238,7 +237,7 @@ class DownloadUtils(): elif int(data.status) >= 400: error = "HTTP response error: " + str(data.status) + " " + str(data.reason) - xbmc.log (error) + xbmc.log(error) if suppress is False: if popup == 0: xbmc.executebuiltin("XBMC.Notification(URL error: "+ str(data.reason) +",)") @@ -252,7 +251,7 @@ class DownloadUtils(): link = "" except Exception, msg: error = "Unable to connect to " + str(server) + " : " + str(msg) - xbmc.log (error) + xbmc.log(error) xbmc.executebuiltin("XBMC.Notification(\"MBCon\": URL error: Unable to connect to server,)") xbmcgui.Dialog().ok("",self.getString(30204)) raise