Add object type filtering to iter_resources

This commit is contained in:
Laurent Bachelier 2012-02-05 13:30:02 +01:00
commit bfb3689456
16 changed files with 92 additions and 61 deletions

View file

@ -22,7 +22,7 @@ from __future__ import with_statement
import re
from weboob.capabilities.video import ICapVideo
from weboob.capabilities.video import ICapVideo, BaseVideo
from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.tools.value import Value
@ -71,6 +71,7 @@ class CanalplusBackend(BaseBackend, ICapVideo, ICapCollection):
OBJECTS = {CanalplusVideo: fill_video}
def iter_resources(self, split_path):
with self.browser:
return self.browser.iter_resources(split_path)
def iter_resources(self, objs, split_path):
if BaseVideo in objs:
with self.browser:
return self.browser.iter_resources(split_path)

View file

@ -19,6 +19,7 @@
from weboob.tools.test import BackendTest
from weboob.capabilities.video import BaseVideo
class CanalPlusTest(BackendTest):
BACKEND = 'canalplus'
@ -29,3 +30,10 @@ class CanalPlusTest(BackendTest):
v = l[0]
self.backend.fillobj(v, ('url',))
self.assertTrue(v.url and v.url.startswith('rtmp://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
def test_ls(self):
l = list(self.backend.iter_resources((BaseVideo, ), []))
self.assertTrue(len(l) > 0)
l = list(self.backend.iter_resources((BaseVideo, ), ['SPORT']))
self.assertTrue(len(l) > 0)

View file

@ -62,15 +62,16 @@ class NovaBackend(BaseBackend, ICapRadio, ICapCollection):
_RADIOS = {'nova': (u'Radio Nova', u'Radio nova', u'http://broadcast.infomaniak.net:80/radionova-high.mp3'),
}
def iter_resources(self, split_path):
if len(split_path) > 0:
raise CollectionNotFound(split_path)
def iter_resources(self, objs, split_path):
if Radio in objs:
if len(split_path) > 0:
raise CollectionNotFound(split_path)
for id in self._RADIOS.iterkeys():
yield self.get_radio(id)
for id in self._RADIOS.iterkeys():
yield self.get_radio(id)
def iter_radios_search(self, pattern):
for radio in self.iter_resources([]):
for radio in self.iter_resources((Radio, ), []):
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
yield radio

View file

@ -19,10 +19,11 @@
from weboob.tools.test import BackendTest
from weboob.capabilities.radio import Radio
class NovaTest(BackendTest):
BACKEND = 'nova'
def test_nova(self):
l = list(self.backend.iter_resources([]))
l = list(self.backend.iter_resources((Radio, ), []))
self.assertTrue(len(l) > 0)

View file

@ -46,15 +46,16 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
def create_default_browser(self):
return self.create_browser(parser='json')
def iter_resources(self, split_path):
if len(split_path) > 0:
raise CollectionNotFound(split_path)
def iter_resources(self, objs, split_path):
if Radio in objs:
if len(split_path) > 0:
raise CollectionNotFound(split_path)
for id in self._RADIOS.iterkeys():
yield self.get_radio(id)
for id in self._RADIOS.iterkeys():
yield self.get_radio(id)
def iter_radios_search(self, pattern):
for radio in self.iter_resources([]):
for radio in self.iter_resources((Radio, ), []):
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
yield radio

View file

@ -19,10 +19,12 @@
from weboob.tools.test import BackendTest
from weboob.capabilities.radio import Radio
class OuiFMTest(BackendTest):
BACKEND = 'ouifm'
def test_ouifm(self):
l = list(self.backend.iter_resources([]))
l = list(self.backend.iter_resources((Radio, ), []))
self.assertTrue(len(l) > 0)

View file

@ -102,22 +102,23 @@ class RadioFranceBackend(BaseBackend, ICapRadio, ICapCollection, ICapVideo):
_RSS_RADIOS = ('francemusique', )
_ANTENNA_RADIOS = ('fip', )
def iter_resources(self, split_path):
if len(split_path) == 1 and split_path[0] == 'francebleu':
for _id in sorted(self._RADIOS.iterkeys()):
if _id.startswith('fb'):
yield self.get_radio(_id)
elif len(split_path) == 0:
for _id in sorted(self._RADIOS.iterkeys()):
if not _id.startswith('fb'):
yield self.get_radio(_id)
yield Collection('francebleu', 'France Bleu',
children=self.iter_resources(['francebleu']))
else:
raise CollectionNotFound(split_path)
def iter_resources(self, objs, split_path):
if Radio in objs:
if len(split_path) == 1 and split_path[0] == 'francebleu':
for _id in sorted(self._RADIOS.iterkeys()):
if _id.startswith('fb'):
yield self.get_radio(_id)
elif len(split_path) == 0:
for _id in sorted(self._RADIOS.iterkeys()):
if not _id.startswith('fb'):
yield self.get_radio(_id)
yield Collection('francebleu', 'France Bleu',
children=self.iter_resources(objs, ['francebleu']))
else:
raise CollectionNotFound(split_path)
def iter_radios_search(self, pattern):
for radio in self._flatten_resources(self.iter_resources([])):
for radio in self._flatten_resources(self.iter_resources((Radio, ), [])):
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
yield radio

View file

@ -19,14 +19,20 @@
from weboob.tools.test import BackendTest
from weboob.capabilities.video import BaseVideo
from weboob.capabilities.radio import Radio
class RadioFranceTest(BackendTest):
BACKEND = 'radiofrance'
def test_get_radios(self):
l = list(self.backend.iter_resources([]))
self.assertTrue(len(l) > 0)
l = list(self.backend.iter_resources(objs=[Radio], split_path=[]))
self.assertTrue(0 < len(l) < 30)
l = list(self.backend.iter_resources(objs=[Radio], split_path=['francebleu']))
self.assertTrue(len(l) > 30)
l = list(self.backend.iter_resources(objs=[BaseVideo], split_path=[]))
self.assertEquals(len(l), 0)
def test_get_video(self):
# this should be available up to 24/10/2014 15h00

View file

@ -94,17 +94,18 @@ class RedmineBackend(BaseBackend, ICapContent, ICapBugTracker, ICapCollection):
return self.browser.get_wiki_preview(project, page, content.content)
############# CapCollection ###################################################
def iter_resources(self, split_path):
if len(split_path) == 0:
return [Collection(project.id, project.name, fct=self.iter_issues)
for project in self.iter_projects()]
def iter_resources(self, objs, split_path):
if Project in objs or Issue in objs:
if len(split_path) == 0:
return [Collection(project.id, project.name, fct=self.iter_issues)
for project in self.iter_projects()]
if len(split_path) == 1:
query = Query()
query.project = unicode(split_path[0])
return self.iter_issues(query)
if len(split_path) == 1:
query = Query()
query.project = unicode(split_path[0])
return self.iter_issues(query)
raise CollectionNotFound(split_path)
raise CollectionNotFound(split_path)
############# CapBugTracker ###################################################