-b is handled by BaseApplication
This commit is contained in:
parent
27be2bdb25
commit
aee0e49cc8
5 changed files with 40 additions and 35 deletions
|
|
@ -57,7 +57,7 @@ class DefaultOptions():
|
||||||
|
|
||||||
class MyPlayer():
|
class MyPlayer():
|
||||||
"""Black magic invoking a video player to this world.
|
"""Black magic invoking a video player to this world.
|
||||||
|
|
||||||
Presently, due to strong disturbances in the holidays of the ether
|
Presently, due to strong disturbances in the holidays of the ether
|
||||||
world, the video player used is chosen from a static list of
|
world, the video player used is chosen from a static list of
|
||||||
programs. See PLAYERS for more information.
|
programs. See PLAYERS for more information.
|
||||||
|
|
@ -82,11 +82,11 @@ class MyPlayer():
|
||||||
if self.options.verbose:
|
if self.options.verbose:
|
||||||
print "Video player is (%s,%s)" % (self.player,
|
print "Video player is (%s,%s)" % (self.player,
|
||||||
self.player_stdin)
|
self.player_stdin)
|
||||||
|
|
||||||
|
|
||||||
def play(self, video):
|
def play(self, video):
|
||||||
"""Play a video object, using programs from the PLAYERS list.
|
"""Play a video object, using programs from the PLAYERS list.
|
||||||
|
|
||||||
This function dispatch calls to either _play_default or
|
This function dispatch calls to either _play_default or
|
||||||
_play_rtmp for special rtmp streams using SWF verification.
|
_play_rtmp for special rtmp streams using SWF verification.
|
||||||
"""
|
"""
|
||||||
|
|
@ -289,7 +289,7 @@ class MyCmd(Cmd):
|
||||||
|
|
||||||
def do_search(self, pattern):
|
def do_search(self, pattern):
|
||||||
"""search [PATTERN]
|
"""search [PATTERN]
|
||||||
|
|
||||||
Search for videos.
|
Search for videos.
|
||||||
If no patterns are given, display the last entries.
|
If no patterns are given, display the last entries.
|
||||||
"""
|
"""
|
||||||
|
|
@ -307,7 +307,7 @@ class MyCmd(Cmd):
|
||||||
for i, (backend, video) in enumerate(videos_g):
|
for i, (backend, video) in enumerate(videos_g):
|
||||||
self.videos.append((backend,video))
|
self.videos.append((backend,video))
|
||||||
|
|
||||||
|
|
||||||
# code factorisatorminator: display the list of videos
|
# code factorisatorminator: display the list of videos
|
||||||
self.do_ls("")
|
self.do_ls("")
|
||||||
|
|
||||||
|
|
@ -334,8 +334,8 @@ class MyCmd(Cmd):
|
||||||
print_keys_values([
|
print_keys_values([
|
||||||
("url", video.url),
|
("url", video.url),
|
||||||
("duration", "%s seconds" % video.duration),
|
("duration", "%s seconds" % video.duration),
|
||||||
("rating", "%.2f/%.2f" % (video.rating,
|
("rating", "%.2f/%.2f" % (video.rating or 0,
|
||||||
video.rating_max))],
|
video.rating_max or 0))],
|
||||||
indent=4)
|
indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ class WeboobCfg(ReplApplication):
|
||||||
VERSION = '0.1'
|
VERSION = '0.1'
|
||||||
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz, Romain Bignon'
|
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz, Romain Bignon'
|
||||||
|
|
||||||
|
def load_default_backends(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def caps_included(self, modcaps, caps):
|
def caps_included(self, modcaps, caps):
|
||||||
modcaps = [x.__name__ for x in modcaps]
|
modcaps = [x.__name__ for x in modcaps]
|
||||||
for cap in caps:
|
for cap in caps:
|
||||||
|
|
@ -56,7 +59,7 @@ class WeboobCfg(ReplApplication):
|
||||||
self.weboob.modules_loader.load_all()
|
self.weboob.modules_loader.load_all()
|
||||||
if name not in [_name for _name, backend in self.weboob.modules_loader.loaded.iteritems()]:
|
if name not in [_name for _name, backend in self.weboob.modules_loader.loaded.iteritems()]:
|
||||||
logging.error(u'Backend "%s" does not exist.' % name)
|
logging.error(u'Backend "%s" does not exist.' % name)
|
||||||
return 1
|
return
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
# set backend params from command-line arguments
|
# set backend params from command-line arguments
|
||||||
|
|
@ -65,7 +68,7 @@ class WeboobCfg(ReplApplication):
|
||||||
key, value = option.split('=', 1)
|
key, value = option.split('=', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logging.error(u'Parameters have to be formatted "key=value"')
|
logging.error(u'Parameters have to be formatted "key=value"')
|
||||||
return 1
|
return
|
||||||
params[key] = value
|
params[key] = value
|
||||||
# ask for params non-specified on command-line arguments
|
# ask for params non-specified on command-line arguments
|
||||||
backend = self.weboob.modules_loader.get_or_load_module(name)
|
backend = self.weboob.modules_loader.get_or_load_module(name)
|
||||||
|
|
@ -108,7 +111,7 @@ class WeboobCfg(ReplApplication):
|
||||||
except ConfigParser.DuplicateSectionError:
|
except ConfigParser.DuplicateSectionError:
|
||||||
print 'Instance "%s" already exists for backend "%s".' % (new_name, name)
|
print 'Instance "%s" already exists for backend "%s".' % (new_name, name)
|
||||||
|
|
||||||
def do_listconfigured(self):
|
def do_list(self, line):
|
||||||
"""
|
"""
|
||||||
list
|
list
|
||||||
|
|
||||||
|
|
@ -118,10 +121,11 @@ class WeboobCfg(ReplApplication):
|
||||||
for instance_name, name, params in sorted(self.weboob.backends_config.iter_backends()):
|
for instance_name, name, params in sorted(self.weboob.backends_config.iter_backends()):
|
||||||
backend = self.weboob.modules_loader.get_or_load_module(name)
|
backend = self.weboob.modules_loader.get_or_load_module(name)
|
||||||
row = OrderedDict([('Instance name', instance_name),
|
row = OrderedDict([('Instance name', instance_name),
|
||||||
('Backend name', name),
|
('Backend', name),
|
||||||
('Configuration', ', '.join('%s=%s' % (key, ('*****' if key in backend.config and backend.config[key].is_masked else value)) for key, value in params.iteritems())),
|
('Configuration', ', '.join('%s=%s' % (key, ('*****' if key in backend.config and backend.config[key].is_masked else value)) for key, value in params.iteritems())),
|
||||||
])
|
])
|
||||||
self.format(row)
|
self.format(row)
|
||||||
|
self.flush()
|
||||||
|
|
||||||
def do_remove(self, instance_name):
|
def do_remove(self, instance_name):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ class BaseApplication(object):
|
||||||
def __init__(self, option_parser=None):
|
def __init__(self, option_parser=None):
|
||||||
self.weboob = self.create_weboob()
|
self.weboob = self.create_weboob()
|
||||||
self.config = None
|
self.config = None
|
||||||
|
self.options = None
|
||||||
if option_parser is None:
|
if option_parser is None:
|
||||||
self._parser = OptionParser(self.SYNOPSIS, version=self._get_optparse_version())
|
self._parser = OptionParser(self.SYNOPSIS, version=self._get_optparse_version())
|
||||||
else:
|
else:
|
||||||
|
|
@ -199,6 +200,8 @@ class BaseApplication(object):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def load_backends(self, caps=None, names=None, *args, **kwargs):
|
def load_backends(self, caps=None, names=None, *args, **kwargs):
|
||||||
|
if names is None and self.options.backends:
|
||||||
|
names = self.options.backends.split(',')
|
||||||
loaded = self.weboob.load_backends(caps, names, *args, **kwargs)
|
loaded = self.weboob.load_backends(caps, names, *args, **kwargs)
|
||||||
if not loaded:
|
if not loaded:
|
||||||
logging.warning(u'No backend loaded')
|
logging.warning(u'No backend loaded')
|
||||||
|
|
@ -248,6 +251,14 @@ class BaseApplication(object):
|
||||||
else:
|
else:
|
||||||
return self._do_complete_obj(backend, fields, res)
|
return self._do_complete_obj(backend, fields, res)
|
||||||
|
|
||||||
|
def parse_args(self, args):
|
||||||
|
self.options, args = self._parser.parse_args(args)
|
||||||
|
|
||||||
|
self._handle_options()
|
||||||
|
self.handle_application_options()
|
||||||
|
|
||||||
|
return args
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(klass, args=None):
|
def run(klass, args=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -267,9 +278,7 @@ class BaseApplication(object):
|
||||||
if args is None:
|
if args is None:
|
||||||
args = [(sys.stdin.encoding and arg.decode(sys.stdin.encoding) or arg) for arg in sys.argv]
|
args = [(sys.stdin.encoding and arg.decode(sys.stdin.encoding) or arg) for arg in sys.argv]
|
||||||
app = klass()
|
app = klass()
|
||||||
app.options, args = app._parser.parse_args(args)
|
args = app.parse_args(args)
|
||||||
|
|
||||||
app.set_requested_backends(app.options.backends.split(',') if app.options.backends else None)
|
|
||||||
|
|
||||||
if app.options.shell_completion:
|
if app.options.shell_completion:
|
||||||
items = set()
|
items = set()
|
||||||
|
|
@ -292,9 +301,6 @@ class BaseApplication(object):
|
||||||
logging.basicConfig(stream=sys.stdout, level=level, format=log_format)
|
logging.basicConfig(stream=sys.stdout, level=level, format=log_format)
|
||||||
logging.root.level = level
|
logging.root.level = level
|
||||||
|
|
||||||
app._handle_options()
|
|
||||||
app.handle_application_options()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
sys.exit(app.main(args))
|
sys.exit(app.main(args))
|
||||||
|
|
@ -306,6 +312,3 @@ class BaseApplication(object):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
app.deinit()
|
app.deinit()
|
||||||
|
|
||||||
def set_requested_backends(self, requested_backends):
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ class ConsoleApplication(BaseApplication):
|
||||||
SYNOPSIS += ' %prog [--help] [--version]'
|
SYNOPSIS += ' %prog [--help] [--version]'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.enabled_backends = set()
|
|
||||||
option_parser = OptionParser(self.SYNOPSIS, version=self._get_optparse_version())
|
option_parser = OptionParser(self.SYNOPSIS, version=self._get_optparse_version())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -271,8 +270,6 @@ class ConsoleApplication(BaseApplication):
|
||||||
command = staticmethod(command)
|
command = staticmethod(command)
|
||||||
|
|
||||||
def load_backends(self, caps=None, names=None, *args, **kwargs):
|
def load_backends(self, caps=None, names=None, *args, **kwargs):
|
||||||
if names is None:
|
|
||||||
names = self.enabled_backends
|
|
||||||
loaded_backends = BaseApplication.load_backends(self, caps, names, *args, **kwargs)
|
loaded_backends = BaseApplication.load_backends(self, caps, names, *args, **kwargs)
|
||||||
if not loaded_backends:
|
if not loaded_backends:
|
||||||
print 'Cannot start application: no configured backend was found.'
|
print 'Cannot start application: no configured backend was found.'
|
||||||
|
|
@ -314,9 +311,6 @@ class ConsoleApplication(BaseApplication):
|
||||||
except BackendNotFound, e:
|
except BackendNotFound, e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
|
|
||||||
def set_requested_backends(self, requested_backends):
|
|
||||||
self.enabled_backends = requested_backends
|
|
||||||
|
|
||||||
def do(self, function, *args, **kwargs):
|
def do(self, function, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Call Weboob.do(), after having filled the yielded object, if selected fields are given by user.
|
Call Weboob.do(), after having filled the yielded object, if selected fields are given by user.
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
import readline
|
import readline
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
finally:
|
else:
|
||||||
history_filepath = os.path.join(self.weboob.WORKDIR, '%s_history' % self.APPNAME)
|
history_filepath = os.path.join(self.weboob.WORKDIR, '%s_history' % self.APPNAME)
|
||||||
try:
|
try:
|
||||||
readline.read_history_file(history_filepath)
|
readline.read_history_file(history_filepath)
|
||||||
|
|
@ -118,18 +118,16 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
atexit.register(savehist)
|
atexit.register(savehist)
|
||||||
|
|
||||||
self._interactive = False
|
self._interactive = False
|
||||||
|
self.enabled_backends = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def interactive(self):
|
def interactive(self):
|
||||||
return self._interactive
|
return self._interactive
|
||||||
|
|
||||||
def set_requested_backends(self, requested_backends):
|
def load_backends(self, *args, **kwargs):
|
||||||
self.load_default_backends()
|
ret = super(ReplApplication, self).load_backends(*args, **kwargs)
|
||||||
if requested_backends:
|
self.enabled_backends = list(self.weboob.iter_backends())
|
||||||
self.enabled_backends = set(backend for backend in self.weboob.iter_backends()
|
return ret
|
||||||
if backend.name in requested_backends)
|
|
||||||
else:
|
|
||||||
self.enabled_backends = list(self.weboob.iter_backends())
|
|
||||||
|
|
||||||
def load_default_backends(self):
|
def load_default_backends(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -168,8 +166,12 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
raise
|
raise
|
||||||
except NotEnoughArguments, e:
|
except NotEnoughArguments, e:
|
||||||
print >>sys.stderr, 'Error: no enough arguments.'
|
print >>sys.stderr, 'Error: no enough arguments.'
|
||||||
|
except (KeyboardInterrupt,EOFError):
|
||||||
|
# ^C during a command process doesn't exit application.
|
||||||
|
print '\nAborted.'
|
||||||
|
|
||||||
def main(self, argv):
|
def main(self, argv):
|
||||||
|
self.load_default_backends()
|
||||||
cmd_args = argv[1:]
|
cmd_args = argv[1:]
|
||||||
if cmd_args:
|
if cmd_args:
|
||||||
if cmd_args[0] == 'help':
|
if cmd_args[0] == 'help':
|
||||||
|
|
@ -197,6 +199,8 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
# XXX IT ABSOLUTLY DOESN'T WORK, OBJ ISN'T EXISTANT.
|
# XXX IT ABSOLUTLY DOESN'T WORK, OBJ ISN'T EXISTANT.
|
||||||
# PLEASE REVIEW THIS CODE.
|
# PLEASE REVIEW THIS CODE.
|
||||||
#fields = [k for k, v in iter_fields(obj)]
|
#fields = [k for k, v in iter_fields(obj)]
|
||||||
|
# TODO Perhaps this is the core goal to determine what fields to use,
|
||||||
|
# by creating a singleton AllFields.
|
||||||
fields = None
|
fields = None
|
||||||
return self.weboob.do(self._do_complete, self.options.count, fields, function, *args, **kwargs)
|
return self.weboob.do(self._do_complete, self.options.count, fields, function, *args, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue