Use class attributes as much as possible for application output

refs #803
This commit is contained in:
Laurent Bachelier 2014-09-03 01:22:18 +02:00
commit c07e23cafc
35 changed files with 228 additions and 260 deletions

View file

@ -23,7 +23,6 @@ import datetime, uuid
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from dateutil.parser import parse as parse_date from dateutil.parser import parse as parse_date
from decimal import Decimal, InvalidOperation from decimal import Decimal, InvalidOperation
import sys
from weboob.capabilities.base import empty from weboob.capabilities.base import empty
from weboob.capabilities.bank import CapBank, Account, Transaction from weboob.capabilities.bank import CapBank, Account, Transaction
@ -328,7 +327,7 @@ class Boobank(ReplApplication):
account = self.get_object(id, 'get_account', []) account = self.get_object(id, 'get_account', [])
if not account: if not account:
print('Error: account "%s" not found (Hint: try the command "list")' % id, file=sys.stderr) print('Error: account "%s" not found (Hint: try the command "list")' % id, file=self.stderr)
return 2 return 2
if end_date is not None: if end_date is not None:
@ -336,7 +335,7 @@ class Boobank(ReplApplication):
end_date = parse_date(end_date) end_date = parse_date(end_date)
except ValueError: except ValueError:
print('"%s" is an incorrect date format (for example "%s")' % \ print('"%s" is an incorrect date format (for example "%s")' % \
(end_date, (datetime.date.today() - relativedelta(months=1)).strftime('%Y-%m-%d')), file=sys.stderr) (end_date, (datetime.date.today() - relativedelta(months=1)).strftime('%Y-%m-%d')), file=self.stderr)
return 3 return 3
old_count = self.options.count old_count = self.options.count
self.options.count = None self.options.count = None
@ -406,7 +405,7 @@ class Boobank(ReplApplication):
account = self.get_object(id_from, 'get_account', []) account = self.get_object(id_from, 'get_account', [])
if not account: if not account:
print('Error: account %s not found' % id_from, file=sys.stderr) print('Error: account %s not found' % id_from, file=self.stderr)
return 1 return 1
if not id_to: if not id_to:
@ -422,13 +421,13 @@ class Boobank(ReplApplication):
id_to, backend_name_to = self.parse_id(id_to) id_to, backend_name_to = self.parse_id(id_to)
if account.backend != backend_name_to: if account.backend != backend_name_to:
print("Transfer between different backends is not implemented", file=sys.stderr) print("Transfer between different backends is not implemented", file=self.stderr)
return 4 return 4
try: try:
amount = Decimal(amount) amount = Decimal(amount)
except (TypeError, ValueError, InvalidOperation): except (TypeError, ValueError, InvalidOperation):
print('Error: please give a decimal amount to transfer', file=sys.stderr) print('Error: please give a decimal amount to transfer', file=self.stderr)
return 2 return 2
if self.interactive: if self.interactive:
@ -460,7 +459,7 @@ class Boobank(ReplApplication):
""" """
account = self.get_object(id, 'get_account', []) account = self.get_object(id, 'get_account', [])
if not account: if not account:
print('Error: account "%s" not found (Hint: try the command "list")' % id, file=sys.stderr) print('Error: account "%s" not found (Hint: try the command "list")' % id, file=self.stderr)
return 2 return 2
self.start_format() self.start_format()

View file

