conduit r1222 - in trunk: . conduit/datatypes conduit/modules/FeedModule test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1222 - in trunk: . conduit/datatypes conduit/modules/FeedModule test/python-tests
- Date: Tue, 15 Jan 2008 13:07:26 +0000 (GMT)
Author: jstowers
Date: Tue Jan 15 13:07:25 2008
New Revision: 1222
URL: http://svn.gnome.org/viewvc/conduit?rev=1222&view=rev
Log:
2008-01-16 John Stowers <john stowers gmail com>
* conduit/datatypes/File.py: When setting filename, ensure it is a string
because gnomevfs does not like unicode
* conduit/modules/FeedModule/FeedModule.py:
* conduit/modules/FeedModule/config.glade: Add support for video enclosures
and retain the title and extension when downloading
* test/python-tests/TestDataProviderFeed.py: Add test for RSSSource
Added:
trunk/test/python-tests/TestDataProviderFeed.py
Modified:
trunk/ChangeLog
trunk/conduit/datatypes/File.py
trunk/conduit/modules/FeedModule/FeedModule.py
trunk/conduit/modules/FeedModule/config.glade
Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py (original)
+++ trunk/conduit/datatypes/File.py Tue Jan 15 13:07:25 2008
@@ -141,13 +141,16 @@
def _set_filename(self, filename):
newInfo = gnomevfs.FileInfo()
- newInfo.name = filename
-
- oldname = self.get_filename()
- olduri = self._get_text_uri()
- newuri = olduri.replace(oldname, filename)
+ #FIXME: Gnomevfs complains if name is unicode
+ filename = str(filename)
+ oldname = str(self.get_filename())
+
if filename != oldname:
+ newInfo.name = filename
+ olduri = self._get_text_uri()
+ newuri = olduri.replace(oldname, filename)
+
log.debug("Trying to rename file %s (%s) -> %s (%s)" % (olduri,oldname,newuri,filename))
gnomevfs.set_file_info(self.URI,newInfo,gnomevfs.SET_FILE_INFO_NAME)
#close so the file info is re-read
Modified: trunk/conduit/modules/FeedModule/FeedModule.py
==============================================================================
--- trunk/conduit/modules/FeedModule/FeedModule.py (original)
+++ trunk/conduit/modules/FeedModule/FeedModule.py Tue Jan 15 13:07:25 2008
@@ -41,26 +41,24 @@
def __init__(self, *args):
DataProvider.DataSource.__init__(self)
- #self.feedUrl = "http://www.flickr.com/services/feeds/photos_public gne?id=44124362632 N01&format=rss_200_enc"
- #self.feedUrl = "http://www.lugradio.org/episodes.ogg.rss"
self.feedUrl = ""
- self.files = None
+ self.files = {}
- self.allowedTypes = []
self.limit = 0
self.downloadPhotos = True
self.downloadAudio = True
+ self.downloadVideo = True
mimetypes.init()
# loop through all mime types and detect common mime types
for m in mimetypes.types_map.values():
if m[:6] == "image/":
- self.PHOTO_TYPES.append(m)
+ RSSSource.PHOTO_TYPES.append(m)
elif m[:6] == "audio/":
- self.AUDIO_TYPES.append(m)
+ RSSSource.AUDIO_TYPES.append(m)
elif m[:6] == "video/":
- self.VIDEO_TYPES.append(m)
+ RSSSource.VIDEO_TYPES.append(m)
# why on gods green earth is there an application/ogg :(
self.AUDIO_TYPES.append("application/ogg")
@@ -81,6 +79,7 @@
limitSb = tree.get_widget("limitnumber")
photosCb = tree.get_widget("downloadphotos")
audioCb = tree.get_widget("downloadaudio")
+ videoCb = tree.get_widget("downloadvideo")
#preload the widgets
if self.limit > 0:
@@ -91,7 +90,8 @@
url.set_text(self.feedUrl)
photosCb.set_active(self.downloadPhotos)
audioCb.set_active(self.downloadAudio)
-
+ videoCb.set_active(self.downloadVideo)
+
dlg = tree.get_widget("RSSSourceConfigDialog")
response = Utils.run_dialog (dlg, window)
@@ -100,21 +100,25 @@
if limitCb.get_active():
#Need to cast to a float cause it returns an int
self.limit = int(limitSb.get_value())
- self.allowedTypes = []
- if photosCb.get_active():
- self.allowedTypes += RSSSource.PHOTO_TYPES
- if audioCb.get_active():
- self.allowedTypes += RSSSource.AUDIO_TYPES
- self.downloadAudio = audioCb.get_active()
self.downloadPhotos = photosCb.get_active()
+ self.downloadAudio = audioCb.get_active()
+ self.downloadVideo = videoCb.get_active()
dlg.destroy()
- log.debug(self.allowedTypes)
def refresh(self):
DataProvider.DataSource.refresh(self)
- self.files = []
+ #Add allowed mimetypes to filter
+ allowedTypes = []
+ if self.downloadPhotos:
+ allowedTypes += RSSSource.PHOTO_TYPES
+ if self.downloadAudio:
+ allowedTypes += RSSSource.AUDIO_TYPES
+ if self.downloadVideo:
+ allowedTypes += RSSSource.VIDEO_TYPES
+
+ self.files = {}
try:
url_info = urllib2.urlopen(self.feedUrl)
if (url_info):
@@ -133,13 +137,14 @@
t = c.get("type")
if c.tag == "title":
title = c.text
-
+
#Check if we have all the info
if url and t and title:
- if t in self.allowedTypes:
+ log.debug("Got enclosure %s %s (%s)" % (title,url,t))
+ if t in allowedTypes:
if ((url not in allreadyInserted) and ((len(allreadyInserted) < self.limit) or (self.limit == 0))):
allreadyInserted.append(url)
- self.files.append(url)
+ self.files[url] = (title,t)
else:
log.debug("Enclosure %s is on non-allowed type (%s)" % (title,t))
except:
@@ -148,34 +153,37 @@
def get_all(self):
DataProvider.DataSource.get_all(self)
- return self.files
+ return self.files.keys()
- def get(self, LUID):
- DataProvider.DataSource.get(self, LUID)
+ def get(self, url):
+ DataProvider.DataSource.get(self, url)
#Make a file
- f = File.File(LUID)
-
- #create the correct extension
- # use python built in mimetypes (utilises /etc/mime.types)
- # fix to use pygtk when they are out of api freeze and can fix 349619?
+ f = File.File(URI=url)
+ f.set_UID(url)
+ f.set_open_URI(url)
+
+ #create the correct extension and filename
try:
+ title,t = self.files[url]
ext = mimetypes.guess_extension(t)
+ f.force_new_filename(title)
+ f.force_new_file_extension(ext)
except:
- ext = ""
+ log.warn("Error setting filename\n%s" % traceback.format_exc())
return f
def finish(self, aborted, error, conflict):
DataProvider.DataSource.finish(self)
- self.files = None
+ self.files = {}
def get_configuration(self):
return {
"feedUrl" : self.feedUrl,
- "allowedTypes" : str(self.allowedTypes),
"limit" : self.limit,
"downloadPhotos" : self.downloadPhotos,
- "downloadAudio" : self.downloadAudio
+ "downloadAudio" : self.downloadAudio,
+ "downloadVideo" : self.downloadVideo
}
def get_UID(self):
Modified: trunk/conduit/modules/FeedModule/config.glade
==============================================================================
--- trunk/conduit/modules/FeedModule/config.glade (original)
+++ trunk/conduit/modules/FeedModule/config.glade Tue Jan 15 13:07:25 2008
@@ -1,258 +1,183 @@
-<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
-<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
-
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--*- mode: xml -*-->
<glade-interface>
-<requires lib="gnome"/>
-
-<widget class="GtkDialog" id="RSSSourceConfigDialog">
- <property name="visible">True</property>
- <property name="title" translatable="yes">RSS Feed</property>
- <property name="type">GTK_WINDOW_TOPLEVEL</property>
- <property name="window_position">GTK_WIN_POS_NONE</property>
- <property name="modal">False</property>
- <property name="default_width">250</property>
- <property name="default_height">350</property>
- <property name="resizable">False</property>
- <property name="destroy_with_parent">False</property>
- <property name="decorated">True</property>
- <property name="skip_taskbar_hint">False</property>
- <property name="skip_pager_hint">False</property>
- <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
- <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
- <property name="focus_on_map">True</property>
- <property name="urgency_hint">False</property>
- <property name="has_separator">True</property>
-
- <child internal-child="vbox">
- <widget class="GtkVBox" id="vbox22">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">0</property>
-
- <child internal-child="action_area">
- <widget class="GtkHButtonBox" id="hbuttonbox9">
- <property name="visible">True</property>
- <property name="layout_style">GTK_BUTTONBOX_END</property>
-
- <child>
- <widget class="GtkButton" id="button24">
- <property name="visible">True</property>
- <property name="can_default">True</property>
- <property name="can_focus">True</property>
- <property name="label">gtk-cancel</property>
- <property name="use_stock">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="response_id">-6</property>
- </widget>
- </child>
-
- <child>
- <widget class="GtkButton" id="button25">
- <property name="visible">True</property>
- <property name="can_default">True</property>
- <property name="can_focus">True</property>
- <property name="label">gtk-ok</property>
- <property name="use_stock">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="response_id">-5</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="pack_type">GTK_PACK_END</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkVBox" id="vbox23">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">5</property>
-
- <child>
- <widget class="GtkLabel" id="label52">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><b>Feed Details</b></property>
- <property name="use_underline">False</property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkLabel" id="label56">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Feed Address:</property>
- <property name="use_underline">False</property>
- <property name="use_markup">False</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkEntry" id="url">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">True</property>
- <property name="visibility">True</property>
- <property name="max_length">0</property>
- <property name="text" translatable="yes"></property>
- <property name="has_frame">True</property>
- <property name="invisible_char">â</property>
- <property name="activates_default">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkLabel" id="label55">
- <property name="visible">True</property>
- <property name="label" translatable="yes"><b>Enclosure Settings</b></property>
- <property name="use_underline">False</property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkCheckButton" id="limitdownloads">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">Limit the Number of
+ <widget class="GtkDialog" id="RSSSourceConfigDialog">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">RSS Feed</property>
+ <property name="resizable">False</property>
+ <property name="default_width">250</property>
+ <property name="default_height">350</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="vbox22">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkVBox" id="vbox23">
+ <property name="visible">True</property>
+ <property name="spacing">5</property>
+ <child>
+ <widget class="GtkLabel" id="label52">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Feed Details</b></property>
+ <property name="use_markup">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label56">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Feed Address:</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkEntry" id="url">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label55">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Enclosure Settings</b></property>
+ <property name="use_markup">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkCheckButton" id="limitdownloads">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Limit the Number of
Enclosures Downloaded to:</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkSpinButton" id="limitnumber">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="climb_rate">1</property>
- <property name="digits">0</property>
- <property name="numeric">False</property>
- <property name="update_policy">GTK_UPDATE_ALWAYS</property>
- <property name="snap_to_ticks">False</property>
- <property name="wrap">False</property>
- <property name="adjustment">1 1 100 1 10 10</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkCheckButton" id="downloadphotos">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">Download photos</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">True</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkCheckButton" id="downloadaudio">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">Download audio</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">True</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- </child>
-</widget>
-
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkSpinButton" id="limitnumber">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">1 1 100 1 10 10</property>
+ <property name="climb_rate">1</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">5</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkCheckButton" id="downloadphotos">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Download Photos</property>
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">6</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkCheckButton" id="downloadaudio">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Download Audio Files</property>
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">7</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkCheckButton" id="downloadvideo">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Download Video Files</property>
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">8</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="hbuttonbox9">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <child>
+ <widget class="GtkButton" id="button24">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="label">gtk-cancel</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">-6</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkButton" id="button25">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="label">gtk-ok</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">-5</property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">GTK_PACK_END</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
</glade-interface>
Added: trunk/test/python-tests/TestDataProviderFeed.py
==============================================================================
--- (empty file)
+++ trunk/test/python-tests/TestDataProviderFeed.py Tue Jan 15 13:07:25 2008
@@ -0,0 +1,54 @@
+#common sets up the conduit environment
+from common import *
+
+if not is_online():
+ skip()
+
+#setup the test
+test = SimpleTest(sourceName="RSSSource")
+
+TESTS = (
+ ("Photos", "http://www.flickr.com/services/feeds/photos_public gne?id=44124362632 N01&format=rss_200_enc"),
+ ("Audio", "http://www.lugradio.org/episodes.ogg.rss"),
+ ("Video", "http://telemusicvision.com/videos/tmv.rss")
+)
+
+for name,url in TESTS:
+ ok("%s: Url %s" % (name,url), True)
+
+ config = {
+ "feedUrl": url,
+ "limit": 1,
+ "downloadPhotos": True,
+ "downloadAudio": True,
+ "downloadVideo": True
+ }
+ test.configure(source=config)
+ dp = test.get_source().module
+
+ try:
+ dp.refresh()
+ ok("%s: Downloaded feed ok" % name, True)
+ except Exception, err:
+ ok("%s: Downloaded feed (%s)" % (name,err), False)
+
+ try:
+ enclosures = dp.get_all()
+ ok("%s: Got enclosures" % name, len(enclosures) > 0)
+ except Exception, err:
+ ok("%s: Got enclosures (%s)" % (name,err), False)
+
+ try:
+ f = dp.get(enclosures[0])
+ ok("%s: Got a file" % name, f.exists())
+ except Exception, err:
+ ok("%s: Got a file (%s)" % (name,err), False)
+
+ try:
+ dp.finish(True,True,True)
+ config2 = dp.get_configuration()
+ ok("%s: Got configuration" % name, config == config2)
+ except Exception, err:
+ ok("%s: Got configuration (%s)" % (name,err), False)
+
+finished()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]