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