new attributes and code improvement
This commit is contained in:
parent
758281effb
commit
ccf4303cc0
11 changed files with 71 additions and 34 deletions
|
|
@ -35,6 +35,8 @@ from weboob.tools.misc import html2text
|
|||
|
||||
class Monboob(ConsoleApplication):
|
||||
APPNAME = 'monboob'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
CONFIG = {'interval': 15,
|
||||
'domain': 'weboob.example.org',
|
||||
'recipient': 'weboob@example.org',
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ __all__ = ['Boobank']
|
|||
|
||||
class Boobank(ConsoleApplication):
|
||||
APPNAME = 'boobank'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
|
||||
def main(self, argv):
|
||||
self.load_backends(ICapBank, names=self.enabled_backends)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ from weboob.capabilities.dating import ICapDating
|
|||
|
||||
class HaveSex(PromptApplication):
|
||||
APPNAME = 'havesex'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
STORAGE_FILENAME = 'dating.storage'
|
||||
|
||||
def main(self, argv):
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ from .main_window import MainWindow
|
|||
|
||||
class QVideoob(QtApplication):
|
||||
APPNAME = 'qvideoob'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
CONFIG = {'settings': {'nsfw': True,
|
||||
'sortby': 0,
|
||||
'backend': ''
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ from weboob.tools.application import ConsoleApplication
|
|||
|
||||
class Travel(ConsoleApplication):
|
||||
APPNAME = 'travel'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
|
||||
def main(self, argv):
|
||||
self.load_modules(ICapTravel)
|
||||
|
|
|
|||
|
|
@ -156,6 +156,8 @@ class TransilienUI():
|
|||
class Travel(BaseApplication):
|
||||
"Application Class"
|
||||
APPNAME = 'travel'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Julien Hébert'
|
||||
|
||||
def main(self, argv):
|
||||
"main fonction"
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ from weboob.tools.application import ConsoleApplication
|
|||
|
||||
class Videoob(ConsoleApplication):
|
||||
APPNAME = 'videoob'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz, Romain Bignon'
|
||||
CONFIG = {}
|
||||
|
||||
def main(self, argv):
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ from weboob.tools.application import ConsoleApplication
|
|||
|
||||
class WeboobCfg(ConsoleApplication):
|
||||
APPNAME = 'weboobcfg'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
|
||||
def main(self, argv):
|
||||
return self.process_command(*argv[1:])
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ from weboob.tools.application import ConsoleApplication
|
|||
|
||||
class WetBoobs(ConsoleApplication):
|
||||
APPNAME = 'wetboobs'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
|
||||
def main(self, argv):
|
||||
self.load_modules(ICapWeather)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ class BaseApplication(object):
|
|||
CONFIG = {}
|
||||
# Configuration directory
|
||||
CONFDIR = os.path.join(os.path.expanduser('~'), '.weboob')
|
||||
# Synopsis
|
||||
SYNOPSIS = 'Usage: %prog [options (-h for help)] ...'
|
||||
# Version
|
||||
VERSION = None
|
||||
# Copyright
|
||||
COPYRIGHT = None
|
||||
|
||||
def __init__(self):
|
||||
self.weboob = self.create_weboob()
|
||||
|
|
@ -119,7 +125,13 @@ class BaseApplication(object):
|
|||
@classmethod
|
||||
def run(klass):
|
||||
app = klass()
|
||||
parser = OptionParser('Usage: %prog [options (-h for help)] URL...')
|
||||
version = None
|
||||
if app.VERSION:
|
||||
if app.COPYRIGHT:
|
||||
version = '%s v%s (%s)' % (app.APPNAME, app.VERSION, app.COPYRIGHT)
|
||||
else:
|
||||
version = '%s v%s' % (app.APPNAME, app.VERSION)
|
||||
parser = OptionParser(app.SYNOPSIS, version=version)
|
||||
parser.add_option('-b', '--backends', help='what backend(s) to enable (comma separated)')
|
||||
parser.add_option('-d', '--debug', action='store_true', help='display debug messages')
|
||||
parser.add_option('-q', '--quiet', action='store_true', help='display only error messages')
|
||||
|
|
|
|||
|
|
@ -87,12 +87,14 @@ class TextFormatter(object):
|
|||
return unicode(formatted).strip()
|
||||
|
||||
|
||||
formatters = dict(text=TextFormatter,
|
||||
table=TableFormatter,
|
||||
)
|
||||
formatters = {'text': TextFormatter,
|
||||
'table': TableFormatter,
|
||||
}
|
||||
|
||||
|
||||
class ConsoleApplication(BaseApplication):
|
||||
SYNOPSIS = 'Usage: %prog [options (-h for help)] command [parameters...]'
|
||||
|
||||
def __init__(self):
|
||||
try:
|
||||
BaseApplication.__init__(self)
|
||||
|
|
@ -149,40 +151,45 @@ class ConsoleApplication(BaseApplication):
|
|||
|
||||
if len(matching_commands) == 0:
|
||||
sys.stderr.write("No such command: %s.\n" % command)
|
||||
elif len(matching_commands) == 1:
|
||||
func = getattr(self, matching_commands[0])
|
||||
|
||||
_args, varargs, varkw, defaults = getargspec(func)
|
||||
nb_max_args = nb_min_args = len(_args) - 1
|
||||
if defaults:
|
||||
nb_min_args -= len(defaults)
|
||||
|
||||
if len(args) < nb_min_args or len(args) > nb_max_args and not varargs:
|
||||
if varargs or defaults:
|
||||
sys.stderr.write("Command '%s' takes at least %d arguments.\n" % (command, nb_min_args))
|
||||
else:
|
||||
sys.stderr.write("Command '%s' takes %d arguments.\n" % (command, nb_min_args))
|
||||
return
|
||||
command_result = func(*args)
|
||||
if isinstance(command_result, dict):
|
||||
if self.options.output_format is not None:
|
||||
output_format = self.options.output_format
|
||||
else:
|
||||
if self.default_output_format is not None:
|
||||
output_format = self.default_output_format
|
||||
else:
|
||||
output_format = 'table'
|
||||
print formatters[output_format].format(command_result)
|
||||
return 0
|
||||
elif isinstance(command_result, int):
|
||||
return command_result
|
||||
elif command_result is None:
|
||||
return 0
|
||||
else:
|
||||
raise Exception('Should never go here')
|
||||
else:
|
||||
return 1
|
||||
if len(matching_commands) != 1:
|
||||
sys.stderr.write("Ambiguious command %s: %s.\n" % (command, ', '.join(
|
||||
[s.replace('command_', '', 1) for s in matching_commands])))
|
||||
return 1
|
||||
|
||||
func = getattr(self, matching_commands[0])
|
||||
|
||||
_args, varargs, varkw, defaults = getargspec(func)
|
||||
nb_max_args = nb_min_args = len(_args) - 1
|
||||
if defaults:
|
||||
nb_min_args -= len(defaults)
|
||||
|
||||
if len(args) < nb_min_args or len(args) > nb_max_args and not varargs:
|
||||
if varargs or defaults:
|
||||
sys.stderr.write("Command '%s' takes at least %d arguments.\n" % (command, nb_min_args))
|
||||
else:
|
||||
sys.stderr.write("Command '%s' takes %d arguments.\n" % (command, nb_min_args))
|
||||
return 1
|
||||
|
||||
command_result = func(*args)
|
||||
|
||||
# Process result
|
||||
if isinstance(command_result, dict):
|
||||
if self.options.output_format is not None:
|
||||
output_format = self.options.output_format
|
||||
else:
|
||||
if self.default_output_format is not None:
|
||||
output_format = self.default_output_format
|
||||
else:
|
||||
output_format = 'table'
|
||||
print formatters[output_format].format(command_result)
|
||||
return 0
|
||||
elif isinstance(command_result, int):
|
||||
return command_result
|
||||
elif command_result is None:
|
||||
return 0
|
||||
else:
|
||||
raise Exception('Should never go here')
|
||||
|
||||
_command_help = []
|
||||
def register_command(f, doc_string, register_to=_command_help):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue