Add object type filtering to iter_resources
This commit is contained in:
parent
63da39e005
commit
bfb3689456
16 changed files with 92 additions and 61 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import sys
|
||||
|
||||
from weboob.capabilities.bank import ICapBank
|
||||
from weboob.capabilities.bank import ICapBank, Account, Operation
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter
|
||||
|
||||
|
|
@ -142,6 +142,7 @@ class Boobank(ReplApplication):
|
|||
'list': 'account_list',
|
||||
'transfer': 'transfer',
|
||||
}
|
||||
COLLECTION_OBJECTS = (Account, Operation, )
|
||||
|
||||
def _complete_account(self, exclude=None):
|
||||
if exclude:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
from datetime import timedelta
|
||||
import sys
|
||||
|
||||
from weboob.capabilities.bugtracker import ICapBugTracker, Query, Update
|
||||
from weboob.capabilities.bugtracker import ICapBugTracker, Query, Update, Project, Issue
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter
|
||||
from weboob.tools.misc import html2text
|
||||
|
|
@ -93,6 +93,7 @@ class BoobTracker(ReplApplication):
|
|||
'search': 'issues_list',
|
||||
'ls': 'issues_list',
|
||||
}
|
||||
COLLECTION_OBJECTS = (Project, Issue, )
|
||||
|
||||
def add_application_options(self, group):
|
||||
group.add_option('--author')
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import sys
|
||||
|
||||
from weboob.capabilities.radio import ICapRadio
|
||||
from weboob.capabilities.radio import ICapRadio, Radio
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.media_player import InvalidMediaPlayer, MediaPlayer, MediaPlayerNotFound
|
||||
|
|
@ -66,6 +66,7 @@ class Radioob(ReplApplication):
|
|||
COMMANDS_FORMATTERS = {'ls': 'radio_list',
|
||||
'search': 'radio_list',
|
||||
}
|
||||
COLLECTION_OBJECTS = (Radio, )
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
ReplApplication.__init__(self, *args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import subprocess
|
|||
import sys
|
||||
import os
|
||||
|
||||
from weboob.capabilities.video import ICapVideo
|
||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.media_player import InvalidMediaPlayer, MediaPlayer, MediaPlayerNotFound
|
||||
|
|
@ -66,6 +66,7 @@ class Videoob(ReplApplication):
|
|||
EXTRA_FORMATTERS = {'video_list': VideoListFormatter}
|
||||
COMMANDS_FORMATTERS = {'search': 'video_list',
|
||||
'ls': 'video_list'}
|
||||
COLLECTION_OBJECTS = (BaseVideo, )
|
||||
|
||||
nsfw = True
|
||||
|
||||
|
|
|
|||
|
|
@ -74,11 +74,12 @@ class Transfer(CapBaseObject):
|
|||
self.add_field('recipient', (int, long, basestring))
|
||||
|
||||
class ICapBank(ICapCollection):
|
||||
def iter_resources(self, split_path):
|
||||
if len(split_path) > 0:
|
||||
raise CollectionNotFound(split_path)
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Account in objs:
|
||||
if len(split_path) > 0:
|
||||
raise CollectionNotFound(split_path)
|
||||
|
||||
return self.iter_accounts()
|
||||
return self.iter_accounts()
|
||||
|
||||
def iter_accounts(self):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ class ICapCollection(IBaseCap):
|
|||
lst.append(resource)
|
||||
return lst
|
||||
|
||||
def iter_resources(self, split_path):
|
||||
def iter_resources(self, objs, split_path):
|
||||
"""
|
||||
split_path is a list, either empty (root path) or with one or many
|
||||
components.
|
||||
|
|
|
|||
|
|
@ -80,6 +80,9 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
DEFAULT_FORMATTER = 'multiline'
|
||||
COMMANDS_FORMATTERS = {}
|
||||
|
||||
# Objects to allow in do_ls / do_cd
|
||||
COLLECTION_OBJECTS = tuple()
|
||||
|
||||
weboob_commands = set(['backends', 'condition', 'count', 'formatter', 'inspect', 'logging', 'select', 'quit', 'ls', 'cd'])
|
||||
hidden_commands = set(['EOF'])
|
||||
|
||||
|
|
@ -849,7 +852,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
|
||||
List objects in current path.
|
||||
"""
|
||||
self.objects = self._fetch_objects()
|
||||
self.objects = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
||||
|
||||
for obj in self.objects:
|
||||
if isinstance(obj, CapBaseObject):
|
||||
|
|
@ -879,21 +882,22 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
else:
|
||||
self.working_path.extend(line)
|
||||
|
||||
objects = self._fetch_objects()
|
||||
objects = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
||||
if len(objects) == 0:
|
||||
print >>sys.stderr, "Path: %s not found" % self.working_path.tostring()
|
||||
self.working_path.restore()
|
||||
return 1
|
||||
|
||||
self.objects = objects
|
||||
self._change_prompt()
|
||||
|
||||
def _fetch_objects(self):
|
||||
def _fetch_objects(self, objs):
|
||||
objects = []
|
||||
path = self.working_path.get()
|
||||
split_path = self.working_path.get()
|
||||
|
||||
try:
|
||||
for backend, res in self.do('iter_resources', path, caps=ICapCollection):
|
||||
for backend, res in self.do('iter_resources',
|
||||
objs=objs, split_path=split_path,
|
||||
caps=ICapCollection):
|
||||
objects.append(res)
|
||||
except CallErrors, errors:
|
||||
for backend, error, backtrace in errors.errors:
|
||||
|
|
@ -910,7 +914,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
offs = len(mline) - len(text)
|
||||
|
||||
if len(self.objects) == 0:
|
||||
self.objects = self._fetch_objects()
|
||||
self.objects = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
||||
|
||||
for obj in self.objects:
|
||||
if isinstance(obj, Collection):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue