[rhythmbox/wip/python3: 16/16] Port Magnatune to python 3



commit cb07231438c9aac4f342e90573d6320a48e42cc2
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Apr 15 11:28:44 2013 +0200

    Port Magnatune to python 3

 plugins/magnatune/MagnatuneAccount.py |  4 +--
 plugins/magnatune/MagnatuneSource.py  | 53 +++++++++++++++++------------------
 plugins/magnatune/TrackListHandler.py |  4 +--
 plugins/magnatune/magnatune.py        |  6 ++--
 4 files changed, 33 insertions(+), 34 deletions(-)
---
diff --git a/plugins/magnatune/MagnatuneAccount.py b/plugins/magnatune/MagnatuneAccount.py
index 16b9f43..dea4743 100644
--- a/plugins/magnatune/MagnatuneAccount.py
+++ b/plugins/magnatune/MagnatuneAccount.py
@@ -64,8 +64,8 @@ class MagnatuneAccount(object):
                if Secret is None:
                        print ("Account details will not be saved because libsecret was not found")
                        return
-                # Haha.
-                self.secret_service = 
SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.OPEN_SESSION, None)
+               # Haha.
+               self.secret_service = 
SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.OPEN_SESSION, None)
                items = self.secret_service.search_sync(MAGNATUNE_SCHEMA,
                                                        self.keyring_attributes,
                                                        SecretUnstable.SearchFlags.LOAD_SECRETS,
diff --git a/plugins/magnatune/MagnatuneSource.py b/plugins/magnatune/MagnatuneSource.py
index 435264f..3e9bb9b 100644
--- a/plugins/magnatune/MagnatuneSource.py
+++ b/plugins/magnatune/MagnatuneSource.py
@@ -29,7 +29,6 @@ import os
 import sys
 import xml
 import urllib
-import urlparse
 import threading
 import zipfile
 
@@ -134,11 +133,11 @@ class MagnatuneSource(RB.BrowserSource):
 
                        if not magnatune_in_progress_dir.query_exists(None):
                                magnatune_in_progress_path = magnatune_in_progress_dir.get_path()
-                               os.mkdir(magnatune_in_progress_path, 0700)
+                               os.mkdir(magnatune_in_progress_path, 0o700)
 
                        if not magnatune_cache_dir.query_exists(None):
                                magnatune_cache_path = magnatune_cache_dir.get_path()
-                               os.mkdir(magnatune_cache_path, 0700)
+                               os.mkdir(magnatune_cache_path, 0o700)
 
                        self.__activated = True
                        self.__show_loading_screen(True)
@@ -213,7 +212,7 @@ class MagnatuneSource(RB.BrowserSource):
                        # Just use the first library location
                        library = Gio.Settings("org.gnome.rhythmbox.rhythmdb")
                        library_location = library['locations'][0]
-               except IndexError, e:
+               except IndexError as e:
                        RB.error_dialog(title = _("Couldn't download album"),
                                        message = _("You must have a library location set to download an 
album."))
                        return
@@ -242,14 +241,14 @@ class MagnatuneSource(RB.BrowserSource):
                                local_changes = ""
 
                        remote_changes = remote_changes.strip()
-                       print "local checksum %s, remote checksum %s" % (local_changes, remote_changes)
+                       print("local checksum %s, remote checksum %s" % (local_changes, remote_changes))
                        if local_changes != remote_changes:
                                try:
                                        f = open(magnatune_changes, 'w')
                                        f.write(remote_changes + "\n")
                                        f.close()
-                               except Exception, e:
-                                       print "unable to write local change id: %s" % str(e)
+                               except Exception as e:
+                                       print("unable to write local change id: %s" % str(e))
 
                                download_catalogue()
                        elif self.__has_loaded is False:
@@ -268,11 +267,11 @@ class MagnatuneSource(RB.BrowserSource):
 
                        def download_finished(copy, success, self):
                                if not success:
-                                       print "catalog download failed"
-                                       print copy.get_error()
+                                       print("catalog download failed")
+                                       print(copy.get_error())
                                        return
 
-                               print "catalog download successful"
+                               print("catalog download successful")
                                # done downloading, unzip to real location
                                catalog_zip = zipfile.ZipFile(magnatune_song_info_temp)
                                catalog = open(magnatune_song_info, 'w')
@@ -312,13 +311,13 @@ class MagnatuneSource(RB.BrowserSource):
                                        error = loader.get_error()
                                        if error:
                                                # report error somehow?
-                                               print "error loading catalogue: %s" % error
+                                               print("error loading catalogue: %s" % error)
 
                                        try:
                                                parser.close()
-                                       except xml.sax.SAXParseException, e:
+                                       except xml.sax.SAXParseException as e:
                                                # there isn't much we can do here
-                                               print "error parsing catalogue: %s" % e
+                                               print("error parsing catalogue: %s" % e)
 
                                        self.__show_loading_screen(False)
                                        self.__updating = False
@@ -331,7 +330,7 @@ class MagnatuneSource(RB.BrowserSource):
                                                if not name.startswith("in_progress_"):
                                                        continue
                                                (result, uri, etag) = 
magnatune_in_progress_dir.resolve_relative_path(name).load_contents(None)
-                                               print "restarting download from %s" % uri
+                                               print("restarting download from %s" % uri)
                                                self.__download_album(uri, name[12:])
                                else:
                                        # hack around some weird chars that show up in the catalogue for some 
reason
@@ -344,8 +343,8 @@ class MagnatuneSource(RB.BrowserSource):
 
                                        try:
                                                parser.feed(data)
-                                       except xml.sax.SAXParseException, e:
-                                               print "error parsing catalogue: %s" % e
+                                       except xml.sax.SAXParseException as e:
+                                               print("error parsing catalogue: %s" % e)
 
                                        load_size['size'] += len(data)
                                        self.__load_progress = (load_size['size'], total)
@@ -400,7 +399,7 @@ class MagnatuneSource(RB.BrowserSource):
 
        def __auth_download(self, sku): # http://magnatune.com/info/api
 
-               def auth_data_cb(data, (username, password)):
+               def auth_data_cb(data, username, password):
                        dl_album_handler = DownloadAlbumHandler(self.__settings['format'])
                        auth_parser = xml.sax.make_parser()
                        auth_parser.setContentHandler(dl_album_handler)
@@ -417,7 +416,7 @@ class MagnatuneSource(RB.BrowserSource):
                                auth_parser.close()
 
                                # process the URI: add authentication info, quote the filename component for 
some reason
-                               parsed = urlparse.urlparse(dl_album_handler.url)
+                               parsed = urllib.parse.urlparse(dl_album_handler.url)
                                netloc = "%s:%s %s" % (username, password, parsed.hostname)
 
                                spath = os.path.split(urllib.url2pathname(parsed.path))
@@ -427,18 +426,18 @@ class MagnatuneSource(RB.BrowserSource):
                                authed = (parsed[0], netloc, path) + parsed[3:]
                                audio_dl_uri = urlparse.urlunparse(authed)
 
-                               print "download uri for %s is %s" % (sku, audio_dl_uri)
+                               print("download uri for %s is %s" % (sku, audio_dl_uri))
                                self.__download_album(audio_dl_uri, sku)
 
-                       except MagnatuneDownloadError, e:
+                       except MagnatuneDownloadError as e:
                                RB.error_dialog(title = _("Download Error"),
                                                message = _("An error occurred while trying to authorize the 
download.\nThe Magnatune server returned:\n%s") % str(e))
-                       except Exception, e:
+                       except Exception as e:
                                sys.excepthook(*sys.exc_info())
                                RB.error_dialog(title = _("Error"),
                                                message = _("An error occurred while trying to download the 
album.\nThe error text is:\n%s") % str(e))
 
-               print "downloading album: " + sku
+               print("downloading album: " + sku)
                account = MagnatuneAccount.instance()
                (account_type, username, password) = account.get()
                url_dict = {
@@ -461,7 +460,7 @@ class MagnatuneSource(RB.BrowserSource):
                        del self.__downloads[audio_dl_uri]
                        del self.__copies[audio_dl_uri]
 
-                       print "download of %s finished: %s" % (audio_dl_uri, success)
+                       print("download of %s finished: %s" % (audio_dl_uri, success))
                        if success:
                                threading.Thread(target=unzip_album).start()
                        else:
@@ -481,11 +480,11 @@ class MagnatuneSource(RB.BrowserSource):
                        library = Gio.Settings("org.gnome.rhythmbox.rhythmdb")
                        library_location = Gio.file_new_for_uri(library['locations'][0])
 
-                       print "unzipping %s" % dest.get_path()
+                       print("unzipping %s" % dest.get_path())
                        album = zipfile.ZipFile(dest.get_path())
                        for track in album.namelist():
                                track_uri = library_location.resolve_relative_path(track).get_uri()
-                               print "zip file entry: %s => %s" % (track, track_uri)
+                               print("zip file entry: %s => %s" % (track, track_uri))
 
                                track_uri = RB.sanitize_uri_for_filesystem(track_uri)
                                RB.uri_create_parent_dirs(track_uri)
@@ -494,14 +493,14 @@ class MagnatuneSource(RB.BrowserSource):
                                if track_out is not None:
                                        track_out.write(album.read(track), None)
                                        track_out.close(None)
-                                       print "adding %s to library" % track_uri
+                                       print("adding %s to library" % track_uri)
                                        self.__db.add_uri(track_uri)
 
                        album.close()
                        remove_download_files()
 
                def remove_download_files():
-                       print "removing download files"
+                       print("removing download files")
                        in_progress.delete(None)
                        dest.delete(None)
 
diff --git a/plugins/magnatune/TrackListHandler.py b/plugins/magnatune/TrackListHandler.py
index 96a5a0f..357285d 100644
--- a/plugins/magnatune/TrackListHandler.py
+++ b/plugins/magnatune/TrackListHandler.py
@@ -93,10 +93,10 @@ class TrackListHandler(xml.sax.handler.ContentHandler):
                                self.__art_dict[sku] = str(self.__track['cover_small'])
 
                                self.__db.commit()
-                       except Exception,e: # This happens on duplicate uris being added
+                       except Exception as e: # This happens on duplicate uris being added
                                import sys
                                sys.excepthook(*sys.exc_info())
-                               print "Couldn't add %s - %s" % (self.__track['artist'], 
self.__track['trackname']), e
+                               print("Couldn't add %s - %s" % (self.__track['artist'], 
self.__track['trackname']), e)
 
                        self.__track = {}
                elif name == "AllSongs":
diff --git a/plugins/magnatune/magnatune.py b/plugins/magnatune/magnatune.py
index ef4330e..9cda0bf 100644
--- a/plugins/magnatune/magnatune.py
+++ b/plugins/magnatune/magnatune.py
@@ -59,7 +59,7 @@ class MagnatuneEntryType(RB.RhythmDBEntryType):
                if account_type != "none":
                        uri = self.URIre.sub("http://%s:%s %s magnatune com/" % (username, password, 
account_type), uri)
                        uri = self.nsre.sub(r"_nospeech.\1", uri)
-                       print "converted track uri: %s" % uri
+                       print("converted track uri: %s" % uri)
 
                return uri
 
@@ -197,7 +197,7 @@ class MagnatuneConfig(GObject.GObject, PeasGtk.Configurable):
 
 
                def account_type_toggled(button):
-                       print "account type radiobutton toggled: " + button.get_name()
+                       print("account type radiobutton toggled: " + button.get_name())
                        account_type = {"no_account_radio": 'none', "stream_account_radio": 'stream', 
"download_account_radio": 'download'} 
                        if button.get_active():
                                self.settings['account-type'] = account_type[button.get_name()]
@@ -208,7 +208,7 @@ class MagnatuneConfig(GObject.GObject, PeasGtk.Configurable):
                        password = builder.get_object("password_entry").get_text()
 
                        if username == "" or password == "":
-                               print "missing something"
+                               print("missing something")
                                return
 
                        # should actually try a request to http://username:password account-type magnatune 
com/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]