[totem] plugins: Make various methods in the iPlayer plugin private
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] plugins: Make various methods in the iPlayer plugin private
- Date: Tue, 5 Apr 2011 00:15:47 +0000 (UTC)
commit 809cc090bccb8a8b27d14fadd0165bb1b778e238
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Apr 4 23:04:23 2011 +0100
plugins: Make various methods in the iPlayer plugin private
Helps: bgo#645739
src/plugins/iplayer/iplayer.py | 62 ++++++++++++++++++++------------------
src/plugins/iplayer/iplayer2.py | 60 +++++++++++++++++++-------------------
2 files changed, 63 insertions(+), 59 deletions(-)
---
diff --git a/src/plugins/iplayer/iplayer.py b/src/plugins/iplayer/iplayer.py
index 9b28d65..720ffa9 100644
--- a/src/plugins/iplayer/iplayer.py
+++ b/src/plugins/iplayer/iplayer.py
@@ -35,8 +35,8 @@ class IplayerPlugin (GObject.Object, Peas.Activatable):
self.tv_tree_store = builder.get_object ('iplayer_programme_store')
programme_list = builder.get_object ('iplayer_programme_list')
- programme_list.connect ('row-expanded', self._row_expanded_cb)
- programme_list.connect ('row-activated', self._row_activated_cb)
+ programme_list.connect ('row-expanded', self.__row_expanded_cb)
+ programme_list.connect ('row-activated', self.__row_activated_cb)
container.show_all ()
@@ -46,12 +46,12 @@ class IplayerPlugin (GObject.Object, Peas.Activatable):
self.totem.add_sidebar_page ("iplayer", _(u"BBC iPlayer"), container)
# Get the channel category listings
- self.populate_channel_list (self.tv_feed, self.tv_tree_store)
+ self._populate_channel_list (self.tv_feed, self.tv_tree_store)
def do_deactivate (self):
self.totem.remove_sidebar_page ("iplayer")
- def populate_channel_list (self, feed, tree_store):
+ def _populate_channel_list (self, feed, tree_store):
if self.debug:
print "Populating channel listâ?¦"
@@ -62,10 +62,11 @@ class IplayerPlugin (GObject.Object, Peas.Activatable):
# Add the channels' categories in a thread, since they each require a
# network request
- thread = PopulateChannelsThread (self, feed, tree_store)
+ thread = PopulateChannelsThread (self.__populate_channel_list_cb,
+ feed, tree_store)
thread.start ()
- def _populate_channel_list_cb (self, tree_store, parent_path, values):
+ def __populate_channel_list_cb (self, tree_store, parent_path, values):
# Callback from PopulateChannelsThread to add stuff to the tree store
if values == None:
self.totem.action_error (_(u'Error listing channel categories'),
@@ -84,11 +85,11 @@ class IplayerPlugin (GObject.Object, Peas.Activatable):
return False
- def _row_expanded_cb (self, tree_view, row_iter, path):
+ def __row_expanded_cb (self, tree_view, row_iter, path):
tree_model = tree_view.get_model ()
if self.debug:
- print "_row_expanded_cb called."
+ print "__row_expanded_cb called."
# We only care about the category level (level 1), and only when
# it has the "Loading..." placeholder child row
@@ -97,9 +98,9 @@ class IplayerPlugin (GObject.Object, Peas.Activatable):
return
# Populate it with programmes asynchronously
- self.populate_programme_list (self.tv_feed, tree_model, row_iter)
+ self._populate_programme_list (self.tv_feed, tree_model, row_iter)
- def _row_activated_cb (self, tree_view, path, view_column):
+ def __row_activated_cb (self, tree_view, path, view_column):
tree_store = tree_view.get_model ()
tree_iter = tree_store.get_iter (path)
if tree_iter == None:
@@ -116,16 +117,17 @@ class IplayerPlugin (GObject.Object, Peas.Activatable):
title = tree_store.get_value (tree_iter, 0)
self.totem.add_to_playlist_and_play (mrl, title, True)
- def populate_programme_list (self, feed, tree_store, category_iter):
+ def _populate_programme_list (self, feed, tree_store, category_iter):
if self.debug:
print "Populating programme listâ?¦"
category_path = tree_store.get_path (category_iter)
- thread = PopulateProgrammesThread (self, feed, tree_store,
- category_path)
+ thread = PopulateProgrammesThread (self,
+ self.__populate_programme_list_cb,
+ feed, (tree_store, category_path))
thread.start ()
- def _populate_programme_list_cb (self, tree_store, category_path, values,
+ def __populate_programme_list_cb (self, tree_store, category_path, values,
remove_placeholder):
# Callback from PopulateProgrammesThread to add stuff to the tree store
if values == None:
@@ -162,8 +164,8 @@ def category_name_to_id (category_name):
class PopulateChannelsThread (threading.Thread):
# Class to populate the channel list from the Internet
- def __init__ (self, plugin, feed, tree_model):
- self.plugin = plugin
+ def __init__ (self, callback, feed, tree_model):
+ self.callback = callback
self.feed = feed
self.tree_model = tree_model
threading.Thread.__init__ (self)
@@ -182,14 +184,14 @@ class PopulateChannelsThread (threading.Thread):
# invalidating an iter
for name, _count in self.feed.get (channel_id).categories ():
category_id = category_name_to_id (name)
- GObject.idle_add (self.plugin._populate_channel_list_cb,
+ GObject.idle_add (self.callback,
self.tree_model, parent_path,
[name, category_id, None])
except:
# Only show the error once, rather than for each channel
# (it gets a bit grating)
if not shown_error:
- GObject.idle_add (self.plugin._populate_channel_list_cb,
+ GObject.idle_add (self.callback,
self.tree_model, parent_path, None)
shown_error = True
@@ -198,21 +200,23 @@ class PopulateChannelsThread (threading.Thread):
class PopulateProgrammesThread (threading.Thread):
# Class to populate the programme list for a channel/category combination
# from the Internet
- def __init__ (self, plugin, feed, tree_model, category_path):
- self.plugin = plugin
+ def __init__ (self, download_lock, callback, feed,
+ (tree_model, category_path)):
+ self.download_lock = download_lock
+ self.callback = callback
self.feed = feed
self.tree_model = tree_model
self.category_path = category_path
threading.Thread.__init__ (self)
def run (self):
- self.plugin.programme_download_lock.acquire ()
+ self.download_lock.acquire ()
category_iter = self.tree_model.get_iter (self.category_path)
if category_iter == None:
- GObject.idle_add (self.plugin._populate_programme_list_cb,
+ GObject.idle_add (self.callback,
self.tree_model, self.category_path, None, False)
- self.plugin.programme_download_lock.release ()
+ self.download_lock.release ()
return
category_id = self.tree_model.get_value (category_iter, 1)
@@ -222,18 +226,18 @@ class PopulateProgrammesThread (threading.Thread):
# Retrieve the programmes and return them
feed = self.feed.get (channel_id).get (category_id)
if feed == None:
- GObject.idle_add (self.plugin._populate_programme_list_cb,
+ GObject.idle_add (self.callback,
self.tree_model, self.category_path, None, False)
- self.plugin.programme_download_lock.release ()
+ self.download_lock.release ()
return
# Get the programmes
try:
programmes = feed.list ()
except:
- GObject.idle_add (self.plugin._populate_programme_list_cb,
+ GObject.idle_add (self.callback,
self.tree_model, self.category_path, None, False)
- self.plugin.programme_download_lock.release ()
+ self.download_lock.release ()
return
# Add the programmes to the tree store
@@ -252,11 +256,11 @@ class PopulateProgrammesThread (threading.Thread):
print "Programme has no HTTP streams"
continue
- GObject.idle_add (self.plugin._populate_programme_list_cb,
+ GObject.idle_add (self.callback,
self.tree_model, self.category_path,
[programme.get_title (), programme.get_summary (),
media.url],
remove_placeholder)
remove_placeholder = False
- self.plugin.programme_download_lock.release ()
+ self.download_lock.release ()
diff --git a/src/plugins/iplayer/iplayer2.py b/src/plugins/iplayer/iplayer2.py
index d9918d2..71cf300 100644
--- a/src/plugins/iplayer/iplayer2.py
+++ b/src/plugins/iplayer/iplayer2.py
@@ -317,7 +317,7 @@ class Media (object):
self.kind = None
self.method = None
self.width, self.height = None, None
- self.read_media_node (media_node)
+ self.__read_media_node (media_node)
self.mimetype = None
self.encoding = None
@@ -359,7 +359,7 @@ class Media (object):
self.connection_protocol)
return tep.get (media, None)
- def read_media_node (self, media):
+ def __read_media_node (self, media):
"""
Reads media info from a media XML node
media: media node from BeautifulStoneSoup
@@ -439,9 +439,9 @@ class Item (object):
self.group = None
self.kind = None
self.live = False
- self.read_item_node (item_node)
+ self.__read_item_node (item_node)
- def read_item_node (self, node):
+ def __read_item_node (self, node):
"""
Reads the specified XML <item> node and sets this instance's
properties.
@@ -545,9 +545,9 @@ class Programme (object):
self._related = []
@call_once
- def read_playlist (self):
+ def __read_playlist (self):
#logging.info ('Read playlist for %s...', self.pid)
- self.parse_playlist (self.playlist)
+ self.__parse_playlist (self.playlist)
def get_playlist_xml (self):
""" Downloads and returns the XML for a PID from the iPlayer site. """
@@ -560,7 +560,7 @@ class Programme (object):
#logging.error ("Timed out trying to download programme XML")
raise
- def parse_playlist (self, xml):
+ def __parse_playlist (self, xml):
#logging.info ('Parsing playlist XML... %s', xml)
entities = BeautifulStoneSoup.XML_ENTITIES
@@ -631,19 +631,19 @@ class Programme (object):
def get_updated (self):
return self.meta['updated']
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_title (self):
return self.meta['title']
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_summary (self):
return self.meta['summary']
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_related (self):
return self._related
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_items (self):
if not self._items:
raise NoItemsError (self.meta['reason'])
@@ -683,13 +683,13 @@ class ProgrammeSimple (object):
self._related = []
@call_once
- def read_playlist (self):
+ def __read_playlist (self):
pass
def get_playlist_xml (self):
pass
- def parse_playlist (self, xml):
+ def __parse_playlist (self, xml):
pass
def get_thumbnail (self, size='large', tvradio='tv'):
@@ -728,19 +728,19 @@ class ProgrammeSimple (object):
def get_updated (self):
return self.meta['updated']
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_title (self):
return self.meta['title']
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_summary (self):
return self.meta['summary']
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_related (self):
return self._related
- @loaded_by (read_playlist)
+ @loaded_by (__read_playlist)
def get_items (self):
if not self._items:
raise NoItemsError (self.meta['reason'])
@@ -794,7 +794,7 @@ class Feed (object):
self.atoz = atoz
self.searchterm = searchterm
- def create_url (self, listing):
+ def __create_url (self, listing):
"""
<channel>/['list'|'popular'|'highlights']
'categories'/<category> (/<subcategory>) \
@@ -902,18 +902,18 @@ class Feed (object):
raise NotImplementedError ('Sub-categories not yet supported')
@classmethod
- def is_atoz (cls, letter):
+ def __is_atoz (cls, letter):
"""
Return False if specified letter is not a valid 'A to Z' directory
entry. Otherwise returns the directory name.
- >>> feed.is_atoz ('a'), feed.is_atoz ('z')
+ >>> feed.__is_atoz ('a'), feed.__is_atoz ('z')
('a', 'z')
- >>> feed.is_atoz ('0'), feed.is_atoz ('9')
+ >>> feed.__is_atoz ('0'), feed.__is_atoz ('9')
('0-9', '0-9')
- >>> feed.is_atoz ('123'), feed.is_atoz ('abc')
+ >>> feed.__is_atoz ('123'), feed.__is_atoz ('abc')
(False, False)
- >>> feed.is_atoz ('big british castle'), feed.is_atoz ('')
+ >>> feed.__is_atoz ('big british castle'), feed.__is_atoz ('')
(False, False)
"""
letter = letter.lower ()
@@ -952,8 +952,8 @@ class Feed (object):
elif self.category:
# no children: TODO support subcategories
return None
- elif self.is_atoz (subfeed):
- return self.sub (atoz=self.is_atoz (subfeed))
+ elif self.__is_atoz (subfeed):
+ return self.sub (atoz=self.__is_atoz (subfeed))
else:
if subfeed in CHANNELS_TV:
return Feed ('tv', channel = subfeed)
@@ -963,7 +963,7 @@ class Feed (object):
return None
@classmethod
- def read_rss (cls, url):
+ def __read_rss (cls, url):
#logging.info ('Read RSS: %s', url)
if url not in RSS_CACHE:
#logging.info ('Feed URL not in cache, requesting...')
@@ -983,17 +983,17 @@ class Feed (object):
return RSS_CACHE[url]
def popular (self):
- return self.read_rss (self.create_url ('popular'))
+ return self.__read_rss (self.__create_url ('popular'))
def highlights (self):
- return self.read_rss (self.create_url ('highlights'))
+ return self.__read_rss (self.__create_url ('highlights'))
def list (self):
- return self.read_rss (self.create_url ('list'))
+ return self.__read_rss (self.__create_url ('list'))
def categories (self):
# quick and dirty category extraction and count
- xml_url = self.create_url ('list')
+ xml_url = self.__create_url ('list')
xml = httpget (xml_url)
cat = re.findall ("<category .*term=\" (.*?)\"", xml)
categories = {}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]