Merge branch 'master' of git://git.symlink.me/pub/romain/weboob
This commit is contained in:
commit
69bdb100c4
4 changed files with 38 additions and 46 deletions
|
|
@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from smtplib import SMTP
|
from smtplib import SMTP
|
||||||
from email.Header import Header
|
from email.Header import Header, decode_header
|
||||||
from email.Utils import parseaddr, formataddr
|
from email.Utils import parseaddr, formataddr
|
||||||
from email import message_from_file
|
from email import message_from_file
|
||||||
import time
|
import time
|
||||||
|
|
@ -61,6 +61,14 @@ class Monboob(ConsoleApplication):
|
||||||
if m:
|
if m:
|
||||||
reply_to = m.group(1)
|
reply_to = m.group(1)
|
||||||
title = msg.get('Subject')
|
title = msg.get('Subject')
|
||||||
|
if title:
|
||||||
|
new_title = u''
|
||||||
|
for part in decode_header(title):
|
||||||
|
if part[1]:
|
||||||
|
new_title += unicode(part[0], part[1])
|
||||||
|
else:
|
||||||
|
new_title += unicode(part[0])
|
||||||
|
title = new_title
|
||||||
|
|
||||||
content = u''
|
content = u''
|
||||||
for part in msg.walk():
|
for part in msg.walk():
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class Boobank(ConsoleApplication):
|
||||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
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)
|
||||||
return self.process_command(*argv[1:])
|
return self.process_command(*argv[1:])
|
||||||
|
|
||||||
@ConsoleApplication.command('List every available accounts')
|
@ConsoleApplication.command('List every available accounts')
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
import logging
|
import logging
|
||||||
from optparse import OptionParser
|
from optparse import OptionGroup, OptionParser
|
||||||
|
|
||||||
from weboob import Weboob
|
from weboob import Weboob
|
||||||
from weboob.tools.config.iconfig import ConfigError
|
from weboob.tools.config.iconfig import ConfigError
|
||||||
|
|
@ -46,6 +46,19 @@ class BaseApplication(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.weboob = self.create_weboob()
|
self.weboob = self.create_weboob()
|
||||||
self.config = None
|
self.config = None
|
||||||
|
version = None
|
||||||
|
if self.VERSION:
|
||||||
|
if self.COPYRIGHT:
|
||||||
|
version = '%s v%s (%s)' % (self.APPNAME, self.VERSION, self.COPYRIGHT)
|
||||||
|
else:
|
||||||
|
version = '%s v%s' % (self.APPNAME, self.VERSION)
|
||||||
|
self._parser = OptionParser(self.SYNOPSIS, version=version)
|
||||||
|
self._parser.add_option('-b', '--backends', help='what backend(s) to enable (comma separated)')
|
||||||
|
logging_options = OptionGroup(self._parser, 'Logging Options')
|
||||||
|
logging_options.add_option('-d', '--debug', action='store_true', help='display debug messages')
|
||||||
|
logging_options.add_option('-q', '--quiet', action='store_true', help='display only error messages')
|
||||||
|
logging_options.add_option('-v', '--verbose', action='store_true', help='display info messages')
|
||||||
|
self._parser.add_option_group(logging_options)
|
||||||
|
|
||||||
def create_weboob(self):
|
def create_weboob(self):
|
||||||
return Weboob(self.APPNAME)
|
return Weboob(self.APPNAME)
|
||||||
|
|
@ -99,19 +112,6 @@ class BaseApplication(object):
|
||||||
""" Main function """
|
""" Main function """
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def configure_parser(self, parser):
|
|
||||||
"""
|
|
||||||
Frontend parser configuration.
|
|
||||||
Overload this method to add custom options for your parser.
|
|
||||||
Options will be available in the BaseApplication.options variable.
|
|
||||||
|
|
||||||
@param parser [OptionParser] the parser object.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _configure_parser(self, parser):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def load_backends(self, caps=None, names=None, *args, **kwargs):
|
def load_backends(self, caps=None, names=None, *args, **kwargs):
|
||||||
if names is None:
|
if names is None:
|
||||||
names = self._enabled_backends
|
names = self._enabled_backends
|
||||||
|
|
@ -123,22 +123,9 @@ class BaseApplication(object):
|
||||||
self.weboob.load_modules(caps, names, *args, **kwargs)
|
self.weboob.load_modules(caps, names, *args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(klass):
|
def run(klass, args=sys.argv):
|
||||||
app = klass()
|
app = klass()
|
||||||
version = None
|
app.options, args = app._parser.parse_args(args)
|
||||||
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')
|
|
||||||
parser.add_option('-v', '--verbose', action='store_true', help='display info messages')
|
|
||||||
app._configure_parser(parser)
|
|
||||||
app.configure_parser(parser)
|
|
||||||
app.options, args = parser.parse_args(sys.argv)
|
|
||||||
if app.options.debug:
|
if app.options.debug:
|
||||||
level=logging.DEBUG
|
level=logging.DEBUG
|
||||||
elif app.options.verbose:
|
elif app.options.verbose:
|
||||||
|
|
|
||||||
|
|
@ -102,17 +102,16 @@ class ConsoleApplication(BaseApplication):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
self.default_output_format = None
|
self.default_output_format = None
|
||||||
|
|
||||||
def _configure_parser(self, parser):
|
self._parser.format_description = lambda x: self._parser.description
|
||||||
parser.format_description = lambda x: parser.description
|
|
||||||
|
|
||||||
if parser.description is None:
|
if self._parser.description is None:
|
||||||
parser.description = ''
|
self._parser.description = ''
|
||||||
parser.description += 'Available commands:\n'
|
self._parser.description += 'Available commands:\n'
|
||||||
for f in self._command_help:
|
for f in self._command_help:
|
||||||
parser.description += ' %s\n' % f
|
self._parser.description += ' %s\n' % f
|
||||||
|
|
||||||
parser.add_option('-o', '--output-format', choices=formatters.keys(),
|
self._parser.add_option('-o', '--output-format', choices=formatters.keys(),
|
||||||
help='output format %s (default: table)' % formatters.keys())
|
help='output format %s (default: table)' % formatters.keys())
|
||||||
|
|
||||||
def ask(self, question, default=None, masked=False, regexp=None):
|
def ask(self, question, default=None, masked=False, regexp=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -150,7 +149,11 @@ class ConsoleApplication(BaseApplication):
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def process_command(self, command='help', *args):
|
def process_command(self, command=None, *args):
|
||||||
|
if command is None:
|
||||||
|
self._parser.print_help()
|
||||||
|
return 0
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
return x.startswith('command_' + command)
|
return x.startswith('command_' + command)
|
||||||
|
|
||||||
|
|
@ -232,11 +235,5 @@ class ConsoleApplication(BaseApplication):
|
||||||
def command(doc_string, f=register_command):
|
def command(doc_string, f=register_command):
|
||||||
return partial(f, doc_string=doc_string)
|
return partial(f, doc_string=doc_string)
|
||||||
|
|
||||||
@command("display this notice")
|
|
||||||
def command_help(self):
|
|
||||||
sys.stdout.write("Available commands:\n")
|
|
||||||
for f in self._command_help:
|
|
||||||
sys.stdout.write(' %s\n' % f)
|
|
||||||
|
|
||||||
register_command = staticmethod(register_command)
|
register_command = staticmethod(register_command)
|
||||||
command = staticmethod(command)
|
command = staticmethod(command)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue