From 080770f6bf5d9038c2b358e392634388d6eee7b1 Mon Sep 17 00:00:00 2001 From: Robert McNamara Date: Mon, 12 Oct 2009 17:07:26 +0000 Subject: [PATCH] Closes #7308. Adds timezone check functionality to the Python Bindings (matches Perl bindings). Useful for Live CD purposes to query the MBE for Timezone/Time. git-svn-id: http://svn.mythtv.org/svn/trunk@22395 7dbf422c-18fa-0310-86e9-fd20926502f2 --- mythtv/bindings/python/MythTV/MythTV.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mythtv/bindings/python/MythTV/MythTV.py b/mythtv/bindings/python/MythTV/MythTV.py index 2dae6b048cb..e2b671cc39f 100755 --- a/mythtv/bindings/python/MythTV/MythTV.py +++ b/mythtv/bindings/python/MythTV/MythTV.py @@ -14,7 +14,7 @@ import socket import code import re -from datetime import datetime +from datetime import datetime, tzinfo, timedelta from time import mktime from MythDB import * @@ -483,6 +483,24 @@ def getLastGuideData(self): """ return self.backendCommand('QUERY_GUIDEDATATHROUGH') + def getTimeZone(self): + """ + Returns a tuple containing Zone ID, UTC offset, and ISO format date + """ + return tuple(self.backendCommand('QUERY_TIME_ZONE').split(BACKEND_SEP)) + + def getTime(self): + """ + Returns an "aware" datetime object of the backend's current time + """ + class tz(tzinfo): + def __init__(self,offs): self.offset = int(offs) + def tzname(self): return "GMT%d" % (self.offset/3600) + def dst(self,dt): return timedelta(0) + def utcoffset(self,dt): return timedelta(seconds=self.offset) + tup = self.getTimeZone() + return datetime.strptime(tup[2],"%Y-%m-%dT%H:%M:%S").replace(tzinfo=tz(tup[1])) + def joinInt(self,high,low): """ Returns a single long from a pair of signed integers