@ -119,7 +119,7 @@ class Event(object):
elif line.startswith('h3=. '): elif line.startswith('h3=. '):
m = re.match('h3=. Event finished. Winner is "(.*)":/users/(\d+)\!', line) m = re.match('h3=. Event finished. Winner is "(.*)":/users/(\d+)\!', line)
if not m: if not m:
print >>sys.stderr, 'Unable to parse h3=: %s' % line print >>self.stderr, 'Unable to parse h3=: %s' % line
continue continue
self.winner = Member(int(m.group(2)), m.group(1)) self.winner = Member(int(m.group(2)), m.group(1))
elif line.startswith('h2. '): elif line.startswith('h2. '):
@ -127,7 +127,7 @@ class Event(object):
elif line.startswith('h3. '): elif line.startswith('h3. '):
m = re.match('h3. "(.*)":/users/(\d+)', line) m = re.match('h3. "(.*)":/users/(\d+)', line)
if not m: if not m:
print >>sys.stderr, 'Unable to parse user "%s"' % line print >>self.stderr, 'Unable to parse user "%s"' % line
continue continue
member = Member(int(m.group(2)), m.group(1)) member = Member(int(m.group(2)), m.group(1))
if member.id == self.my_id: if member.id == self.my_id:
@ -166,7 +166,7 @@ class Event(object):
elif line.startswith('[['): elif line.startswith('[['):
m = re.match('\[\[(\w+)\]\]\|\[\[(\w+)\]\]\|(.*)\|', line) m = re.match('\[\[(\w+)\]\]\|\[\[(\w+)\]\]\|(.*)\|', line)
if not m: if not m:
print >>sys.stderr, 'Unable to parse task: "%s"' % line print >>self.stderr, 'Unable to parse task: "%s"' % line
continue continue
task = Task(m.group(1), m.group(2)) task = Task(m.group(1), m.group(2))
member.tasks.append(task) member.tasks.append(task)
@ -292,7 +292,7 @@ class Boobathon(ReplApplication):
def main(self, argv): def main(self, argv):
if len(argv) < 2: if len(argv) < 2:
print >>sys.stderr, 'Please give the name of the boobathon' print >>self.stderr, 'Please give the name of the boobathon'
return 1 return 1
self.event = Event(argv[1], choice(self.weboob.backend_instances.values())) self.event = Event(argv[1], choice(self.weboob.backend_instances.values()))
@ -414,9 +414,9 @@ class Boobathon(ReplApplication):
i = -2 i = -2
while not stop: while not stop:
if i >= 0 and not i%2: if i >= 0 and not i%2:
sys.stdout.write(' #%-2d' % (i/2)) self.stdout.write(' #%-2d' % (i/2))
else: else:
sys.stdout.write(' ') self.stdout.write(' ')
if i >= 0 and i%2: if i >= 0 and i%2:
# second line of task, see if we'll stop # second line of task, see if we'll stop
stop = True stop = True
@ -425,11 +425,11 @@ class Boobathon(ReplApplication):
# there are more tasks, don't stop now # there are more tasks, don't stop now
stop = False stop = False
if i == -2: if i == -2:
sys.stdout.write(' %s%-20s%s' % (self.BOLD, mem.shortname().encode('utf-8'), self.NC)) self.stdout.write(' %s%-20s%s' % (self.BOLD, mem.shortname().encode('utf-8'), self.NC))
elif i == -1: elif i == -1:
sys.stdout.write(' %s%-20s%s' % (self.BOLD, '-' * len(mem.shortname()), self.NC)) self.stdout.write(' %s%-20s%s' % (self.BOLD, '-' * len(mem.shortname()), self.NC))
elif len(mem.tasks) <= (i/2): elif len(mem.tasks) <= (i/2):
sys.stdout.write(' ' * (20+1)) self.stdout.write(' ' * (20+1))
else: else:
task = mem.tasks[i/2] task = mem.tasks[i/2]
if task.status == task.STATUS_DONE: if task.status == task.STATUS_DONE:
@ -446,8 +446,8 @@ class Boobathon(ReplApplication):
line = u'%s %s' % (status, task.backend) line = u'%s %s' % (status, task.backend)
else: #2nd line else: #2nd line
line = u'%s `-%s' % (status, task.capability[3:]) line = u'%s `-%s' % (status, task.capability[3:])
sys.stdout.write((u' %-20s' % line).encode('utf-8')) self.stdout.write((u' %-20s' % line).encode('utf-8'))
sys.stdout.write('\n') self.stdout.write('\n')
i += 1 i += 1
def complete_close(self, text, line, *ignored): def complete_close(self, text, line, *ignored):
@ -471,7 +471,7 @@ class Boobathon(ReplApplication):
print 'Event is now closed. Winner is %s!' % self.event.winner.name print 'Event is now closed. Winner is %s!' % self.event.winner.name
return return
print >>sys.stderr, '"%s" not found' % name print >>self.stderr, '"%s" not found' % name
return 3 return 3
def complete_edit(self, text, line, *ignored): def complete_edit(self, text, line, *ignored):
@ -486,7 +486,7 @@ class Boobathon(ReplApplication):
Edit information about you or about event. Edit information about you or about event.
""" """
if not line: if not line:
print >>sys.stderr, 'Syntax: edit [event | me]' print >>self.stderr, 'Syntax: edit [event | me]'
return 2 return 2
self.event.load() self.event.load()
@ -496,12 +496,12 @@ class Boobathon(ReplApplication):
elif line == 'me': elif line == 'me':
mem = self.event.get_me() mem = self.event.get_me()
if not mem: if not mem:
print >>sys.stderr, 'You haven\'t joined the event.' print >>self.stderr, 'You haven\'t joined the event.'
return 1 return 1
self.edit_member(mem) self.edit_member(mem)
self.save_event('Member edited') self.save_event('Member edited')
else: else:
print >>sys.stderr, 'Unable to edit "%s"' % line print >>self.stderr, 'Unable to edit "%s"' % line
return 1 return 1
def do_info(self, line): def do_info(self, line):
@ -558,11 +558,11 @@ class Boobathon(ReplApplication):
""" """
self.event.load() self.event.load()
if self.event.backend.browser.get_userid() in self.event.members: if self.event.backend.browser.get_userid() in self.event.members:
print >>sys.stderr, 'You have already joined this event.' print >>self.stderr, 'You have already joined this event.'
return 1 return 1
if self.event.is_closed(): if self.event.is_closed():
print >>sys.stderr, "Boobathon is closed." print >>self.stderr, "Boobathon is closed."
return 1 return 1
m = Member(self.event.backend.browser.get_userid(), None) m = Member(self.event.backend.browser.get_userid(), None)
@ -579,17 +579,17 @@ class Boobathon(ReplApplication):
self.event.load() self.event.load()
if self.event.currently_in_event(): if self.event.currently_in_event():
print >>sys.stderr, 'Unable to leave during the event, loser!' print >>self.stderr, 'Unable to leave during the event, loser!'
return 1 return 1
if self.event.is_closed(): if self.event.is_closed():
print >>sys.stderr, "Boobathon is closed." print >>self.stderr, "Boobathon is closed."
return 1 return 1
try: try:
self.event.members.pop(self.event.backend.browser.get_userid()) self.event.members.pop(self.event.backend.browser.get_userid())
except KeyError: except KeyError:
print >>sys.stderr, "You have not joined this event." print >>self.stderr, "You have not joined this event."
return 1 return 1
else: else:
self.save_event('Left the event') self.save_event('Left the event')
@ -603,23 +603,23 @@ class Boobathon(ReplApplication):
self.event.load() self.event.load()
mem = self.event.get_me() mem = self.event.get_me()
if not mem: if not mem:
print >>sys.stderr, "You have not joined this event." print >>self.stderr, "You have not joined this event."
return 1 return 1
if self.event.is_closed(): if self.event.is_closed():
print >>sys.stderr, "Boobathon is closed." print >>self.stderr, "Boobathon is closed."
return 1 return 1
try: try:
task_id = int(line) task_id = int(line)
except ValueError: except ValueError:
print >>sys.stderr, 'The task ID should be a number' print >>self.stderr, 'The task ID should be a number'
return 2 return 2
try: try:
task = mem.tasks.pop(task_id) task = mem.tasks.pop(task_id)
except IndexError: except IndexError:
print >>sys.stderr, 'Unable to find task #%d' % task_id print >>self.stderr, 'Unable to find task #%d' % task_id
return 1 return 1
else: else:
print 'Removing task #%d (%s,%s).' % (task_id, task.backend, task.capability) print 'Removing task #%d (%s,%s).' % (task_id, task.backend, task.capability)
@ -634,24 +634,24 @@ class Boobathon(ReplApplication):
self.event.load() self.event.load()
mem = self.event.get_me() mem = self.event.get_me()
if not mem: if not mem:
print >>sys.stderr, "You have not joined this event." print >>self.stderr, "You have not joined this event."
return 1 return 1
if self.event.is_closed(): if self.event.is_closed():
print >>sys.stderr, "Boobathon is closed." print >>self.stderr, "Boobathon is closed."
return 1 return 1
backend, capability = self.parse_command_args(line, 2, 2) backend, capability = self.parse_command_args(line, 2, 2)
if not backend[0].isupper(): if not backend[0].isupper():
print >>sys.stderr, 'The backend name "%s" needs to start with a capital.' % backend print >>self.stderr, 'The backend name "%s" needs to start with a capital.' % backend
return 2 return 2
if not capability.startswith('Cap') or not capability[3].isupper(): if not capability.startswith('Cap') or not capability[3].isupper():
print >>sys.stderr, '"%s" is not a proper capability name (must start with Cap).' % capability print >>self.stderr, '"%s" is not a proper capability name (must start with Cap).' % capability
return 2 return 2
for task in mem.tasks: for task in mem.tasks:
if (task.backend,task.capability) == (backend,capability): if (task.backend,task.capability) == (backend,capability):
print >>sys.stderr, "A task already exists for that." print >>self.stderr, "A task already exists for that."
return 1 return 1
task = Task(backend, capability) task = Task(backend, capability)
@ -668,15 +668,15 @@ class Boobathon(ReplApplication):
self.event.load() self.event.load()
mem = self.event.get_me() mem = self.event.get_me()
if not mem: if not mem:
print >>sys.stderr, "You have not joined this event." print >>self.stderr, "You have not joined this event."
return 1 return 1
if len(mem.tasks) == 0: if len(mem.tasks) == 0:
print >>sys.stderr, "You don't have any task to do." print >>self.stderr, "You don't have any task to do."
return 1 return 1
if not self.event.currently_in_event(): if not self.event.currently_in_event():
print >>sys.stderr, "You can't start a task, we are not in event." print >>self.stderr, "You can't start a task, we are not in event."
return 1 return 1
if line.isdigit(): if line.isdigit():
@ -695,11 +695,11 @@ class Boobathon(ReplApplication):
if (i == task_id or task_id < 0) and task.status == task.STATUS_NONE: if (i == task_id or task_id < 0) and task.status == task.STATUS_NONE:
break break
else: else:
print >>sys.stderr, 'Task not found.' print >>self.stderr, 'Task not found.'
return 3 return 3
if task.status == task.STATUS_DONE: if task.status == task.STATUS_DONE:
print >>sys.stderr, 'Task is already done.' print >>self.stderr, 'Task is already done.'
return 1 return 1
task.status = task.STATUS_PROGRESS task.status = task.STATUS_PROGRESS
@ -716,11 +716,11 @@ class Boobathon(ReplApplication):
self.event.load() self.event.load()
mem = self.event.get_me() mem = self.event.get_me()
if not mem: if not mem:
print >>sys.stderr, "You have not joined this event." print >>self.stderr, "You have not joined this event."
return 1 return 1
if self.event.is_closed(): if self.event.is_closed():
print >>sys.stderr, "Boobathon is closed." print >>self.stderr, "Boobathon is closed."
return 1 return 1
for i, task in enumerate(mem.tasks): for i, task in enumerate(mem.tasks):
@ -733,12 +733,12 @@ class Boobathon(ReplApplication):
self.save_event('Task accomplished') self.save_event('Task accomplished')
else: else:
task.status = task.STATUS_NONE task.status = task.STATUS_NONE
print >>sys.stderr, 'Oops, you are out of event. Canceling the task...' print >>self.stderr, 'Oops, you are out of event. Canceling the task...'
self.save_event('Cancel task') self.save_event('Cancel task')
return 1 return 1
return return
print >>sys.stderr, "There isn't any task in progress." print >>self.stderr, "There isn't any task in progress."
return 1 return 1
def do_cancel(self, line): def do_cancel(self, line):
@ -750,11 +750,11 @@ class Boobathon(ReplApplication):
self.event.load() self.event.load()
mem = self.event.get_me() mem = self.event.get_me()
if not mem: if not mem:
print >>sys.stderr, "You have not joined this event." print >>self.stderr, "You have not joined this event."
return 1 return 1
if self.event.is_closed(): if self.event.is_closed():
print >>sys.stderr, "Boobathon is closed." print >>self.stderr, "Boobathon is closed."
return 1 return 1
for task in mem.tasks: for task in mem.tasks:
@ -764,7 +764,7 @@ class Boobathon(ReplApplication):
self.save_event('Cancel task') self.save_event('Cancel task')
return return
print >>sys.stderr, "There isn't any task in progress." print >>self.stderr, "There isn't any task in progress."
return 1 return 1
def load_default_backends(self): def load_default_backends(self):

