Fix style issues in reporting.py (#2355)

This commit is contained in:
Zach Welch 2015-03-02 14:12:15 -08:00
parent d4c02caa03
commit 366092075d
2 changed files with 17 additions and 6 deletions

View File

@ -34,7 +34,7 @@ from chirp import CHIRP_VERSION, platform
REPORT_URL = "http://chirp.danplanet.com/report/report.php?do_report"
ENABLED = True
THREAD_SEM = threading.Semaphore(10) # Maximum number of outstanding threads
THREAD_SEM = threading.Semaphore(10) # Maximum number of outstanding threads
LAST = 0
LAST_TYPE = None
@ -47,6 +47,7 @@ try:
except:
ENABLED = False
def should_report():
if not ENABLED:
LOG.debug("Not reporting due to recent failure")
@ -59,11 +60,13 @@ def should_report():
return True
def _report_model_usage(model, direction, success):
global ENABLED
if direction not in ["live", "download", "upload", "import", "export", "importsrc"]:
if direction not in ["live", "download", "upload",
"import", "export", "importsrc"]:
print "Invalid direction `%s'" % direction
return True # This is a bug, but not fatal
return True # This is a bug, but not fatal
model = "%s_%s" % (model.VENDOR, model.MODEL)
data = "%s,%s,%s" % (model, direction, success)
@ -79,6 +82,7 @@ def _report_model_usage(model, direction, success):
# If the server returns zero, it wants us to shut up
return id != 0
def _report_exception(stack):
global ENABLED
@ -93,6 +97,7 @@ def _report_exception(stack):
# If the server returns zero, it wants us to shut up
return id != 0
def _report_misc_error(module, data):
global ENABLED
@ -106,6 +111,7 @@ def _report_misc_error(module, data):
# If the server returns zero, it wants us to shut up
return id != 0
def _check_for_updates(callback):
LOG.debug("Checking for updates")
proxy = xmlrpclib.ServerProxy(REPORT_URL)
@ -116,6 +122,7 @@ def _check_for_updates(callback):
callback(ver)
return True
class ReportThread(threading.Thread):
def __init__(self, func, *args):
threading.Thread.__init__(self)
@ -128,7 +135,7 @@ class ReportThread(threading.Thread):
except Exception, e:
LOG.debug("Failed to report: %s" % e)
return False
def run(self):
start = time.time()
result = self._run()
@ -137,12 +144,13 @@ class ReportThread(threading.Thread):
ENABLED = False
elif (time.time() - start) > 15:
# Reporting took too long
LOG.debug("Time to report was %.2f sec -- Disabling" % \
LOG.debug("Time to report was %.2f sec -- Disabling" %
(time.time()-start))
ENABLED = False
THREAD_SEM.release()
def dispatch_thread(func, *args):
global LAST
global LAST_TYPE
@ -169,15 +177,19 @@ def dispatch_thread(func, *args):
t = ReportThread(func, *args)
t.start()
def report_model_usage(model, direction, success):
dispatch_thread(_report_model_usage, model, direction, success)
def report_exception(stack):
dispatch_thread(_report_exception, stack)
def report_misc_error(module, data):
dispatch_thread(_report_misc_error, module, data)
# Calls callback with the latest version
def check_for_updates(callback):
dispatch_thread(_check_for_updates, callback)

View File

@ -71,6 +71,5 @@
./chirp/wouxun_common.py
./chirp/yaesu_clone.py
./chirpui/fips.py
./chirpui/reporting.py
./tools/bitdiff.py
./tools/img2thd72.py