[rhythmbox/wip/python3] Port context plugin to python 3
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/wip/python3] Port context plugin to python 3
- Date: Mon, 15 Apr 2013 09:12:25 +0000 (UTC)
commit 9c93e307897cd41f9440eccfe8e8a38f54f6a0de
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Apr 15 11:12:10 2013 +0200
Port context plugin to python 3
plugins/context/AlbumTab.py | 24 +++++++++----------
plugins/context/ArtistTab.py | 22 ++++++++---------
plugins/context/ContextView.py | 46 ++++++++++++++++++------------------
plugins/context/LastFM.py | 10 ++++----
plugins/context/LinksTab.py | 6 ++---
plugins/context/LyricsTab.py | 8 +++----
plugins/context/tmpl/album-tmpl.html | 2 +-
plugins/rb/rb.py | 2 +-
8 files changed, 60 insertions(+), 60 deletions(-)
---
diff --git a/plugins/context/AlbumTab.py b/plugins/context/AlbumTab.py
index 61b3a1a..ac66bb1 100644
--- a/plugins/context/AlbumTab.py
+++ b/plugins/context/AlbumTab.py
@@ -102,7 +102,7 @@ class AlbumView (GObject.GObject):
self.file = ""
plugindir = plugin.plugin_info.get_data_dir()
- self.basepath = "file://" + urllib.pathname2url (plugindir)
+ self.basepath = "file://" + urllib.request.pathname2url (plugindir)
self.load_tmpl ()
self.connect_signals ()
@@ -160,7 +160,7 @@ class AlbumDataSource (GObject.GObject):
"""
try:
return data[position].firstChild.data
- except Exception, e:
+ except Exception as e:
return None
def get_artist (self):
@@ -186,13 +186,13 @@ class AlbumDataSource (GObject.GObject):
def parse_album_list (self, data, artist):
if data is None:
- print "Nothing fetched for %s top albums" % artist
+ print("Nothing fetched for %s top albums" % artist)
return
try:
parsed = dom.parseString (data)
- except Exception, e:
- print "Error parsing album list: %s" % e
+ except Exception as e:
+ print("Error parsing album list: %s" % e)
return False
lfm = parsed.getElementsByTagName ('lfm')[0]
@@ -203,7 +203,7 @@ class AlbumDataSource (GObject.GObject):
self.albums = []
album_nodes = parsed.getElementsByTagName ('album')
- print "num albums: %d" % len(album_nodes)
+ print("num albums: %d" % len(album_nodes))
if len(album_nodes) == 0:
self.error = "No albums found for %s" % artist
self.emit('albums-ready')
@@ -241,8 +241,8 @@ class AlbumDataSource (GObject.GObject):
try:
parsed = dom.parseString (data)
self.albums[index]['id'] = parsed.getElementsByTagName ('id')[0].firstChild.data
- except Exception, e:
- print "Error parsing album tracklist: %s" % e
+ except Exception as e:
+ print("Error parsing album tracklist: %s" % e)
return False
self.albums[index]['releasedate'] = self.extract(parsed.getElementsByTagName ('releasedate'),0)
@@ -257,7 +257,7 @@ class AlbumDataSource (GObject.GObject):
def assemble_info (self, data, album, index):
rv = True
if data is None:
- print "nothing fetched for %s tracklist" % album
+ print("nothing fetched for %s tracklist" % album)
else:
try:
parsed = dom.parseString (data)
@@ -271,12 +271,12 @@ class AlbumDataSource (GObject.GObject):
tracklist.append ((i, title, duration))
self.albums[index]['tracklist'] = tracklist
self.albums[index]['duration'] = album_length
- except Exception, e:
- print "Error parsing album playlist: %s" % e
+ except Exception as e:
+ print("Error parsing album playlist: %s" % e)
rv = False
self.album_info_fetched -= 1
- print "%s albums left to process" % self.album_info_fetched
+ print("%s albums left to process" % self.album_info_fetched)
if self.album_info_fetched == 0:
self.emit('albums-ready')
diff --git a/plugins/context/ArtistTab.py b/plugins/context/ArtistTab.py
index 4859991..a333f42 100644
--- a/plugins/context/ArtistTab.py
+++ b/plugins/context/ArtistTab.py
@@ -69,20 +69,20 @@ class ArtistTab (GObject.GObject):
buttons.pack_start (self.button, True, True, 0)
def activate (self):
- print "activating Artist Tab"
+ print("activating Artist Tab")
self.button.set_active(True)
self.active = True
self.reload ()
def deactivate (self):
- print "deactivating Artist Tab"
+ print("deactivating Artist Tab")
self.button.set_active(False)
self.active = False
def reload (self):
entry = self.sp.get_playing_entry ()
if entry is None:
- print "Nothing playing"
+ print("Nothing playing")
return None
artist = entry.get_string (RB.RhythmDBPropType.ARTIST)
@@ -103,8 +103,8 @@ class ArtistView (GObject.GObject):
self.plugin = plugin
self.file = ""
- plugindir = plugin.plugin_info.get_data_dir()
- self.basepath = "file://" + urllib.pathname2url (plugindir)
+ plugindir = plugin.plugin_info.get_data_dir()
+ self.basepath = "file://" + urllib.request.pathname2url (plugindir)
self.load_tmpl ()
self.connect_signals ()
@@ -145,8 +145,8 @@ class ArtistView (GObject.GObject):
datasource = LastFM.datasource_link (self.basepath),
stylesheet = self.styles )
self.load_view ()
- except Exception, e:
- print "Problem in info ready: %s" % e
+ except Exception as e:
+ print("Problem in info ready: %s" % e)
class ArtistDataSource (GObject.GObject):
@@ -205,7 +205,7 @@ class ArtistDataSource (GObject.GObject):
try:
return data[position].firstChild.data
- except Exception, e:
+ except Exception as e:
return None
def fetch_top_tracks (self, artist):
@@ -243,15 +243,15 @@ class ArtistDataSource (GObject.GObject):
def fetch_artist_data_cb (self, data, category):
if data is None:
- print "no data fetched for artist %s" % category['function']
+ print("no data fetched for artist %s" % category['function'])
return
try:
category['data'] = dom.parseString (data)
category['parsed'] = False
self.emit (category['signal'])
- except Exception, e:
- print "Error parsing artist %s: %s" % (category['function'], e)
+ except Exception as e:
+ print("Error parsing artist %s: %s" % (category['function'], e))
return False
def get_current_artist (self):
diff --git a/plugins/context/ContextView.py b/plugins/context/ContextView.py
index f7515ce..86bcb42 100644
--- a/plugins/context/ContextView.py
+++ b/plugins/context/ContextView.py
@@ -81,15 +81,15 @@ class ContextView (GObject.GObject):
self.current = 'artist'
self.tab[self.current].activate ()
- app = shell.props.application
- action = Gio.SimpleAction.new_stateful("view-context-pane", None, GLib.Variant.new_boolean(True))
- action.connect("activate", self.toggle_visibility, None)
+ app = shell.props.application
+ action = Gio.SimpleAction.new_stateful("view-context-pane", None, GLib.Variant.new_boolean(True))
+ action.connect("activate", self.toggle_visibility, None)
- window = shell.props.window
- window.add_action(action)
+ window = shell.props.window
+ window.add_action(action)
- item = Gio.MenuItem.new(label=_("Context Pane"), detailed_action="win.view-context-pane")
- app.add_plugin_menu_item("view", "view-context-pane", item)
+ item = Gio.MenuItem.new(label=_("Context Pane"), detailed_action="win.view-context-pane")
+ app.add_plugin_menu_item("view", "view-context-pane", item)
def deactivate (self, shell):
@@ -106,15 +106,15 @@ class ContextView (GObject.GObject):
if self.visible:
shell.remove_widget (self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR)
self.visible = False
- self.vbox = None
- self.label = None
- self.webview = None
- self.websettings = None
- self.buttons = None
- self.top_five_list = None
+ self.vbox = None
+ self.label = None
+ self.webview = None
+ self.websettings = None
+ self.buttons = None
+ self.top_five_list = None
- app = shell.props.application
- app.remove_plugin_menu_item("view", "view-context-pane")
+ app = shell.props.application
+ app.remove_plugin_menu_item("view", "view-context-pane")
def connect_signals(self):
self.player_cb_ids = ( self.sp.connect ('playing-changed', self.playing_changed_cb),
@@ -136,7 +136,7 @@ class ContextView (GObject.GObject):
self.tab[key].disconnect (id)
def toggle_visibility (self, action, parameter, data):
- if self.visible:
+ if self.visible:
self.shell.remove_widget (self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR)
self.visible = False
else:
@@ -144,7 +144,7 @@ class ContextView (GObject.GObject):
self.visible = True
def change_tab (self, tab, newtab):
- print "swapping tab from %s to %s" % (self.current, newtab)
+ print("swapping tab from %s to %s" % (self.current, newtab))
if (self.current != newtab):
self.tab[self.current].deactivate()
self.tab[newtab].activate()
@@ -209,8 +209,8 @@ class ContextView (GObject.GObject):
def navigation_request_cb(self, view, frame, request):
# open HTTP URIs externally. this isn't a web browser.
if request.get_uri().startswith('http'):
- print "opening uri %s" % request.get_uri()
- Gtk.show_uri(self.shell.props.window.get_screen(), request.get_uri(), Gdk.CURRENT_TIME)
+ print("opening uri %s" % request.get_uri())
+ Gtk.show_uri(self.shell.props.window.get_screen(), request.get_uri(), Gdk.CURRENT_TIME)
return 1 # WEBKIT_NAVIGATION_RESPONSE_IGNORE
else:
@@ -229,7 +229,7 @@ class ContextView (GObject.GObject):
font_size /= Pango.SCALE
self.websettings.props.default_font_size = font_size
self.websettings.props.default_font_family = style.font_desc.get_family()
- print "web view font settings: %s, %d" % (style.font_desc.get_family(), font_size)
+ print("web view font settings: %s, %d" % (style.font_desc.get_family(), font_size))
def init_gui(self):
self.vbox = Gtk.VBox()
@@ -261,9 +261,9 @@ class ContextView (GObject.GObject):
top_five_view.set_headers_visible( False )
- scroll = Gtk.ScrolledWindow()
- scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
- scroll.add(top_five_view)
+ scroll = Gtk.ScrolledWindow()
+ scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
+ scroll.add(top_five_view)
frame.add (scroll)
diff --git a/plugins/context/LastFM.py b/plugins/context/LastFM.py
index cb4301c..687e044 100644
--- a/plugins/context/LastFM.py
+++ b/plugins/context/LastFM.py
@@ -25,7 +25,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import os
-import ConfigParser
+import configparser
from gi.repository import RB
@@ -45,14 +45,14 @@ def user_has_account():
session_file = os.path.join(RB.user_data_dir(), "audioscrobbler", "sessions")
if os.path.exists(session_file) == False:
- return False
+ return False
- sessions = ConfigParser.RawConfigParser()
+ sessions = configparser.RawConfigParser()
sessions.read(session_file)
try:
- return (sessions.get('Last.fm', 'username') != "")
+ return (sessions.get('Last.fm', 'username') != "")
except:
- return False
+ return False
def datasource_link(path):
return "<a href='http://last.fm/'><img src='%s/img/lastfm.png'></a>" % path
diff --git a/plugins/context/LinksTab.py b/plugins/context/LinksTab.py
index ea49e65..7fd42c4 100644
--- a/plugins/context/LinksTab.py
+++ b/plugins/context/LinksTab.py
@@ -66,12 +66,12 @@ class LinksTab (GObject.GObject):
buttons.pack_start (self.button, True, True, 0)
def activate (self):
- print "activating Links Tab"
+ print("activating Links Tab")
self.button.set_active(True)
self.reload ()
def deactivate (self):
- print "deactivating Links Tab"
+ print("deactivating Links Tab")
self.button.set_active(False)
def reload (self):
@@ -103,7 +103,7 @@ class LinksView (GObject.GObject):
self.basepath = "file://" + urllib.pathname2url (plugindir)
def load_links (self, ds):
- print "Loading links into webview"
+ print("Loading links into webview")
self.path = rb.find_plugin_file(self.plugin, 'tmpl/links-tmpl.html')
self.images = self.basepath + '/img/links/'
self.styles = self.basepath + '/tmpl/main.css'
diff --git a/plugins/context/LyricsTab.py b/plugins/context/LyricsTab.py
index c8b1fed..4fed759 100644
--- a/plugins/context/LyricsTab.py
+++ b/plugins/context/LyricsTab.py
@@ -62,12 +62,12 @@ class LyricsTab (GObject.GObject):
toolbar.pack_start (self.button, True, True, 0)
def activate (self):
- print "activating Lyrics Tab"
+ print("activating Lyrics Tab")
self.button.set_active(True)
self.reload ()
def deactivate (self):
- print "deactivating Lyrics Tab"
+ print("deactivating Lyrics Tab")
self.button.set_active(False)
def reload (self):
@@ -105,7 +105,7 @@ class LyricsView (GObject.GObject):
song = song,
basepath = self.basepath)
self.webview.load_string (self.loading_file, 'text/html', 'utf-8', self.basepath)
- print "loading screen loaded"
+ print("loading screen loaded")
def load_tmpl (self):
self.path = rb.find_plugin_file(self.plugin, 'tmpl/lyrics-tmpl.html')
@@ -115,7 +115,7 @@ class LyricsView (GObject.GObject):
self.styles = self.basepath + '/tmpl/main.css'
def lyrics_ready (self, ds, entry, lyrics):
- print "loading lyrics into webview"
+ print("loading lyrics into webview")
if lyrics is None:
lyrics = _("Lyrics not found")
else:
diff --git a/plugins/context/tmpl/album-tmpl.html b/plugins/context/tmpl/album-tmpl.html
index b8860c6..2a27d39 100644
--- a/plugins/context/tmpl/album-tmpl.html
+++ b/plugins/context/tmpl/album-tmpl.html
@@ -23,7 +23,7 @@
def format_year(date):
try:
parsed = rfc822.parsedate(date)
- except Exception, e:
+ except Exception as e:
return ""
if parsed is None:
return ""
diff --git a/plugins/rb/rb.py b/plugins/rb/rb.py
index 6fdc6c2..3bb0819 100644
--- a/plugins/rb/rb.py
+++ b/plugins/rb/rb.py
@@ -97,7 +97,7 @@ class _rbdebugfile:
# add the class name to the method, if 'self' exists
methodname = co.co_name
- if fr.f_locals.has_key('self'):
+ if 'self' in fr.f_locals:
methodname = '%s.%s' % (fr.f_locals['self'].__class__.__name__, methodname)
ln = co.co_firstlineno + fr.f_lineno
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]