View file

@ -17,7 +17,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from datetime import time, datetime from datetime import time, datetime
from weboob.tools.date import parse_date from weboob.tools.date import parse_date
@ -231,7 +230,7 @@ class Boobcoming(ReplApplication):
if line: if line:
_date = parse_date(line) _date = parse_date(line)
if not _date: if not _date:
print >>sys.stderr, 'Invalid argument: %s' % self.get_command_help('list') print >>self.stderr, 'Invalid argument: %s' % self.get_command_help('list')
return 2 return 2
date_from = datetime.combine(_date, time.min) date_from = datetime.combine(_date, time.min)
@ -256,13 +255,13 @@ class Boobcoming(ReplApplication):
""" """
if not _id: if not _id:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True)
return 2 return 2
event = self.get_object(_id, 'get_event') event = self.get_object(_id, 'get_event')
if not event: if not event:
print >>sys.stderr, 'Upcoming event not found: %s' % _id print >>self.stderr, 'Upcoming event not found: %s' % _id
return 3 return 3
self.start_format() self.start_format()
@ -279,7 +278,7 @@ class Boobcoming(ReplApplication):
Export event in ICALENDAR format Export event in ICALENDAR format
""" """
if not line: if not line:
print >>sys.stderr, 'This command takes at leat one argument: %s' % self.get_command_help('export') print >>self.stderr, 'This command takes at leat one argument: %s' % self.get_command_help('export')
return 2 return 2
_file, args = self.parse_command_args(line, 2, req_n=1) _file, args = self.parse_command_args(line, 2, req_n=1)
@ -307,7 +306,7 @@ class Boobcoming(ReplApplication):
event = self.get_object(_id, 'get_event') event = self.get_object(_id, 'get_event')
if not event: if not event:
print >>sys.stderr, 'Upcoming event not found: %s' % _id print >>self.stderr, 'Upcoming event not found: %s' % _id
return 3 return 3
l.append(event) l.append(event)
@ -329,7 +328,7 @@ class Boobcoming(ReplApplication):
ID is the identifier of the event. ID is the identifier of the event.
""" """
if not line: if not line:
print >>sys.stderr, 'This command takes at leat one argument: %s' % self.get_command_help('attends') print >>self.stderr, 'This command takes at leat one argument: %s' % self.get_command_help('attends')
return 2 return 2
args = self.parse_command_args(line, 1, req_n=1) args = self.parse_command_args(line, 1, req_n=1)
@ -347,7 +346,7 @@ class Boobcoming(ReplApplication):
""" """
if not line: if not line:
print >>sys.stderr, 'This command takes at leat one argument: %s' % self.get_command_help('unattends') print >>self.stderr, 'This command takes at leat one argument: %s' % self.get_command_help('unattends')
return 2 return 2
args = self.parse_command_args(line, 1, req_n=1) args = self.parse_command_args(line, 1, req_n=1)

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from decimal import Decimal from decimal import Decimal
from weboob.capabilities.bill import CapBill, Detail, Subscription from weboob.capabilities.bill import CapBill, Detail, Subscription
@ -87,9 +86,9 @@ class Boobill(ReplApplication):
self.bcall_error_handler(backend, error, backtrace) self.bcall_error_handler(backend, error, backtrace)
if len(more_results) > 0: if len(more_results) > 0:
print >>sys.stderr, 'Hint: There are more results available for %s (use option -n or count command)' % (', '.join(more_results)) print >>self.stderr, 'Hint: There are more results available for %s (use option -n or count command)' % (', '.join(more_results))
for backend in not_implemented: for backend in not_implemented:
print >>sys.stderr, u'Error(%s): This feature is not supported yet by this backend.' % backend.name print >>self.stderr, u'Error(%s): This feature is not supported yet by this backend.' % backend.name
def do_subscriptions(self, line): def do_subscriptions(self, line):
""" """
@ -184,7 +183,7 @@ class Boobill(ReplApplication):
id, dest = self.parse_command_args(line, 2, 1) id, dest = self.parse_command_args(line, 2, 1)
id, backend_name = self.parse_id(id) id, backend_name = self.parse_id(id)
if not id: if not id:
print >>sys.stderr, 'Error: please give a bill ID (hint: use bills command)' print >>self.stderr, 'Error: please give a bill ID (hint: use bills command)'
return 2 return 2
names = (backend_name,) if backend_name is not None else None names = (backend_name,) if backend_name is not None else None
@ -211,7 +210,7 @@ class Boobill(ReplApplication):
with open(dest, 'w') as f: with open(dest, 'w') as f:
f.write(buf) f.write(buf)
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to write bill in "%s": %s' % (dest, e) print >>self.stderr, 'Unable to write bill in "%s": %s' % (dest, e)
return 1 return 1
return return
@ -228,7 +227,7 @@ class Boobill(ReplApplication):
with open(dest, 'w') as f: with open(dest, 'w') as f:
f.write(buf) f.write(buf)
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to write bill in "%s": %s' % (dest, e) print >>self.stderr, 'Unable to write bill in "%s": %s' % (dest, e)
return 1 return 1
return return

View file

@ -19,7 +19,6 @@
import sys
from weboob.capabilities.lyrics import CapLyrics from weboob.capabilities.lyrics import CapLyrics
from weboob.capabilities.base import empty from weboob.capabilities.base import empty
@ -85,7 +84,7 @@ class Booblyrics(ReplApplication):
songlyrics = self.get_object(id, 'get_lyrics') songlyrics = self.get_object(id, 'get_lyrics')
if not songlyrics: if not songlyrics:
print >>sys.stderr, 'Song lyrics not found: %s' % id print >>self.stderr, 'Song lyrics not found: %s' % id
return 3 return 3
self.start_format() self.start_format()

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
import os import os
import datetime import datetime
import hashlib import hashlib
@ -431,7 +430,7 @@ class Boobmsg(ReplApplication):
""" """
message = None message = None
if len(arg) == 0: if len(arg) == 0:
print >>sys.stderr, 'Please give a message ID.' print >>self.stderr, 'Please give a message ID.'
return 2 return 2
try: try:
@ -448,7 +447,7 @@ class Boobmsg(ReplApplication):
self.weboob.do('set_message_read', message, backends=message.backend) self.weboob.do('set_message_read', message, backends=message.backend)
return return
else: else:
print >>sys.stderr, 'Message not found' print >>self.stderr, 'Message not found'
return 3 return 3
def do_profile(self, id): def do_profile(self, id):
@ -476,7 +475,7 @@ class Boobmsg(ReplApplication):
""" """
photo_cmd = self.config.get('photo_viewer') photo_cmd = self.config.get('photo_viewer')
if photo_cmd is None: if photo_cmd is None:
print >>sys.stderr, "Configuration error: photo_viewer is undefined" print >>self.stderr, "Configuration error: photo_viewer is undefined"
return return
_id, backend_name = self.parse_id(id, unique_backend=True) _id, backend_name = self.parse_id(id, unique_backend=True)

View file

@ -20,7 +20,6 @@
from weboob.capabilities.library import CapBook, Book from weboob.capabilities.library import CapBook, Book
from weboob.tools.application.repl import ReplApplication from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import PrettyFormatter from weboob.tools.application.formatters.iformatter import PrettyFormatter
import sys
__all__ = ['Boobooks'] __all__ = ['Boobooks']
@ -63,7 +62,7 @@ class Boobooks(ReplApplication):
id, backend_name = self.parse_id(id) id, backend_name = self.parse_id(id)
if not id: if not id:
print >>sys.stderr, 'Error: please give a book ID (hint: use ls command)' print >>self.stderr, 'Error: please give a book ID (hint: use ls command)'
return 2 return 2
names = (backend_name,) if backend_name is not None else None names = (backend_name,) if backend_name is not None else None

View file

@ -23,7 +23,6 @@ from weboob.capabilities.gauge import CapGauge, SensorNotFound
from weboob.tools.application.repl import ReplApplication from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import IFormatter from weboob.tools.application.formatters.iformatter import IFormatter
import sys
__all__ = ['Boobsize'] __all__ = ['Boobsize']
@ -111,7 +110,7 @@ class Boobsize(ReplApplication):
def bcall_error_handler(self, backend, error, backtrace): def bcall_error_handler(self, backend, error, backtrace):
if isinstance(error, SensorNotFound): if isinstance(error, SensorNotFound):
msg = unicode(error) or 'Sensor not found (hint: try details command)' msg = unicode(error) or 'Sensor not found (hint: try details command)'
print >>sys.stderr, 'Error(%s): %s' % (backend.name, msg) print >>self.stderr, 'Error(%s): %s' % (backend.name, msg)
else: else:
return ReplApplication.bcall_error_handler(self, backend, error, backtrace) return ReplApplication.bcall_error_handler(self, backend, error, backtrace)

View file

@ -23,7 +23,6 @@ from email import message_from_string, message_from_file
from email.Header import decode_header from email.Header import decode_header
from email.mime.text import MIMEText from email.mime.text import MIMEText
from smtplib import SMTP from smtplib import SMTP
import sys
import os import os
import re import re
import unicodedata import unicodedata
@ -157,7 +156,7 @@ class BoobTracker(ReplApplication):
elif len(path) > 0: elif len(path) > 0:
query.project = path[0] query.project = path[0]
else: else:
print >>sys.stderr, 'Please enter a project name' print >>self.stderr, 'Please enter a project name'
return 1 return 1
query.author = self.options.author query.author = self.options.author
@ -184,12 +183,12 @@ class BoobTracker(ReplApplication):
Get an issue and display it. Get an issue and display it.
""" """
if not line: if not line:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('get', short=True) print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('get', short=True)
return 2 return 2
issue = self.get_object(line, 'get_issue') issue = self.get_object(line, 'get_issue')
if not issue: if not issue:
print >>sys.stderr, 'Issue not found: %s' % line print >>self.stderr, 'Issue not found: %s' % line
return 3 return 3
self.format(issue) self.format(issue)
@ -227,7 +226,7 @@ class BoobTracker(ReplApplication):
try: try:
hours = float(hours) hours = float(hours)
except ValueError: except ValueError:
print >>sys.stderr, 'Error: HOURS parameter may be a float' print >>self.stderr, 'Error: HOURS parameter may be a float'
return 1 return 1
id, backend_name = self.parse_id(id, unique_backend=True) id, backend_name = self.parse_id(id, unique_backend=True)
@ -383,16 +382,16 @@ class BoobTracker(ReplApplication):
backend = self.weboob.get_backend(issue.backend) backend = self.weboob.get_backend(issue.backend)
content = self.issue2text(issue, backend) content = self.issue2text(issue, backend)
while True: while True:
if sys.stdin.isatty(): if self.stdin.isatty():
content = self.acquire_input(content, {'vim': "-c 'set ft=mail'"}) content = self.acquire_input(content, {'vim': "-c 'set ft=mail'"})
m = message_from_string(content.encode('utf-8')) m = message_from_string(content.encode('utf-8'))
else: else:
m = message_from_file(sys.stdin) m = message_from_file(self.stdin)
try: try:
email_to = self.text2issue(issue, m) email_to = self.text2issue(issue, m)
except ValueError as e: except ValueError as e:
if not sys.stdin.isatty(): if not self.stdin.isatty():
raise raise
raw_input("%s -- Press Enter to continue..." % unicode(e).encode("utf-8")) raw_input("%s -- Press Enter to continue..." % unicode(e).encode("utf-8"))
continue continue
@ -407,7 +406,7 @@ class BoobTracker(ReplApplication):
self.send_notification(email_to, issue) self.send_notification(email_to, issue)
return 0 return 0
except IssueError as e: except IssueError as e:
if not sys.stdin.isatty(): if not self.stdin.isatty():
raise raise
raw_input("%s -- Press Enter to continue..." % unicode(e).encode("utf-8")) raw_input("%s -- Press Enter to continue..." % unicode(e).encode("utf-8"))
@ -482,7 +481,7 @@ Weboob Team
_id, key, value = self.parse_command_args(line, 3, 1) _id, key, value = self.parse_command_args(line, 3, 1)
issue = self.get_object(_id, 'get_issue') issue = self.get_object(_id, 'get_issue')
if not issue: if not issue:
print >>sys.stderr, 'Issue not found: %s' % _id print >>self.stderr, 'Issue not found: %s' % _id
return 3 return 3
return self.edit_issue(issue, edit=True) return self.edit_issue(issue, edit=True)
@ -500,4 +499,4 @@ Weboob Team
Attach a file to an issue (Not implemented yet). Attach a file to an issue (Not implemented yet).
""" """
print >>sys.stderr, 'Not implemented yet.' print >>self.stderr, 'Not implemented yet.'

View file

@ -19,7 +19,6 @@
import sys
from datetime import datetime from datetime import datetime
from weboob.applications.weboorrents.weboorrents import TorrentInfoFormatter, TorrentListFormatter from weboob.applications.weboorrents.weboorrents import TorrentInfoFormatter, TorrentListFormatter
@ -231,11 +230,11 @@ class Cineoob(ReplApplication):
person1 = self.get_object(id1, 'get_person', caps=CapCinema) person1 = self.get_object(id1, 'get_person', caps=CapCinema)
if not person1: if not person1:
print >>sys.stderr, 'Person not found: %s' % id1 print >>self.stderr, 'Person not found: %s' % id1
return 3 return 3
person2 = self.get_object(id2, 'get_person', caps=CapCinema) person2 = self.get_object(id2, 'get_person', caps=CapCinema)
if not person2: if not person2:
print >>sys.stderr, 'Person not found: %s' % id2 print >>self.stderr, 'Person not found: %s' % id2
return 3 return 3
initial_count = self.options.count initial_count = self.options.count
@ -264,11 +263,11 @@ class Cineoob(ReplApplication):
movie1 = self.get_object(id1, 'get_movie', caps=CapCinema) movie1 = self.get_object(id1, 'get_movie', caps=CapCinema)
if not movie1: if not movie1:
print >>sys.stderr, 'Movie not found: %s' % id1 print >>self.stderr, 'Movie not found: %s' % id1
return 3 return 3
movie2 = self.get_object(id2, 'get_movie', caps=CapCinema) movie2 = self.get_object(id2, 'get_movie', caps=CapCinema)
if not movie2: if not movie2:
print >>sys.stderr, 'Movie not found: %s' % id2 print >>self.stderr, 'Movie not found: %s' % id2
return 3 return 3
initial_count = self.options.count initial_count = self.options.count
@ -295,7 +294,7 @@ class Cineoob(ReplApplication):
movie = self.get_object(id, 'get_movie', caps=CapCinema) movie = self.get_object(id, 'get_movie', caps=CapCinema)
if not movie: if not movie:
print >>sys.stderr, 'Movie not found: %s' % id print >>self.stderr, 'Movie not found: %s' % id
return 3 return 3
self.start_format() self.start_format()
@ -310,7 +309,7 @@ class Cineoob(ReplApplication):
person = self.get_object(id, 'get_person', caps=CapCinema) person = self.get_object(id, 'get_person', caps=CapCinema)
if not person: if not person:
print >>sys.stderr, 'Person not found: %s' % id print >>self.stderr, 'Person not found: %s' % id
return 3 return 3
self.start_format() self.start_format()
@ -357,7 +356,7 @@ class Cineoob(ReplApplication):
movie = self.get_object(movie_id, 'get_movie', caps=CapCinema) movie = self.get_object(movie_id, 'get_movie', caps=CapCinema)
if not movie: if not movie:
print >>sys.stderr, 'Movie not found: %s' % id print >>self.stderr, 'Movie not found: %s' % id
return 3 return 3
for backend, person in self.do('iter_movie_persons', movie.id, role, backends=movie.backend, caps=CapCinema): for backend, person in self.do('iter_movie_persons', movie.id, role, backends=movie.backend, caps=CapCinema):
@ -374,7 +373,7 @@ class Cineoob(ReplApplication):
person = self.get_object(person_id, 'get_person', caps=CapCinema) person = self.get_object(person_id, 'get_person', caps=CapCinema)
if not person: if not person:
print >>sys.stderr, 'Person not found: %s' % id print >>self.stderr, 'Person not found: %s' % id
return 3 return 3
for backend, movie in self.do('iter_person_movies', person.id, role, backends=person.backend, caps=CapCinema): for backend, movie in self.do('iter_person_movies', person.id, role, backends=person.backend, caps=CapCinema):
@ -388,7 +387,7 @@ class Cineoob(ReplApplication):
""" """
person = self.get_object(person_id, 'get_person', ('name', 'biography'), caps=CapCinema) person = self.get_object(person_id, 'get_person', ('name', 'biography'), caps=CapCinema)
if not person: if not person:
print >>sys.stderr, 'Person not found: %s' % person_id print >>self.stderr, 'Person not found: %s' % person_id
return 3 return 3
self.start_format() self.start_format()
@ -412,7 +411,7 @@ class Cineoob(ReplApplication):
movie = self.get_object(id, 'get_movie', ('original_title'), caps=CapCinema) movie = self.get_object(id, 'get_movie', ('original_title'), caps=CapCinema)
if not movie: if not movie:
print >>sys.stderr, 'Movie not found: %s' % id print >>self.stderr, 'Movie not found: %s' % id
return 3 return 3
# i would like to clarify with fillobj but how could i fill the movie AND choose the country ? # i would like to clarify with fillobj but how could i fill the movie AND choose the country ?
@ -420,7 +419,7 @@ class Cineoob(ReplApplication):
if not empty(release): if not empty(release):
movie.all_release_dates = u'%s' % (release) movie.all_release_dates = u'%s' % (release)
else: else:
print >>sys.stderr, 'Movie releases not found for %s' % movie.original_title print >>self.stderr, 'Movie releases not found for %s' % movie.original_title
return 3 return 3
self.start_format() self.start_format()
self.format(movie) self.format(movie)
@ -441,7 +440,7 @@ class Cineoob(ReplApplication):
torrent = self.get_object(id, 'get_torrent', caps=CapTorrent) torrent = self.get_object(id, 'get_torrent', caps=CapTorrent)
if not torrent: if not torrent:
print >>sys.stderr, 'Torrent not found: %s' % id print >>self.stderr, 'Torrent not found: %s' % id
return 3 return 3
self.start_format() self.start_format()
@ -479,20 +478,20 @@ class Cineoob(ReplApplication):
with open(dest, 'w') as f: with open(dest, 'w') as f:
f.write(buf) f.write(buf)
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e) print >>self.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
return 1 return 1
return return
except CallErrors as errors: except CallErrors as errors:
for backend, error, backtrace in errors: for backend, error, backtrace in errors:
if isinstance(error, MagnetOnly): if isinstance(error, MagnetOnly):
print >>sys.stderr, u'Error(%s): No direct URL available, ' \ print >>self.stderr, u'Error(%s): No direct URL available, ' \
u'please provide this magnet URL ' \ u'please provide this magnet URL ' \
u'to your client:\n%s' % (backend, error.magnet) u'to your client:\n%s' % (backend, error.magnet)
return 4 return 4
else: else:
self.bcall_error_handler(backend, error, backtrace) self.bcall_error_handler(backend, error, backtrace)
print >>sys.stderr, 'Torrent "%s" not found' % id print >>self.stderr, 'Torrent "%s" not found' % id
return 3 return 3
@defaultcount(10) @defaultcount(10)
@ -519,7 +518,7 @@ class Cineoob(ReplApplication):
""" """
movie = self.get_object(id, 'get_movie', ('original_title'), caps=CapCinema) movie = self.get_object(id, 'get_movie', ('original_title'), caps=CapCinema)
if not movie: if not movie:
print >>sys.stderr, 'Movie not found: %s' % id print >>self.stderr, 'Movie not found: %s' % id
return 3 return 3
pattern = movie.original_title pattern = movie.original_title
@ -548,7 +547,7 @@ class Cineoob(ReplApplication):
subtitle = self.get_object(id, 'get_subtitle', caps=CapCinema) subtitle = self.get_object(id, 'get_subtitle', caps=CapCinema)
if not subtitle: if not subtitle:
print >>sys.stderr, 'Subtitle not found: %s' % id print >>self.stderr, 'Subtitle not found: %s' % id
return 3 return 3
self.start_format() self.start_format()
@ -585,11 +584,11 @@ class Cineoob(ReplApplication):
with open(dest, 'w') as f: with open(dest, 'w') as f:
f.write(buf) f.write(buf)
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to write file in "%s": %s' % (dest, e) print >>self.stderr, 'Unable to write file in "%s": %s' % (dest, e)
return 1 return 1
return return
print >>sys.stderr, 'Subtitle "%s" not found' % id print >>self.stderr, 'Subtitle "%s" not found' % id
return 3 return 3
@defaultcount(10) @defaultcount(10)
@ -658,7 +657,7 @@ class Cineoob(ReplApplication):
language, id = self.parse_command_args(line, 2, 2) language, id = self.parse_command_args(line, 2, 2)
movie = self.get_object(id, 'get_movie', ('original_title'), caps=CapCinema) movie = self.get_object(id, 'get_movie', ('original_title'), caps=CapCinema)
if not movie: if not movie:
print >>sys.stderr, 'Movie not found: %s' % id print >>self.stderr, 'Movie not found: %s' % id
return 3 return 3
pattern = movie.original_title pattern = movie.original_title

View file

@ -20,7 +20,6 @@
import sys
from weboob.capabilities.pricecomparison import CapPriceComparison from weboob.capabilities.pricecomparison import CapPriceComparison
from weboob.tools.html import html2text from weboob.tools.html import html2text
@ -109,7 +108,7 @@ class Comparoob(ReplApplication):
product = None product = None
if len(products) == 0: if len(products) == 0:
print >>sys.stderr, 'Error: no product found with this pattern' print >>self.stderr, 'Error: no product found with this pattern'
return 1 return 1
elif len(products) == 1: elif len(products) == 1:
product = products[0] product = products[0]
@ -147,12 +146,12 @@ class Comparoob(ReplApplication):
Get information about a product. Get information about a product.
""" """
if not _id: if not _id:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True)
return 2 return 2
price = self.get_object(_id, 'get_price') price = self.get_object(_id, 'get_price')
if not price: if not price:
print >>sys.stderr, 'Price not found: %s' % _id print >>self.stderr, 'Price not found: %s' % _id
return 3 return 3
self.start_format() self.start_format()

View file

