default behavior is to unlimit results, except for explicit commands (searches or history)
closes #1139
This commit is contained in:
parent
f1305f0daa
commit
9094294683
17 changed files with 65 additions and 21 deletions
|
|
@ -23,7 +23,7 @@ import sys
|
|||
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.capabilities.bank import ICapBank, Account, Transaction
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
|
||||
|
|
@ -226,6 +226,7 @@ class Boobank(ReplApplication):
|
|||
if len(args) == 2:
|
||||
return self._complete_account()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_history(self, id):
|
||||
"""
|
||||
history ID
|
||||
|
|
@ -246,6 +247,7 @@ class Boobank(ReplApplication):
|
|||
if len(args) == 2:
|
||||
return self._complete_account()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_coming(self, id):
|
||||
"""
|
||||
coming ID
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import sys
|
|||
from decimal import Decimal
|
||||
|
||||
from weboob.capabilities.bill import ICapBill, Detail, Subscription
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import PrettyFormatter
|
||||
|
||||
|
||||
|
|
@ -129,6 +129,7 @@ class Boobill(ReplApplication):
|
|||
|
||||
self.exec_method(id, 'get_balance')
|
||||
|
||||
@defaultcount(10)
|
||||
def do_history(self, id):
|
||||
"""
|
||||
history [Id]
|
||||
|
|
@ -138,6 +139,7 @@ class Boobill(ReplApplication):
|
|||
"""
|
||||
self.exec_method(id, 'iter_bills_history')
|
||||
|
||||
@defaultcount(10)
|
||||
def do_bills(self, id):
|
||||
"""
|
||||
bills [Id]
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import sys
|
|||
|
||||
from weboob.capabilities.lyrics import ICapLyrics
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
|
||||
|
|
@ -97,6 +97,7 @@ class Booblyrics(ReplApplication):
|
|||
if len(args) == 2:
|
||||
return self.SEARCH_CRITERIAS
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, line):
|
||||
"""
|
||||
search [artist | song] [PATTERN]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ from weboob.core import CallErrors
|
|||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.capabilities.account import ICapAccount
|
||||
from weboob.capabilities.contact import ICapContact, Contact
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter
|
||||
from weboob.tools.misc import html2text
|
||||
|
||||
|
|
@ -382,6 +382,7 @@ class Boobmsg(ReplApplication):
|
|||
threads = []
|
||||
messages = []
|
||||
|
||||
@defaultcount(10)
|
||||
def do_list(self, arg):
|
||||
"""
|
||||
list
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from datetime import timedelta
|
|||
import sys
|
||||
|
||||
from weboob.capabilities.bugtracker import ICapBugTracker, Query, Update, Project, Issue
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
from weboob.tools.misc import html2text
|
||||
|
||||
|
|
@ -96,6 +96,7 @@ class BoobTracker(ReplApplication):
|
|||
group.add_option('--category')
|
||||
group.add_option('--status')
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, line):
|
||||
"""
|
||||
search PROJECT
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from weboob.capabilities.torrent import ICapTorrent, MagnetOnly
|
|||
from weboob.capabilities.cinema import ICapCinema
|
||||
from weboob.capabilities.subtitle import ICapSubtitle
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
from weboob.core import CallErrors
|
||||
|
||||
|
|
@ -325,6 +325,7 @@ class Cineoob(ReplApplication):
|
|||
self.format(person)
|
||||
self.flush()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search_movie(self, pattern):
|
||||
"""
|
||||
search_movie [PATTERN]
|
||||
|
|
@ -340,6 +341,7 @@ class Cineoob(ReplApplication):
|
|||
self.cached_format(movie)
|
||||
self.flush()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search_person(self, pattern):
|
||||
"""
|
||||
search_person [PATTERN]
|
||||
|
|
@ -507,6 +509,7 @@ class Cineoob(ReplApplication):
|
|||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
||||
return 3
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search_torrent(self, pattern):
|
||||
"""
|
||||
search_torrent [PATTERN]
|
||||
|
|
@ -522,6 +525,7 @@ class Cineoob(ReplApplication):
|
|||
self.cached_format(torrent)
|
||||
self.flush()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search_movie_torrent(self, id):
|
||||
"""
|
||||
search_movie_torrent movie_ID
|
||||
|
|
@ -609,6 +613,7 @@ class Cineoob(ReplApplication):
|
|||
print >>sys.stderr, 'Subtitle "%s" not found' % id
|
||||
return 3
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search_subtitle(self, line):
|
||||
"""
|
||||
search_subtitle language [PATTERN]
|
||||
|
|
@ -645,6 +650,7 @@ class Cineoob(ReplApplication):
|
|||
self.cached_format(subtitle)
|
||||
self.flush()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search_movie_subtitle(self, line):
|
||||
"""
|
||||
search_movie_subtitle language movie_ID
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import codecs
|
|||
|
||||
from weboob.capabilities.recipe import ICapRecipe
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
|
||||
|
|
@ -148,6 +148,7 @@ class Cookboob(ReplApplication):
|
|||
print >>sys.stderr, 'Recipe "%s" not found' % id
|
||||
return 3
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search [PATTERN]
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
import sys
|
||||
|
||||
from weboob.capabilities.housing import ICapHousing, Query
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
|
||||
|
|
@ -91,6 +91,7 @@ class Flatboob(ReplApplication):
|
|||
self.load_config()
|
||||
return ReplApplication.main(self, argv)
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, line):
|
||||
pattern = 'notempty'
|
||||
query = Query()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import sys
|
|||
import os
|
||||
from re import search, sub
|
||||
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.capabilities.gallery import ICapGallery, BaseGallery, BaseImage
|
||||
from weboob.tools.application.formatters.iformatter import PrettyFormatter
|
||||
|
|
@ -60,6 +60,7 @@ class Galleroob(ReplApplication):
|
|||
def __init__(self, *args, **kwargs):
|
||||
ReplApplication.__init__(self, *args, **kwargs)
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search PATTERN
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
import sys
|
||||
|
||||
from weboob.capabilities.job import ICapJob
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
__all__ = ['Handjoob']
|
||||
|
|
@ -87,6 +87,7 @@ class Handjoob(ReplApplication):
|
|||
'info': 'job_advert',
|
||||
}
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search PATTERN
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import sys
|
|||
|
||||
from weboob.capabilities.radio import ICapRadio, Radio
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.media_player import InvalidMediaPlayer, MediaPlayer, MediaPlayerNotFound
|
||||
from weboob.tools.application.formatters.iformatter import PrettyFormatter
|
||||
|
||||
|
|
@ -119,6 +119,7 @@ class Radioob(ReplApplication):
|
|||
self.format(radio)
|
||||
self.flush()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, pattern=None):
|
||||
"""
|
||||
search PATTERN
|
||||
|
|
@ -140,8 +141,5 @@ class Radioob(ReplApplication):
|
|||
|
||||
List radios
|
||||
"""
|
||||
count = self.options.count
|
||||
self.options.count = None
|
||||
ret = super(Radioob, self).do_ls(line)
|
||||
self.options.count = count
|
||||
return ret
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import sys
|
|||
|
||||
from weboob.capabilities.subtitle import ICapSubtitle
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
|
||||
|
|
@ -164,6 +164,7 @@ class Suboob(ReplApplication):
|
|||
print 'Saved to %s' % dest
|
||||
return
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, line):
|
||||
"""
|
||||
search language [PATTERN]
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from datetime import datetime
|
|||
import logging
|
||||
|
||||
from weboob.capabilities.travel import ICapTravel, RoadmapFilters
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
|
||||
|
||||
__all__ = ['Traveloob']
|
||||
|
|
@ -42,6 +42,7 @@ class Traveloob(ReplApplication):
|
|||
group.add_option('--departure-time')
|
||||
group.add_option('--arrival-time')
|
||||
|
||||
@defaultcount(10)
|
||||
def do_stations(self, pattern):
|
||||
"""
|
||||
stations PATTERN
|
||||
|
|
@ -52,6 +53,7 @@ class Traveloob(ReplApplication):
|
|||
self.format(station)
|
||||
self.flush()
|
||||
|
||||
@defaultcount(10)
|
||||
def do_departures(self, line):
|
||||
"""
|
||||
departures STATION [ARRIVAL]
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import os
|
|||
|
||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||
from weboob.capabilities.base import empty
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.media_player import InvalidMediaPlayer, MediaPlayer, MediaPlayerNotFound
|
||||
from weboob.tools.application.formatters.iformatter import PrettyFormatter
|
||||
|
||||
|
|
@ -204,6 +204,7 @@ class Videoob(ReplApplication):
|
|||
else:
|
||||
print "on" if self.nsfw else "off"
|
||||
|
||||
@defaultcount()
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search PATTERN
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
import sys
|
||||
|
||||
from weboob.capabilities.torrent import ICapTorrent, MagnetOnly
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
from weboob.core import CallErrors
|
||||
from weboob.capabilities.base import NotAvailable
|
||||
|
|
@ -154,6 +154,7 @@ class Weboorrents(ReplApplication):
|
|||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
||||
return 3
|
||||
|
||||
@defaultcount(10)
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search [PATTERN]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
from weboob.capabilities.weather import ICapWeather
|
||||
from weboob.capabilities.gauge import ICapGauge, SensorNotFound
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
from weboob.tools.application.repl import ReplApplication, defaultcount
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
||||
import sys
|
||||
|
|
@ -80,6 +80,7 @@ class WetBoobs(ReplApplication):
|
|||
self.load_config()
|
||||
return ReplApplication.main(self, argv)
|
||||
|
||||
@defaultcount(10)
|
||||
def do_cities(self, pattern):
|
||||
"""
|
||||
cities PATTERN
|
||||
|
|
|
|||
|
|
@ -69,6 +69,24 @@ class ReplOptionFormatter(IndentedHelpFormatter):
|
|||
s += ' %s\n' % c
|
||||
return s
|
||||
|
||||
def defaultcount(default_count=10):
|
||||
def deco(f):
|
||||
def inner(self, *args, **kwargs):
|
||||
oldvalue = self.options.count
|
||||
if self._is_default_count:
|
||||
self.options.count = default_count
|
||||
|
||||
try:
|
||||
return f(self, *args, **kwargs)
|
||||
finally:
|
||||
self.options.count = oldvalue
|
||||
|
||||
inner.__doc__ = f.__doc__
|
||||
assert inner.__doc__ is not None, "A command must have a docstring"
|
||||
inner.__doc__ += '\nDefault is limited to %s results.' % default_count
|
||||
|
||||
return inner
|
||||
return deco
|
||||
|
||||
class ReplApplication(Cmd, ConsoleApplication):
|
||||
"""
|
||||
|
|
@ -116,8 +134,8 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
|
||||
results_options = OptionGroup(self._parser, 'Results Options')
|
||||
results_options.add_option('-c', '--condition', help='filter result items to display given a boolean expression')
|
||||
results_options.add_option('-n', '--count', default='10', type='int',
|
||||
help='get a maximum number of results (all backends merged)')
|
||||
results_options.add_option('-n', '--count', type='int',
|
||||
help='limit number of results (from each backends)')
|
||||
results_options.add_option('-s', '--select', help='select result item keys to display (comma separated)')
|
||||
self._parser.add_option_group(results_options)
|
||||
|
||||
|
|
@ -131,6 +149,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
self._parser.add_option_group(formatting_options)
|
||||
|
||||
self._interactive = False
|
||||
self._is_default_count = True
|
||||
self.working_path = WorkingPath()
|
||||
self._change_prompt()
|
||||
|
||||
|
|
@ -458,6 +477,8 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
else:
|
||||
self.condition = None
|
||||
|
||||
if self.options.count is not None:
|
||||
self._is_default_count = False
|
||||
if self.options.count <= 0:
|
||||
# infinite search
|
||||
self.options.count = None
|
||||
|
|
@ -759,6 +780,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
if line:
|
||||
if line == 'off':
|
||||
self.options.count = None
|
||||
self._is_default_count = False
|
||||
else:
|
||||
try:
|
||||
count = int(line)
|
||||
|
|
@ -768,6 +790,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
else:
|
||||
if count > 0:
|
||||
self.options.count = count
|
||||
self._is_default_count = False
|
||||
else:
|
||||
print >>sys.stderr, 'Number must be at least 1.'
|
||||
return 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue