From 4f2e92c6e0dbb249b0a517a17dc9b79dfcdb002d Mon Sep 17 00:00:00 2001 From: Philipp Weissmann Date: Thu, 2 Oct 2014 09:52:26 +0200 Subject: [PATCH 1/3] Python2 to Python3 conversion using 2to3 --- pyicloud/cmdline.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index 940fc97..b4c17d7 100755 --- a/pyicloud/cmdline.py +++ b/pyicloud/cmdline.py @@ -181,20 +181,20 @@ def main(): contents = dev.content if command_line.longlist: - print "-"*30 - print contents["name"] + print("-"*30) + print(contents["name"]) for x in contents: - print "%20s - %s" % (x, contents[x]) + print("%20s - %s" % (x, contents[x])) elif command_line.list: # print "\n" - print "-"*30 - print "Name - %s" % contents["name"] - print "Display Name - %s" % contents["deviceDisplayName"] - print "Location - %s" % contents["location"] - print "Battery Level - %s" % contents["batteryLevel"] - print "Battery Status- %s" % contents["batteryStatus"] - print "Device Class - %s" % contents["deviceClass"] - print "Device Model - %s" % contents["deviceModel"] + print("-"*30) + print("Name - %s" % contents["name"]) + print("Display Name - %s" % contents["deviceDisplayName"]) + print("Location - %s" % contents["location"]) + print("Battery Level - %s" % contents["batteryLevel"]) + print("Battery Status- %s" % contents["batteryStatus"]) + print("Device Class - %s" % contents["deviceClass"]) + print("Device Model - %s" % contents["deviceModel"]) # Play a Sound on a device if command_line.sound: From cb5872c1a05b05ab4d780e2210827194ef687c6d Mon Sep 17 00:00:00 2001 From: Philipp Weissmann Date: Thu, 2 Oct 2014 10:55:33 +0200 Subject: [PATCH 2/3] Use pytz instead of /etc/timezone; Python3 compatible --- pyicloud/services/calendar.py | 36 ++++++++++++++++++++++++++++++----- requirements.txt | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/pyicloud/services/calendar.py b/pyicloud/services/calendar.py index 4f9ae07..47d3403 100644 --- a/pyicloud/services/calendar.py +++ b/pyicloud/services/calendar.py @@ -1,7 +1,8 @@ from __future__ import absolute_import -import os -from datetime import datetime +from datetime import datetime, timedelta from calendar import monthrange +import time +import pytz class CalendarService(object): @@ -16,12 +17,37 @@ class CalendarService(object): self._calendar_refresh_url = '%s/events' % self._calendar_endpoint self._calendar_event_detail_url = '%s/eventdetail' % self._calendar_endpoint + def get_possible_timezones(self): + """ + Return all possible timezones in Olzon TZ notation + This has been taken from + http://stackoverflow.com/questions/7669938 + """ + local_names = [] + if time.daylight: + local_offset = time.altzone + localtz = time.tzname[1] + else: + local_offset = time.timezone + localtz = time.tzname[0] + + local_offset = timedelta(seconds=-local_offset) + + for name in pytz.all_timezones: + timezone = pytz.timezone(name) + if not hasattr(timezone, '_tzinfos'): + continue + for (utcoffset, daylight, tzname), _ in timezone._tzinfos.items(): + if utcoffset == local_offset and tzname == localtz: + local_names.append(name) + return local_names + def get_system_tz(self): """ - Retrieves the system's timezone. - From: http://stackoverflow.com/a/7841417 + Retrieves the system's timezone from a list of possible options. + Just take the first one """ - return '/'.join(os.readlink('/etc/localtime').split('/')[-2:]) + return self.get_possible_timezones()[0] def get_event_detail(self, pguid, guid): """ diff --git a/requirements.txt b/requirements.txt index ed7dc8f..6b77c7d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests>=1.2 six +pytz From c18fcf72214ab0c06ae7626b296b54db3229ad41 Mon Sep 17 00:00:00 2001 From: Philipp Weissmann Date: Fri, 3 Oct 2014 08:31:05 +0200 Subject: [PATCH 3/3] Fixed python2.6 compatiblity, formating and spelling --- pyicloud/cmdline.py | 1 + pyicloud/services/calendar.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index b4c17d7..5968dd8 100755 --- a/pyicloud/cmdline.py +++ b/pyicloud/cmdline.py @@ -4,6 +4,7 @@ A Command Line Wrapper to allow easy use of pyicloud for command line scripts, and related. """ +from __future__ import print_function import argparse import pickle diff --git a/pyicloud/services/calendar.py b/pyicloud/services/calendar.py index 47d3403..861a9bf 100644 --- a/pyicloud/services/calendar.py +++ b/pyicloud/services/calendar.py @@ -2,6 +2,7 @@ from __future__ import absolute_import from datetime import datetime, timedelta from calendar import monthrange import time + import pytz @@ -17,9 +18,9 @@ class CalendarService(object): self._calendar_refresh_url = '%s/events' % self._calendar_endpoint self._calendar_event_detail_url = '%s/eventdetail' % self._calendar_endpoint - def get_possible_timezones(self): + def get_all_possible_timezones_of_local_machine(self): """ - Return all possible timezones in Olzon TZ notation + Return all possible timezones in Olson TZ notation This has been taken from http://stackoverflow.com/questions/7669938 """