@ -19,7 +19,6 @@
import sys
import codecs import codecs
from weboob.capabilities.recipe import CapRecipe from weboob.capabilities.recipe import CapRecipe
@ -100,7 +99,7 @@ class Cookboob(ReplApplication):
""" """
recipe = self.get_object(id, 'get_recipe') recipe = self.get_object(id, 'get_recipe')
if not recipe: if not recipe:
print >>sys.stderr, 'Recipe not found: %s' % id print >>self.stderr, 'Recipe not found: %s' % id
return 3 return 3
self.start_format() self.start_format()
@ -141,10 +140,10 @@ class Cookboob(ReplApplication):
with codecs.open(dest, 'w', 'utf-8') as f: with codecs.open(dest, 'w', 'utf-8') as f:
f.write(xmlstring) f.write(xmlstring)
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to write .kreml in "%s": %s' % (dest, e) print >>self.stderr, 'Unable to write .kreml in "%s": %s' % (dest, e)
return 1 return 1
return return
print >>sys.stderr, 'Recipe "%s" not found' % id print >>self.stderr, 'Recipe "%s" not found' % id
return 3 return 3
@defaultcount(10) @defaultcount(10)

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from weboob.capabilities.housing import CapHousing, Query from weboob.capabilities.housing import CapHousing, Query
from weboob.tools.application.repl import ReplApplication, defaultcount from weboob.tools.application.repl import ReplApplication, defaultcount
@ -167,12 +166,12 @@ class Flatboob(ReplApplication):
Get information about a housing. Get information about a housing.
""" """
if not _id: if not _id:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True)
return 2 return 2
housing = self.get_object(_id, 'get_housing') housing = self.get_object(_id, 'get_housing')
if not housing: if not housing:
print >>sys.stderr, 'Housing not found: %s' % _id print >>self.stderr, 'Housing not found: %s' % _id
return 3 return 3
self.start_format() self.start_format()

View file

@ -19,7 +19,6 @@
import sys
import os import os
from re import search, sub from re import search, sub
@ -68,7 +67,7 @@ class Galleroob(ReplApplication):
List galleries matching a PATTERN. List galleries matching a PATTERN.
""" """
if not pattern: if not pattern:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('search', short=True) print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('search', short=True)
return 2 return 2
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
@ -98,7 +97,7 @@ class Galleroob(ReplApplication):
gallery = result gallery = result
if not gallery: if not gallery:
print >>sys.stderr, 'Gallery not found: %s' % _id print >>self.stderr, 'Gallery not found: %s' % _id
return 3 return 3
backend.fillobj(gallery, ('title',)) backend.fillobj(gallery, ('title',))
@ -123,7 +122,7 @@ class Galleroob(ReplApplication):
if img.data is None: if img.data is None:
backend.fillobj(img, ('url', 'data')) backend.fillobj(img, ('url', 'data'))
if img.data is None: if img.data is None:
print >>sys.stderr, "Couldn't get page %d, exiting" % i print >>self.stderr, "Couldn't get page %d, exiting" % i
break break
ext = search(r"\.([^\.]{1,5})$", img.url) ext = search(r"\.([^\.]{1,5})$", img.url)
@ -150,7 +149,7 @@ class Galleroob(ReplApplication):
gallery = self.get_object(_id, 'get_gallery') gallery = self.get_object(_id, 'get_gallery')
if not gallery: if not gallery:
print >>sys.stderr, 'Gallery not found: %s' % _id print >>self.stderr, 'Gallery not found: %s' % _id
return 3 return 3
self.start_format() self.start_format()

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from weboob.capabilities.geolocip import CapGeolocIp from weboob.capabilities.geolocip import CapGeolocIp
from weboob.tools.application.repl import ReplApplication from weboob.tools.application.repl import ReplApplication
@ -37,7 +36,7 @@ class Geolooc(ReplApplication):
def main(self, argv): def main(self, argv):
if len(argv) < 2: if len(argv) < 2:
print >>sys.stderr, 'Syntax: %s ipaddr' % argv[0] print >>self.stderr, 'Syntax: %s ipaddr' % argv[0]
return 2 return 2
for backend, location in self.do('get_location', argv[1]): for backend, location in self.do('get_location', argv[1]):

View file

@ -17,7 +17,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from weboob.capabilities.job import CapJob from weboob.capabilities.job import CapJob
from weboob.tools.application.repl import ReplApplication, defaultcount from weboob.tools.application.repl import ReplApplication, defaultcount
@ -123,13 +122,13 @@ class Handjoob(ReplApplication):
Get information about an advert. Get information about an advert.
""" """
if not _id: if not _id:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) print >>self.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True)
return 2 return 2
job_advert = self.get_object(_id, 'get_job_advert') job_advert = self.get_object(_id, 'get_job_advert')
if not job_advert: if not job_advert:
print >>sys.stderr, 'Job advert not found: %s' % _id print >>self.stderr, 'Job advert not found: %s' % _id
return 3 return 3
self.start_format() self.start_format()

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from copy import copy from copy import copy
from weboob.core import CallErrors from weboob.core import CallErrors
@ -92,7 +91,7 @@ class HaveDate(Boobmsg):
def edit_optims(self, backend_names, optims_names, stop=False): def edit_optims(self, backend_names, optims_names, stop=False):
if optims_names is None: if optims_names is None:
print >>sys.stderr, 'Error: missing parameters.' print >>self.stderr, 'Error: missing parameters.'
return 2 return 2
for optim_name in optims_names.split(): for optim_name in optims_names.split():
@ -124,14 +123,14 @@ class HaveDate(Boobmsg):
def optims(self, function, backend_names, optims, store=True): def optims(self, function, backend_names, optims, store=True):
if optims is None: if optims is None:
print >>sys.stderr, 'Error: missing parameters.' print >>self.stderr, 'Error: missing parameters.'
return 2 return 2
for optim_name in optims.split(): for optim_name in optims.split():
try: try:
if store: if store:
storage_optim = set(self.storage.get('optims', optim_name, default=[])) storage_optim = set(self.storage.get('optims', optim_name, default=[]))
sys.stdout.write('%sing %s:' % (function.capitalize(), optim_name)) self.stdout.write('%sing %s:' % (function.capitalize(), optim_name))
for backend, optim in self.do('get_optimization', optim_name, backends=backend_names): for backend, optim in self.do('get_optimization', optim_name, backends=backend_names):
if optim: if optim:
# It's useless to start a started optim, or to stop a stopped one. # It's useless to start a started optim, or to stop a stopped one.
@ -144,10 +143,10 @@ class HaveDate(Boobmsg):
self.edit_optims(backend.name, optim_name) self.edit_optims(backend.name, optim_name)
ret = getattr(optim, function)() ret = getattr(optim, function)()
sys.stdout.write(' ' + backend.name) self.stdout.write(' ' + backend.name)
if not ret: if not ret:
sys.stdout.write('(failed)') self.stdout.write('(failed)')
sys.stdout.flush() self.stdout.flush()
if store: if store:
if function == 'start' and ret: if function == 'start' and ret:
storage_optim.add(backend.name) storage_optim.add(backend.name)
@ -156,7 +155,7 @@ class HaveDate(Boobmsg):
storage_optim.remove(backend.name) storage_optim.remove(backend.name)
except KeyError: except KeyError:
pass pass
sys.stdout.write('.\n') self.stdout.write('.\n')
except CallErrors as errors: except CallErrors as errors:
for backend, error, backtrace in errors: for backend, error, backtrace in errors:
if isinstance(error, OptimizationNotFound): if isinstance(error, OptimizationNotFound):
@ -206,7 +205,7 @@ class HaveDate(Boobmsg):
if backend_name == '*': if backend_name == '*':
backend_name = None backend_name = None
elif backend_name is not None and not backend_name in [b.name for b in self.enabled_backends]: elif backend_name is not None and not backend_name in [b.name for b in self.enabled_backends]:
print >>sys.stderr, 'Error: No such backend "%s"' % backend_name print >>self.stderr, 'Error: No such backend "%s"' % backend_name
return 1 return 1
if cmd == 'start': if cmd == 'start':
@ -246,7 +245,7 @@ class HaveDate(Boobmsg):
line.append((b, status)) line.append((b, status))
self.format(tuple(line)) self.format(tuple(line))
return return
print >>sys.stderr, "No such command '%s'" % cmd print >>self.stderr, "No such command '%s'" % cmd
return 1 return 1
def do_events(self, line): def do_events(self, line):

