Move condition code in BaseApplication
The count parameter is now consistent with condition parameter close #1289
This commit is contained in:
parent
f7c4e4c89b
commit
a3e6e98b4e
2 changed files with 10 additions and 11 deletions
|
|
@ -34,13 +34,13 @@ from weboob.tools.config.iconfig import ConfigError
|
||||||
from weboob.tools.log import createColoredFormatter, getLogger
|
from weboob.tools.log import createColoredFormatter, getLogger
|
||||||
from weboob.tools.misc import to_unicode
|
from weboob.tools.misc import to_unicode
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['BaseApplication']
|
__all__ = ['BaseApplication']
|
||||||
|
|
||||||
|
|
||||||
class MoreResultsAvailable(Exception):
|
class MoreResultsAvailable(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ApplicationStorage(object):
|
class ApplicationStorage(object):
|
||||||
def __init__(self, name, storage):
|
def __init__(self, name, storage):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
@ -88,7 +88,7 @@ class BaseApplication(object):
|
||||||
# Default storage tree
|
# Default storage tree
|
||||||
STORAGE = {}
|
STORAGE = {}
|
||||||
# Synopsis
|
# Synopsis
|
||||||
SYNOPSIS = 'Usage: %prog [-h] [-dqv] [-b backends] ...\n'
|
SYNOPSIS = 'Usage: %prog [-h] [-dqv] [-b backends] ...\n'
|
||||||
SYNOPSIS += ' %prog [--help] [--version]'
|
SYNOPSIS += ' %prog [--help] [--version]'
|
||||||
# Description
|
# Description
|
||||||
DESCRIPTION = None
|
DESCRIPTION = None
|
||||||
|
|
@ -249,11 +249,15 @@ class BaseApplication(object):
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _do_complete_iter(self, backend, count, fields, res):
|
def _do_complete_iter(self, backend, count, fields, res):
|
||||||
|
modif = 0
|
||||||
for i, sub in enumerate(res):
|
for i, sub in enumerate(res):
|
||||||
if count and i == count:
|
if self.condition and not self.condition.is_valid(sub):
|
||||||
raise MoreResultsAvailable()
|
modif += 1
|
||||||
sub = self._do_complete_obj(backend, fields, sub)
|
else:
|
||||||
yield sub
|
if count and i - modif == count:
|
||||||
|
raise MoreResultsAvailable()
|
||||||
|
sub = self._do_complete_obj(backend, fields, sub)
|
||||||
|
yield sub
|
||||||
|
|
||||||
def _do_complete(self, backend, count, selected_fields, function, *args, **kwargs):
|
def _do_complete(self, backend, count, selected_fields, function, *args, **kwargs):
|
||||||
assert count is None or count > 0
|
assert count is None or count > 0
|
||||||
|
|
|
||||||
|
|
@ -480,11 +480,6 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
|
|
||||||
if self.options.condition:
|
if self.options.condition:
|
||||||
self.condition = ResultsCondition(self.options.condition)
|
self.condition = ResultsCondition(self.options.condition)
|
||||||
# Enable infinite search by default is condition is set
|
|
||||||
# (count applies on the non-filtered result, and can be confusing for users)
|
|
||||||
if self._is_default_count:
|
|
||||||
self.options.count = None
|
|
||||||
self._is_default_count = False
|
|
||||||
else:
|
else:
|
||||||
self.condition = None
|
self.condition = None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue