[gnome-music] __init__: Cleanup following PEP-8 & PEP-257
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] __init__: Cleanup following PEP-8 & PEP-257
- Date: Mon, 16 Jan 2017 09:58:46 +0000 (UTC)
commit d6bea7c2f7eaa00c1f4fb01bd2715fbef454089c
Author: theawless <thawless gmail com>
Date: Sat Jan 14 01:50:00 2017 +0530
__init__: Cleanup following PEP-8 & PEP-257
Followed PEP guidelines and added docstrings.
https://bugzilla.gnome.org/show_bug.cgi?id=777216
gnomemusic/__init__.py | 43 ++++++++++++++++++++++++++++---------------
1 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/gnomemusic/__init__.py b/gnomemusic/__init__.py
index 883f76b..5d9cb26 100644
--- a/gnomemusic/__init__.py
+++ b/gnomemusic/__init__.py
@@ -25,17 +25,26 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
+from itertools import chain
+from time import time
+import logging
+
import gi
gi.require_version('Tracker', '1.0')
from gi.repository import Tracker
-from itertools import chain
-import logging
-import time
+
logger = logging.getLogger(__name__)
tabbing = 0
def log(fn):
+ """Decorator to log function details.
+
+ Shows function signature, return value, time elapsed, etc.
+ Logging will be done if the debug flag is set.
+ :param fn: the function to be decorated
+ :return: function wrapped for logging
+ """
if logger.getEffectiveLevel() > logging.DEBUG:
return fn
@@ -48,21 +57,23 @@ def log(fn):
params = ", ".join(map(repr, chain(v, k.values())))
if 'rateLimitedFunction' not in name:
- logger.debug("%s%s(%s)[%s:%s]",
- '|' * tabbing, name, params, filename, lineno,)
+ logger.debug("%s%s(%s)[%s:%s]", '|' * tabbing, name, params,
+ filename, lineno)
tabbing += 1
- start = time.time()
+ start = time()
retval = fn(*v, **k)
- elapsed = time.time() - start
+ elapsed = time() - start
tabbing -= 1
elapsed_time = ''
if elapsed > 0.1:
elapsed_time = ', took %02f' % elapsed
- if elapsed_time or retval is not None:
+ if (elapsed_time
+ or retval is not None):
if 'rateLimitedFunction' not in name:
- logger.debug("%s returned %s%s", '|' * tabbing, repr(retval), elapsed_time)
-
+ logger.debug("%s returned %s%s", '|' * tabbing, repr(retval),
+ elapsed_time)
return retval
+
return wrapped
@@ -73,16 +84,18 @@ class TrackerWrapper:
self.tracker = Tracker.SparqlConnection.get(None)
except Exception as e:
from sys import exit
- logger.error("Cannot connect to tracker, error '%s'\Exiting", str(e))
+ logger.error("Cannot connect to tracker, error '%s'\Exiting",
+ str(e))
exit(1)
def __str__(self):
return repr(self)
- instance = None
+
+ _instance = None
def __init__(self):
- if not TrackerWrapper.instance:
- TrackerWrapper.instance = TrackerWrapper.__TrackerWrapper()
+ if not TrackerWrapper._instance:
+ TrackerWrapper._instance = TrackerWrapper.__TrackerWrapper()
def __getattr__(self, name):
- return getattr(self.instance, name)
+ return getattr(self._instance, name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]