View file

@ -26,7 +26,6 @@ from email import message_from_file, message_from_string
from smtpd import SMTPServer from smtpd import SMTPServer
import time import time
import re import re
import sys
import logging import logging
import asyncore import asyncore
import subprocess import subprocess
@ -119,7 +118,7 @@ class Monboob(ReplApplication):
if self.config.get('interval') < 1: if self.config.get('interval') < 1:
raise ValueError() raise ValueError()
except ValueError: except ValueError:
print >>sys.stderr, 'Configuration error: interval must be an integer >0.' print >>self.stderr, 'Configuration error: interval must be an integer >0.'
return 1 return 1
try: try:
@ -127,7 +126,7 @@ class Monboob(ReplApplication):
if self.config.get('html') not in (0, 1): if self.config.get('html') not in (0, 1):
raise ValueError() raise ValueError()
except ValueError: except ValueError:
print >>sys.stderr, 'Configuration error: html must be 0 or 1.' print >>self.stderr, 'Configuration error: html must be 0 or 1.'
return 2 return 2
return ReplApplication.main(self, argv) return ReplApplication.main(self, argv)
@ -151,7 +150,7 @@ class Monboob(ReplApplication):
Pipe with a mail to post message. Pipe with a mail to post message.
""" """
msg = message_from_file(sys.stdin) msg = message_from_file(self.stdin)
return self.process_incoming_mail(msg) return self.process_incoming_mail(msg)
def process_incoming_mail(self, msg): def process_incoming_mail(self, msg):
@ -190,7 +189,7 @@ class Monboob(ReplApplication):
break break
if len(content) == 0: if len(content) == 0:
print >>sys.stderr, 'Unable to send an empty message' print >>self.stderr, 'Unable to send an empty message'
return 1 return 1
# remove signature # remove signature
@ -210,7 +209,7 @@ class Monboob(ReplApplication):
bname, id = reply_to.split('.', 1) bname, id = reply_to.split('.', 1)
thread_id, parent_id = id.rsplit('.', 1) thread_id, parent_id = id.rsplit('.', 1)
except ValueError: except ValueError:
print >>sys.stderr, 'In-Reply-To header might be in form <backend.thread_id.message_id>' print >>self.stderr, 'In-Reply-To header might be in form <backend.thread_id.message_id>'
return 1 return 1
# Default use the To header field to know the backend to use. # Default use the To header field to know the backend to use.
@ -220,11 +219,11 @@ class Monboob(ReplApplication):
try: try:
backend = self.weboob.backend_instances[bname] backend = self.weboob.backend_instances[bname]
except KeyError: except KeyError:
print >>sys.stderr, 'Backend %s not found' % bname print >>self.stderr, 'Backend %s not found' % bname
return 1 return 1
if not backend.has_caps(CapMessagesPost): if not backend.has_caps(CapMessagesPost):
print >>sys.stderr, 'The backend %s does not implement CapMessagesPost' % bname print >>self.stderr, 'The backend %s does not implement CapMessagesPost' % bname
return 1 return 1
thread = Thread(thread_id) thread = Thread(thread_id)

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from weboob.capabilities.base import empty from weboob.capabilities.base import empty
from weboob.capabilities.parcel import CapParcel, Parcel from weboob.capabilities.parcel import CapParcel, Parcel
@ -106,7 +105,7 @@ class Parceloob(ReplApplication):
""" """
parcel = self.get_object(line, 'get_parcel_tracking') parcel = self.get_object(line, 'get_parcel_tracking')
if not parcel: if not parcel:
print >>sys.stderr, 'Error: the parcel "%s" is not found' % line print >>self.stderr, 'Error: the parcel "%s" is not found' % line
return 2 return 2
parcels = set(self.storage.get('tracking', default=[])) parcels = set(self.storage.get('tracking', default=[]))
@ -134,13 +133,13 @@ class Parceloob(ReplApplication):
if not removed: if not removed:
parcel = self.get_object(line, 'get_parcel_tracking') parcel = self.get_object(line, 'get_parcel_tracking')
if not parcel: if not parcel:
print >>sys.stderr, 'Error: the parcel "%s" is not found' % line print >>self.stderr, 'Error: the parcel "%s" is not found' % line
return 2 return 2
try: try:
parcels.remove(parcel.fullid) parcels.remove(parcel.fullid)
except KeyError: except KeyError:
print >>sys.stderr, "Error: parcel \"%s\" wasn't tracked" % parcel.fullid print >>self.stderr, "Error: parcel \"%s\" wasn't tracked" % parcel.fullid
return 2 return 2
self.storage.set('tracking', list(parcels)) self.storage.set('tracking', list(parcels))
@ -181,7 +180,7 @@ class Parceloob(ReplApplication):
""" """
parcel = self.get_object(id, 'get_parcel_tracking', []) parcel = self.get_object(id, 'get_parcel_tracking', [])
if not parcel: if not parcel:
print >>sys.stderr, 'Error: parcel not found' print >>self.stderr, 'Error: parcel not found'
return 2 return 2
self.start_format() self.start_format()

View file

@ -17,7 +17,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import sys
from PyQt4.QtCore import Qt, SIGNAL from PyQt4.QtCore import Qt, SIGNAL
from PyQt4.QtGui import QFrame, QFileDialog from PyQt4.QtGui import QFrame, QFileDialog
@ -83,6 +82,6 @@ class Subtitle(QFrame):
with open(dest, 'w') as f: with open(dest, 'w') as f:
f.write(data) f.write(data)
except IOError as e: except IOError as e:
print >>sys.stderr, 'Unable to write subtitle file in "%s": %s' % (dest, e) print >>self.stderr, 'Unable to write subtitle file in "%s": %s' % (dest, e)
return 1 return 1
return return

Some files were not shown because too many files have changed in this diff Show more