From dce0bc04d3ae152aca535f477ca4e004a92f6686 Mon Sep 17 00:00:00 2001 From: Juho Kolehmainen Date: Fri, 15 Sep 2017 22:51:02 +0300 Subject: [PATCH] Fix support for Python 3.6. --- download_photos.py | 12 ++++++++---- filesystem.py | 10 +++++++--- requirements.txt | 2 +- spk/INFO | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/download_photos.py b/download_photos.py index 2f605298d..9ecfeac4a 100755 --- a/download_photos.py +++ b/download_photos.py @@ -183,11 +183,15 @@ def truncate_middle(s, n): return '{0}...{1}'.format(s[:n_1], s[-n_2:]) def filename_with_size(photo, size): + if sys.version_info[0] >= 3: + filename = photo.filename + else: + filename = photo.filename.encode('utf-8') + if size == 'original': - return photo.filename.encode('utf-8') + return filename else: - return photo.filename.encode('utf-8') \ - .decode('ascii', 'ignore').replace('.', '-%s.' % size) + return filename.decode('ascii', 'ignore').replace('.', '-%s.' % size) def download_photo(photo, size, force_size, album, progress_bar): # Strip any non-ascii characters. @@ -241,7 +245,7 @@ def download_photo(photo, size, force_size, album, progress_bar): if size not in photo.versions and not force_size and size != 'original': return download_photo(photo, 'original', True, album, progress_bar) - progress_bar.set_description("Downloading %s to %s" % (truncated_filename.decode('ascii', 'ignore'), truncated_path.decode('ascii', 'ignore'))) + progress_bar.set_description("Downloading %s to %s" % (truncated_filename.encode().decode('ascii', 'ignore'), truncated_path.encode().decode('ascii', 'ignore'))) for _ in range(MAX_RETRIES): try: diff --git a/filesystem.py b/filesystem.py index 828c09554..f7f9fa688 100644 --- a/filesystem.py +++ b/filesystem.py @@ -27,6 +27,11 @@ def __init__(self, path): def __str__(self): return self.path + def item(self, filename): + filepath = '/'.join((self.path, filename)) + if os.path.isfile(filepath): + return FileSystemPhoto(filepath, os.path.getmtime(filepath)) + def create_item(self, filename, filetype, created, modified = None, filesize = None, title = None, description = None, rating = None, latitude = None, longitude = None): filepath = '/'.join((self.path, filename)) return FileSystemPhoto(filepath, created) @@ -51,6 +56,5 @@ def save_content(self, url): os.utime(self.path, (self.created / 1000,self.created / 1000)) def delete(self): - if exists(): - print "Deleting %s!" % self.path - os.remove(self.path) + print ("Deleting %s!" % self.path) + os.remove(self.path) diff --git a/requirements.txt b/requirements.txt index 60a853f50..e9ba161dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,6 @@ python-dateutil requests tqdm>=4.5.0 git+https://github.com/chadj/pyicloud.git@ckdatabasews#egg=pyicloud -photostation>=0.1.4 +photostation>=0.1.5 biplist requests_toolbelt \ No newline at end of file diff --git a/spk/INFO b/spk/INFO index 317a132db..4cec603f9 100644 --- a/spk/INFO +++ b/spk/INFO @@ -1,5 +1,5 @@ package="icloud_photo_station" -version="0.1.4" +version="0.1.5" description="Synchronize iCloud Photos to Photo Station" maintainer="Juho Kolehmainen"