Skip to content

Commit

Permalink
PEP8 cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
cluther committed May 21, 2012
1 parent 475a8c5 commit 97b0691
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ZenPacks/zenoss/PostgreSQL/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import time


def addLocalLibPath():
"""
Helper to add the ZenPack's lib directory to PYTHONPATH.
Expand All @@ -24,17 +25,20 @@ def addLocalLibPath():

site.addsitedir(os.path.join(os.path.dirname(__file__), 'lib'))


def datetimeToEpoch(datetime):
return time.mktime(datetime.timetuple())


def datetimeDurationInSeconds(begin, end):
d = end - begin

# Taken from the implementation of timedelta.total_seconds in Python 2.7.
# Added microseconds resolution by introducing a float.
return (
d.microseconds + (d.seconds + d.days * 24 * 3600) * 10**6
) / float(10**6)
d.microseconds + (d.seconds + d.days * 24 * 3600) * (10 ** 6)
) / float(10 ** 6)


class CollectedOrModeledMixin:
def getFloatForValue(self, value):
Expand All @@ -50,14 +54,15 @@ def getFloatForValue(self, value):
def getIntForValue(self, value):
r = self.getFloatForValue(value)
return int(round(r)) if r is not None else None

def getStringForValue(self, value, format='{0}'):
r = self.getFloatForValue(value)
if r is None:
return ''

return format.format(r)


def CollectedOrModeledProperty(propertyName):
"""
This uses a closure to make using CollectedOrModeledMixin easier to use in
Expand All @@ -71,6 +76,7 @@ def getter(self):
addLocalLibPath()
from pg8000 import DBAPI


class PgHelper(object):
_host = None
_port = None
Expand Down Expand Up @@ -508,4 +514,3 @@ def getTableStatsForDatabase(self, db):
cursor.close()

return tableStats

0 comments on commit 97b0691

Please sign in to comment.