Remove backend for do() calls

This commit is contained in:
Florent 2014-10-09 11:04:09 +02:00
commit 628c63f899
33 changed files with 112 additions and 113 deletions

View file

@ -193,20 +193,20 @@ class MyThread(Thread):
backend.set_message_read(backend.fill_thread(thread, ['root']).root) backend.set_message_read(backend.fill_thread(thread, ['root']).root)
def check_dlfp(self): def check_dlfp(self):
for backend, msg in self.weboob.do('iter_unread_messages', backends=['dlfp']): for msg in self.weboob.do('iter_unread_messages', backends=['dlfp']):
word = self.find_keywords(msg.content) word = self.find_keywords(msg.content)
if word is not None: if word is not None:
url = msg.signature[msg.signature.find('https://linuxfr'):] url = msg.signature[msg.signature.find('https://linuxfr'):]
self.bot.send_message('[DLFP] %s talks about %s: %s' % ( self.bot.send_message('[DLFP] %s talks about %s: %s' % (
msg.sender, word, url)) msg.sender, word, url))
backend.set_message_read(msg) self.weboob[msg.backend].set_message_read(msg)
def check_board(self): def check_board(self):
def iter_messages(backend): def iter_messages(backend):
with backend.browser: with backend.browser:
return backend.browser.iter_new_board_messages() return backend.browser.iter_new_board_messages()
for backend, msg in self.weboob.do(iter_messages, backends=['dlfp']): for msg in self.weboob.do(iter_messages, backends=['dlfp']):
word = self.find_keywords(msg.message) word = self.find_keywords(msg.message)
if word is not None and msg.login != 'moules': if word is not None and msg.login != 'moules':
message = msg.message.replace(word, '\002%s\002' % word) message = msg.message.replace(word, '\002%s\002' % word)

View file

@ -144,7 +144,7 @@ class BoobankMuninPlugin(object):
accounts = [] accounts = []
if self.monitored_accounts is not None: if self.monitored_accounts is not None:
d = {} d = {}
for backend, account in self.weboob.do('iter_accounts'): for account in self.weboob.do('iter_accounts'):
if self.monitored(account): if self.monitored(account):
d['%s@%s' % (account.id, account.backend)] = account d['%s@%s' % (account.id, account.backend)] = account
@ -154,7 +154,7 @@ class BoobankMuninPlugin(object):
except KeyError: except KeyError:
pass pass
else: else:
accounts = reversed([a for b, a in self.weboob.do('iter_accounts')]) accounts = reversed([a for a in self.weboob.do('iter_accounts')])
first = True first = True
for account in accounts: for account in accounts:
@ -191,7 +191,7 @@ class BoobankMuninPlugin(object):
self.new_cache('boobank-munin') self.new_cache('boobank-munin')
self.weboob.load_backends(CapBank) self.weboob.load_backends(CapBank)
try: try:
for backend, account in self.weboob.do('iter_accounts'): for account in self.weboob.do('iter_accounts'):
if self.monitored(account): if self.monitored(account):
balance = account.balance balance = account.balance
if account.coming and self.add_coming: if account.coming and self.add_coming:

View file

@ -224,9 +224,9 @@ class GenericMuninPlugin(object):
results = [] results = []
for result in self.weboob.do(self.object_list): for result in self.weboob.do(self.object_list):
results.append(result) results.append(result)
for backend, result in results: for result in results:
try: try:
for i in self.weboob.do(self.do[0], result.id, backends=backend): for i in self.weboob.do(self.do[0], result.id, backends=result.backend):
yield i yield i
# Do not crash if one module does not implement the feature # Do not crash if one module does not implement the feature
except CallErrors: except CallErrors:
@ -284,7 +284,7 @@ class GenericMuninPlugin(object):
objects = [] objects = []
if self.tomonitore or self.exclude: if self.tomonitore or self.exclude:
d = {} d = {}
for backend, result in self.build_do(): for result in self.build_do():
if self.monitored(result): if self.monitored(result):
d[self.result2weboobid(result)] = result d[self.result2weboobid(result)] = result
@ -329,7 +329,7 @@ class GenericMuninPlugin(object):
self.new_cache(self.name) self.new_cache(self.name)
self.weboob.load_backends(self.capa) self.weboob.load_backends(self.capa)
try: try:
for backend, result in self.build_do(): for result in self.build_do():
if self.monitored(result): if self.monitored(result):
value = self.get_value(result) value = self.get_value(result)
if value is not NotAvailable: if value is not NotAvailable:

View file

@ -20,7 +20,7 @@ class Videoobmc(Weboobmc):
fields = ['id', 'title', 'date', 'description', 'author', 'duration', 'thumbnail', 'url'] fields = ['id', 'title', 'date', 'description', 'author', 'duration', 'thumbnail', 'url']
try: try:
for _backend, video in self.weboob.do(self._do_complete, self.count, fields, 'search_videos', **kwargs): for video in self.weboob.do(self._do_complete, self.count, fields, 'search_videos', **kwargs):
yield video yield video
except Exception as e: except Exception as e:
print(e) print(e)
@ -42,7 +42,7 @@ class Videoobmc(Weboobmc):
def separate_collections_and_videos(self, objs): def separate_collections_and_videos(self, objs):
videos = [] videos = []
categories = [] categories = []
for backend, obj in objs: for obj in objs:
if isinstance(obj, Collection): if isinstance(obj, Collection):
categories.append(obj) categories.append(obj)
else: else:
@ -50,5 +50,5 @@ class Videoobmc(Weboobmc):
return categories, videos return categories, videos
def download(self, _id, dest, backend): def download(self, _id, dest, backend):
for backend, _video in self.weboob.do('get_video', _id, backends=backend): for _video in self.weboob.do('get_video', _id, backends=backend):
self.download_obj(_video, dest) self.download_obj(_video, dest)

View file

@ -341,7 +341,7 @@ class Boobank(ReplApplication):
self.options.count = None self.options.count = None
self.start_format(account=account) self.start_format(account=account)
for backend, transaction in self.do(command, account, backends=account.backend): for transaction in self.do(command, account, backends=account.backend):
if end_date is not None and transaction.date < end_date: if end_date is not None and transaction.date < end_date:
break break
self.format(transaction) self.format(transaction)
@ -414,7 +414,7 @@ class Boobank(ReplApplication):
self.set_formatter_header(u'Available recipients') self.set_formatter_header(u'Available recipients')
self.start_format() self.start_format()
for backend, recipient in self.do('iter_transfer_recipients', account.id, backends=account.backend): for recipient in self.do('iter_transfer_recipients', account.id, backends=account.backend):
self.cached_format(recipient) self.cached_format(recipient)
return 0 return 0
@ -435,7 +435,7 @@ class Boobank(ReplApplication):
# recipients list, for example for banks which allow transfers to # recipients list, for example for banks which allow transfers to
# arbitrary recipients. # arbitrary recipients.
to = id_to to = id_to
for backend, recipient in self.do('iter_transfer_recipients', account.id, backends=account.backend): for recipient in self.do('iter_transfer_recipients', account.id, backends=account.backend):
if recipient.id == id_to: if recipient.id == id_to:
to = recipient.label to = recipient.label
break break
@ -448,7 +448,7 @@ class Boobank(ReplApplication):
return return
self.start_format() self.start_format()
for backend, transfer in self.do('transfer', account.id, id_to, amount, reason, backends=account.backend): for transfer in self.do('transfer', account.id, id_to, amount, reason, backends=account.backend):
self.format(transfer) self.format(transfer)
def do_investment(self, id): def do_investment(self, id):
@ -463,5 +463,5 @@ class Boobank(ReplApplication):
return 2 return 2
self.start_format() self.start_format()
for backend, investment in self.do('iter_investment', account, backends=account.backend): for investment in self.do('iter_investment', account, backends=account.backend):
self.format(investment) self.format(investment)

View file

@ -213,7 +213,7 @@ class Boobcoming(ReplApplication):
self.change_path([u'events']) self.change_path([u'events'])
self.start_format() self.start_format()
for backend, event in self.do('search_events', query): for event in self.do('search_events', query):
if event: if event:
self.cached_format(event) self.cached_format(event)
@ -241,7 +241,7 @@ class Boobcoming(ReplApplication):
date_from = datetime.now() date_from = datetime.now()
date_to = None date_to = None
for backend, event in self.do('list_events', date_from, date_to): for event in self.do('list_events', date_from, date_to):
self.cached_format(event) self.cached_format(event)
def complete_info(self, text, line, *ignored): def complete_info(self, text, line, *ignored):
@ -299,7 +299,7 @@ class Boobcoming(ReplApplication):
if not args: if not args:
_ids = [] _ids = []
for backend, event in self.do('list_events', datetime.now(), None): for event in self.do('list_events', datetime.now(), None):
_ids.append(event.id) _ids.append(event.id)
else: else:
_ids = args.strip().split(' ') _ids = args.strip().split(' ')

View file

@ -74,7 +74,7 @@ class Boobill(ReplApplication):
for id, backend in l: for id, backend in l:
names = (backend,) if backend is not None else None names = (backend,) if backend is not None else None
try: try:
for backend, result in self.do(method, id, backends=names): for result in self.do(method, id, backends=names):
self.format(result) self.format(result)
except CallErrors as errors: except CallErrors as errors:
for backend, error, backtrace in errors: for backend, error, backtrace in errors:
@ -128,7 +128,7 @@ class Boobill(ReplApplication):
mysum.price = Decimal("0.") mysum.price = Decimal("0.")
self.start_format() self.start_format()
for backend, detail in self.do('get_details', id, backends=names): for detail in self.do('get_details', id, backends=names):
self.format(detail) self.format(detail)
mysum.price = detail.price + mysum.price mysum.price = detail.price + mysum.price
@ -191,7 +191,7 @@ class Boobill(ReplApplication):
# Special keywords, download all bills of all subscriptions # Special keywords, download all bills of all subscriptions
if id == "all": if id == "all":
if dest is None: if dest is None:
for backend, subscription in self.do('iter_subscription', backends=names): for subscription in self.do('iter_subscription', backends=names):
self.download_all(subscription.id, names) self.download_all(subscription.id, names)
return return
else: else:
@ -199,10 +199,10 @@ class Boobill(ReplApplication):
return return
if dest is None: if dest is None:
for backend, bill in self.do('get_bill', id, backends=names): for bill in self.do('get_bill', id, backends=names):
dest = id + "." + bill.format dest = id + "." + bill.format
for backend, buf in self.do('download_bill', id, backends=names): for buf in self.do('download_bill', id, backends=names):
if buf: if buf:
if dest == "-": if dest == "-":
print(buf) print(buf)
@ -217,9 +217,9 @@ class Boobill(ReplApplication):
def download_all(self, id, names): def download_all(self, id, names):
id, backend_name = self.parse_id(id) id, backend_name = self.parse_id(id)
for backend, bill in self.do('iter_bills', id, backends=names): for bill in self.do('iter_bills', id, backends=names):
dest = bill.id + "." + bill.format dest = bill.id + "." + bill.format
for backend2, buf in self.do('download_bill', bill.id, backends=names): for buf in self.do('download_bill', bill.id, backends=names):
if buf: if buf:
if dest == "-": if dest == "-":
print(buf) print(buf)

View file

@ -107,5 +107,5 @@ class Booblyrics(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, songlyrics in self.do('iter_lyrics', criteria, pattern): for songlyrics in self.do('iter_lyrics', criteria, pattern):
self.cached_format(songlyrics) self.cached_format(songlyrics)

View file

@ -280,7 +280,7 @@ class Boobmsg(ReplApplication):
backend_name = None backend_name = None
results = {} results = {}
for useless, field in self.do('get_account_status', for field in self.do('get_account_status',
backends=backend_name, backends=backend_name,
caps=CapAccount): caps=CapAccount):
if field.backend in results: if field.backend in results:
@ -406,7 +406,7 @@ class Boobmsg(ReplApplication):
yield msg yield msg
self.start_format() self.start_format()
for backend, msg in self.do(func): for msg in self.do(func):
self.format(msg) self.format(msg)
def do_export_thread(self, arg): def do_export_thread(self, arg):
@ -460,7 +460,7 @@ class Boobmsg(ReplApplication):
_id, backend_name = self.parse_id(id, unique_backend=True) _id, backend_name = self.parse_id(id, unique_backend=True)
found = 0 found = 0
for backend, contact in self.do('get_contact', _id, backends=backend_name, caps=CapContact): for contact in self.do('get_contact', _id, backends=backend_name, caps=CapContact):
if contact: if contact:
self.format(contact) self.format(contact)
found = 1 found = 1
@ -482,7 +482,7 @@ class Boobmsg(ReplApplication):
_id, backend_name = self.parse_id(id, unique_backend=True) _id, backend_name = self.parse_id(id, unique_backend=True)
found = 0 found = 0
for backend, contact in self.do('get_contact', _id, backends=backend_name): for contact in self.do('get_contact', _id, backends=backend_name):
if contact: if contact:
# Write photo to temporary files # Write photo to temporary files
tmp_files = [] tmp_files = []
@ -492,7 +492,7 @@ class Boobmsg(ReplApplication):
suffix = '.%s' % photo.url.split('/')[-1].split('.')[-1] suffix = '.%s' % photo.url.split('/')[-1].split('.')[-1]
f = NamedTemporaryFile(suffix=suffix) f = NamedTemporaryFile(suffix=suffix)
photo = backend.fillobj(photo, 'data') photo = self.weboob[contact.backend].fillobj(photo, 'data')
f.write(photo.data) f.write(photo.data)
tmp_files.append(f) tmp_files.append(f)
os.system(photo_cmd % ' '.join([file.name for file in tmp_files])) os.system(photo_cmd % ' '.join([file.name for file in tmp_files]))

View file

@ -68,5 +68,5 @@ class Boobooks(ReplApplication):
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
for backend, renew in self.do('renew_book', id, backends=names): for renew in self.do('renew_book', id, backends=names):
self.format(renew) self.format(renew)

View file

@ -123,7 +123,7 @@ class Boobsize(ReplApplication):
""" """
self.change_path([u'gauges']) self.change_path([u'gauges'])
self.start_format() self.start_format()
for backend, gauge in self.do('iter_gauges', pattern or None, caps=CapGauge): for gauge in self.do('iter_gauges', pattern or None, caps=CapGauge):
self.cached_format(gauge) self.cached_format(gauge)
def complete_search(self, text, line, *ignored): def complete_search(self, text, line, *ignored):
@ -141,7 +141,7 @@ class Boobsize(ReplApplication):
_id, backend_name = self.parse_id(gauge) _id, backend_name = self.parse_id(gauge)
self.start_format() self.start_format()
for backend, sensor in self.do('iter_sensors', _id, pattern=pattern, backends=backend_name, caps=CapGauge): for sensor in self.do('iter_sensors', _id, pattern=pattern, backends=backend_name, caps=CapGauge):
self.format(sensor) self.format(sensor)
def do_history(self, line): def do_history(self, line):
@ -154,7 +154,7 @@ class Boobsize(ReplApplication):
_id, backend_name = self.parse_id(gauge) _id, backend_name = self.parse_id(gauge)
self.start_format() self.start_format()
for backend, measure in self.do('iter_gauge_history', _id, backends=backend_name, caps=CapGauge): for measure in self.do('iter_gauge_history', _id, backends=backend_name, caps=CapGauge):
self.format(measure) self.format(measure)
def complete_last_sensor_measure(self, text, line, *ignored): def complete_last_sensor_measure(self, text, line, *ignored):
@ -172,5 +172,5 @@ class Boobsize(ReplApplication):
_id, backend_name = self.parse_id(gauge) _id, backend_name = self.parse_id(gauge)
self.start_format() self.start_format()
for backend, measure in self.do('get_last_measure', _id, backends=backend_name, caps=CapGauge): for measure in self.do('get_last_measure', _id, backends=backend_name, caps=CapGauge):
self.format(measure) self.format(measure)

View file

@ -168,7 +168,7 @@ class BoobTracker(ReplApplication):
query.status = self.options.status query.status = self.options.status
self.change_path([query.project, u'search']) self.change_path([query.project, u'search'])
for backend, issue in self.do('iter_issues', query, backends=backends): for issue in self.do('iter_issues', query, backends=backends):
self.add_object(issue) self.add_object(issue)
self.format(issue) self.format(issue)

View file

@ -241,10 +241,10 @@ class Cineoob(ReplApplication):
self.options.count = None self.options.count = None
lid1 = [] lid1 = []
for backend, id in self.do('iter_person_movies_ids', person1.id, caps=CapCinema): for id in self.do('iter_person_movies_ids', person1.id, caps=CapCinema):
lid1.append(id) lid1.append(id)
lid2 = [] lid2 = []
for backend, id in self.do('iter_person_movies_ids', person2.id, caps=CapCinema): for id in self.do('iter_person_movies_ids', person2.id, caps=CapCinema):
lid2.append(id) lid2.append(id)
self.options.count = initial_count self.options.count = initial_count
inter = list(set(lid1) & set(lid2)) inter = list(set(lid1) & set(lid2))
@ -274,10 +274,10 @@ class Cineoob(ReplApplication):
self.options.count = None self.options.count = None
lid1 = [] lid1 = []
for backend, id in self.do('iter_movie_persons_ids', movie1.id, caps=CapCinema): for id in self.do('iter_movie_persons_ids', movie1.id, caps=CapCinema):
lid1.append(id) lid1.append(id)
lid2 = [] lid2 = []
for backend, id in self.do('iter_movie_persons_ids', movie2.id, caps=CapCinema): for id in self.do('iter_movie_persons_ids', movie2.id, caps=CapCinema):
lid2.append(id) lid2.append(id)
self.options.count = initial_count self.options.count = initial_count
inter = list(set(lid1) & set(lid2)) inter = list(set(lid1) & set(lid2))
@ -327,7 +327,7 @@ class Cineoob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, movie in self.do('iter_movies', pattern=pattern, caps=CapCinema): for movie in self.do('iter_movies', pattern=pattern, caps=CapCinema):
self.cached_format(movie) self.cached_format(movie)
@defaultcount(10) @defaultcount(10)
@ -342,7 +342,7 @@ class Cineoob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, person in self.do('iter_persons', pattern=pattern, caps=CapCinema): for person in self.do('iter_persons', pattern=pattern, caps=CapCinema):
self.cached_format(person) self.cached_format(person)
def do_casting(self, line): def do_casting(self, line):
@ -359,7 +359,7 @@ class Cineoob(ReplApplication):
print('Movie not found: %s' % id, file=self.stderr) print('Movie not found: %s' % id, file=self.stderr)
return 3 return 3
for backend, person in self.do('iter_movie_persons', movie.id, role, backends=movie.backend, caps=CapCinema): for person in self.do('iter_movie_persons', movie.id, role, backends=movie.backend, caps=CapCinema):
self.cached_format(person) self.cached_format(person)
def do_filmography(self, line): def do_filmography(self, line):
@ -376,7 +376,7 @@ class Cineoob(ReplApplication):
print('Person not found: %s' % id, file=self.stderr) print('Person not found: %s' % id, file=self.stderr)
return 3 return 3
for backend, movie in self.do('iter_person_movies', person.id, role, backends=person.backend, caps=CapCinema): for movie in self.do('iter_person_movies', person.id, role, backends=person.backend, caps=CapCinema):
self.cached_format(movie) self.cached_format(movie)
def do_biography(self, person_id): def do_biography(self, person_id):
@ -415,7 +415,7 @@ class Cineoob(ReplApplication):
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 ?
for backend, release in self.do('get_movie_releases', movie.id, country, caps=CapCinema, backends=movie.backend): for release in self.do('get_movie_releases', movie.id, country, caps=CapCinema, backends=movie.backend):
if not empty(release): if not empty(release):
movie.all_release_dates = u'%s' % (release) movie.all_release_dates = u'%s' % (release)
else: else:
@ -469,7 +469,7 @@ class Cineoob(ReplApplication):
dest = '%s.torrent' % _id dest = '%s.torrent' % _id
try: try:
for backend, buf in self.do('get_torrent_file', _id, backends=backend_name, caps=CapTorrent): for buf in self.do('get_torrent_file', _id, backends=backend_name, caps=CapTorrent):
if buf: if buf:
if dest == '-': if dest == '-':
print(buf) print(buf)
@ -506,7 +506,7 @@ class Cineoob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, torrent in self.do('iter_torrents', pattern=pattern, caps=CapTorrent): for torrent in self.do('iter_torrents', pattern=pattern, caps=CapTorrent):
self.cached_format(torrent) self.cached_format(torrent)
@defaultcount(10) @defaultcount(10)
@ -528,7 +528,7 @@ class Cineoob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, torrent in self.do('iter_torrents', pattern=pattern, caps=CapTorrent): for torrent in self.do('iter_torrents', pattern=pattern, caps=CapTorrent):
self.cached_format(torrent) self.cached_format(torrent)
#================== SUBTITLE ================== #================== SUBTITLE ==================
@ -575,7 +575,7 @@ class Cineoob(ReplApplication):
if dest is None: if dest is None:
dest = '%s' % _id dest = '%s' % _id
for backend, buf in self.do('get_subtitle_file', _id, backends=backend_name, caps=CapSubtitle): for buf in self.do('get_subtitle_file', _id, backends=backend_name, caps=CapSubtitle):
if buf: if buf:
if dest == '-': if dest == '-':
print(buf) print(buf)
@ -624,7 +624,7 @@ class Cineoob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, subtitle in self.do('iter_subtitles', language=language, pattern=pattern, caps=CapSubtitle): for subtitle in self.do('iter_subtitles', language=language, pattern=pattern, caps=CapSubtitle):
self.cached_format(subtitle) self.cached_format(subtitle)
@defaultcount(10) @defaultcount(10)
@ -666,5 +666,5 @@ class Cineoob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, subtitle in self.do('iter_subtitles', language=language, pattern=pattern, caps=CapSubtitle): for subtitle in self.do('iter_subtitles', language=language, pattern=pattern, caps=CapSubtitle):
self.cached_format(subtitle) self.cached_format(subtitle)

View file

@ -95,7 +95,7 @@ class Comparoob(ReplApplication):
what product to compare. what product to compare.
""" """
products = [] products = []
for backend, product in self.do('search_products', pattern): for product in self.do('search_products', pattern):
double = False double = False
for prod in products: for prod in products:
if product.name == prod.name: if product.name == prod.name:
@ -124,7 +124,7 @@ class Comparoob(ReplApplication):
self.change_path([u'prices']) self.change_path([u'prices'])
self.start_format() self.start_format()
products = [] products = []
for backend, price in self.do('iter_prices', product): for price in self.do('iter_prices', product):
products.append(price) products.append(price)
for price in sorted(products, key=self._get_price): for price in sorted(products, key=self._get_price):
self.cached_format(price) self.cached_format(price)

View file

@ -155,5 +155,5 @@ class Cookboob(ReplApplication):
""" """
self.change_path([u'search']) self.change_path([u'search'])
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, recipe in self.do('iter_recipes', pattern=pattern): for recipe in self.do('iter_recipes', pattern=pattern):
self.cached_format(recipe) self.cached_format(recipe)

View file

@ -116,7 +116,7 @@ class Flatboob(ReplApplication):
break break
cities = [] cities = []
for backend, city in self.weboob.do('search_city', pattern): for city in self.weboob.do('search_city', pattern):
cities.append(city) cities.append(city)
if len(cities) == 0: if len(cities) == 0:
@ -195,7 +195,7 @@ class Flatboob(ReplApplication):
def complete_search(self, query): def complete_search(self, query):
self.change_path([u'housings']) self.change_path([u'housings'])
self.start_format() self.start_format()
for backend, housing in self.do('search_housings', query): for housing in self.do('search_housings', query):
self.cached_format(housing) self.cached_format(housing)
def ask_int(self, txt): def ask_int(self, txt):

View file

@ -71,7 +71,7 @@ class Galleroob(ReplApplication):
return 2 return 2
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, gallery in self.do('search_gallery', pattern=pattern): for gallery in self.do('search_gallery', pattern=pattern):
self.cached_format(gallery) self.cached_format(gallery)
def do_download(self, line): def do_download(self, line):
@ -91,16 +91,15 @@ class Galleroob(ReplApplication):
gallery = None gallery = None
_id, backend = self.parse_id(_id) _id, backend = self.parse_id(_id)
for _backend, result in self.do('get_gallery', _id, backends=backend): for result in self.do('get_gallery', _id, backends=backend):
if result: if result:
backend = _backend
gallery = result gallery = result
if not gallery: if not gallery:
print('Gallery not found: %s' % _id, file=self.stderr) print('Gallery not found: %s' % _id, file=self.stderr)
return 3 return 3
backend.fillobj(gallery, ('title',)) self.weboob[backend].fillobj(gallery, ('title',))
if dest is None: if dest is None:
dest = sub('/', ' ', gallery.title) dest = sub('/', ' ', gallery.title)
@ -113,14 +112,14 @@ class Galleroob(ReplApplication):
os.chdir(dest) # fail here if dest couldn't be created os.chdir(dest) # fail here if dest couldn't be created
i = 0 i = 0
for img in backend.iter_gallery_images(gallery): for img in self.weboob[backend].iter_gallery_images(gallery):
i += 1 i += 1
if i < first: if i < first:
continue continue
backend.fillobj(img, ('url', 'data')) self.weboob[backend].fillobj(img, ('url', 'data'))
if img.data is None: if img.data is None:
backend.fillobj(img, ('url', 'data')) self.weboob[backend].fillobj(img, ('url', 'data'))
if img.data is None: if img.data is None:
print("Couldn't get page %d, exiting" % i, file=self.stderr) print("Couldn't get page %d, exiting" % i, file=self.stderr)
break break

View file

@ -39,5 +39,5 @@ class Geolooc(ReplApplication):
print('Syntax: %s ipaddr' % argv[0], file=self.stderr) print('Syntax: %s ipaddr' % argv[0], file=self.stderr)
return 2 return 2
for backend, location in self.do('get_location', argv[1]): for location in self.do('get_location', argv[1]):
self.format(location) self.format(location)

View file

@ -97,7 +97,7 @@ class Handjoob(ReplApplication):
""" """
self.change_path([u'search']) self.change_path([u'search'])
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, job_advert in self.do('search_job', pattern): for job_advert in self.do('search_job', pattern):
self.cached_format(job_advert) self.cached_format(job_advert)
@defaultcount(10) @defaultcount(10)
@ -108,7 +108,7 @@ class Handjoob(ReplApplication):
Search for an advert matching to advanced filters. Search for an advert matching to advanced filters.
""" """
self.change_path([u'advanced']) self.change_path([u'advanced'])
for backend, job_advert in self.do('advanced_search_job'): for job_advert in self.do('advanced_search_job'):
self.cached_format(job_advert) self.cached_format(job_advert)
def complete_info(self, text, line, *ignored): def complete_info(self, text, line, *ignored):

View file

@ -87,7 +87,7 @@ class HaveDate(Boobmsg):
""" """
_id, backend_name = self.parse_id(id, unique_backend=True) _id, backend_name = self.parse_id(id, unique_backend=True)
for backend, query in self.do('send_query', _id, backends=backend_name): for query in self.do('send_query', _id, backends=backend_name):
print('%s' % query.message) print('%s' % query.message)
def edit_optims(self, backend_names, optims_names, stop=False): def edit_optims(self, backend_names, optims_names, stop=False):
@ -97,9 +97,9 @@ class HaveDate(Boobmsg):
for optim_name in optims_names.split(): for optim_name in optims_names.split():
backends_optims = {} backends_optims = {}
for backend, optim in self.do('get_optimization', optim_name, backends=backend_names): for optim in self.do('get_optimization', optim_name, backends=backend_names):
if optim: if optim:
backends_optims[backend.name] = optim backends_optims[optim.backend] = optim
for backend_name, optim in backends_optims.iteritems(): for backend_name, optim in backends_optims.iteritems():
if len(optim.CONFIG) == 0: if len(optim.CONFIG) == 0:
print('%s.%s does not require configuration.' % (backend_name, optim_name)) print('%s.%s does not require configuration.' % (backend_name, optim_name))
@ -132,7 +132,7 @@ class HaveDate(Boobmsg):
if store: if store:
storage_optim = set(self.storage.get('optims', optim_name, default=[])) storage_optim = set(self.storage.get('optims', optim_name, default=[]))
self.stdout.write('%sing %s:' % (function.capitalize(), optim_name)) self.stdout.write('%sing %s:' % (function.capitalize(), optim_name))
for useless, optim in self.do('get_optimization', optim_name, backends=backend_names): for 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.
if (function == 'start' and optim.is_running()) or \ if (function == 'start' and optim.is_running()) or \
@ -183,7 +183,7 @@ class HaveDate(Boobmsg):
else: else:
backend = args[2] backend = args[2]
optims = set() optims = set()
for backend, (name, optim) in self.do('iter_optimizations', backends=backend): for (name, optim) in self.do('iter_optimizations', backends=backend):
optims.add(name) optims.add(name)
return sorted(optims - set(args[3:])) return sorted(optims - set(args[3:]))
@ -222,7 +222,7 @@ class HaveDate(Boobmsg):
optims = {} optims = {}
backends = set() backends = set()
for backend, (name, optim) in self.do('iter_optimizations', backends=backend_name): for (name, optim) in self.do('iter_optimizations', backends=backend_name):
if optims_names is not None and not name in optims_names: if optims_names is not None and not name in optims_names:
continue continue
if optim.is_running(): if optim.is_running():
@ -230,10 +230,10 @@ class HaveDate(Boobmsg):
else: else:
status = '-------' status = '-------'
if not name in optims: if not name in optims:
optims[name] = {backend.name: status} optims[name] = {optim.backend: status}
else: else:
optims[name][backend.name] = status optims[name][optim.backend] = status
backends.add(backend.name) backends.add(optim.backend)
backends = sorted(backends) backends = sorted(backends)
for name, backends_status in optims.iteritems(): for name, backends_status in optims.iteritems():
@ -257,5 +257,5 @@ class HaveDate(Boobmsg):
""" """
self.change_path([u'events']) self.change_path([u'events'])
self.start_format() self.start_format()
for backend, event in self.do('iter_events'): for event in self.do('iter_events'):
self.cached_format(event) self.cached_format(event)

View file

@ -268,9 +268,9 @@ class Monboob(ReplApplication):
def process(self): def process(self):
try: try:
for backend, message in self.weboob.do('iter_unread_messages'): for message in self.weboob.do('iter_unread_messages'):
if self.send_email(message.backend, message): if self.send_email(message.backend, message):
backend.set_message_read(message) self.weboob[message.backend].set_message_read(message)
except CallErrors as e: except CallErrors as e:
self.bcall_errors_handler(e) self.bcall_errors_handler(e)

View file

@ -425,25 +425,25 @@ class Radioob(ReplApplication):
if cmd == "radio": if cmd == "radio":
self.set_formatter('radio_list') self.set_formatter('radio_list')
for backend, radio in self.do('iter_radios_search', pattern=args): for radio in self.do('iter_radios_search', pattern=args):
self.add_object(radio) self.add_object(radio)
self.format(radio) self.format(radio)
elif cmd == "song": elif cmd == "song":
self.set_formatter('song_list') self.set_formatter('song_list')
for backend, audio in self.do('search_audio', pattern=args): for audio in self.do('search_audio', pattern=args):
self.add_object(audio) self.add_object(audio)
self.format(audio) self.format(audio)
elif cmd == "album": elif cmd == "album":
self.set_formatter('song_list') self.set_formatter('song_list')
for backend, album in self.do('search_album', pattern=args): for album in self.do('search_album', pattern=args):
self.add_object(album) self.add_object(album)
self.format(album) self.format(album)
elif cmd == "playlist": elif cmd == "playlist":
self.set_formatter('song_list') self.set_formatter('song_list')
for backend, playlist in self.do('search_playlist', pattern=args): for playlist in self.do('search_playlist', pattern=args):
self.add_object(playlist) self.add_object(playlist)
self.format(playlist) self.format(playlist)

View file

@ -146,7 +146,7 @@ class Suboob(ReplApplication):
ext = 'zip' ext = 'zip'
dest = '%s.%s' % (subtitle.name, ext) dest = '%s.%s' % (subtitle.name, ext)
for backend, buf in self.do('get_subtitle_file', subtitle.id, backends=subtitle.backend): for buf in self.do('get_subtitle_file', subtitle.id, backends=subtitle.backend):
if buf: if buf:
if dest == '-': if dest == '-':
self.stdout.write(buf) self.stdout.write(buf)
@ -194,5 +194,5 @@ class Suboob(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, subtitle in self.do('iter_subtitles', language=language, pattern=pattern): for subtitle in self.do('iter_subtitles', language=language, pattern=pattern):
self.cached_format(subtitle) self.cached_format(subtitle)

View file

@ -112,7 +112,7 @@ class Translaboob(ReplApplication):
text = self.acquire_input() text = self.acquire_input()
self.start_format(source=text) self.start_format(source=text)
for backend, translation in self.do('translate', self.LANGUAGE[lan_from], self.LANGUAGE[lan_to], text): for translation in self.do('translate', self.LANGUAGE[lan_from], self.LANGUAGE[lan_to], text):
self.format(translation) self.format(translation)
except (TranslationFail, LanguageNotSupported) as error: except (TranslationFail, LanguageNotSupported) as error:
print(error, file=self.stderr) print(error, file=self.stderr)

View file

@ -88,7 +88,7 @@ class Traveloob(ReplApplication):
Search stations. Search stations.
""" """
for backend, station in self.do('iter_station_search', pattern): for station in self.do('iter_station_search', pattern):
self.format(station) self.format(station)
@defaultcount(10) @defaultcount(10)
@ -125,7 +125,7 @@ class Traveloob(ReplApplication):
print('Please enter a datetime in form "yyyy-mm-dd HH:MM" or "HH:MM".', file=self.stderr) print('Please enter a datetime in form "yyyy-mm-dd HH:MM" or "HH:MM".', file=self.stderr)
return 1 return 1
for backend, departure in self.do('iter_station_departures', station_id, arrival_id, date, backends=backends): for departure in self.do('iter_station_departures', station_id, arrival_id, date, backends=backends):
self.format(departure) self.format(departure)
def do_roadmap(self, line): def do_roadmap(self, line):
@ -154,7 +154,7 @@ class Traveloob(ReplApplication):
print('Please enter a datetime in form "yyyy-mm-dd HH:MM" or "HH:MM".', file=self.stderr) print('Please enter a datetime in form "yyyy-mm-dd HH:MM" or "HH:MM".', file=self.stderr)
return 1 return 1
for backend, route in self.do('iter_roadmap', departure, arrival, filters): for route in self.do('iter_roadmap', departure, arrival, filters):
self.format(route) self.format(route)
def parse_datetime(self, text): def parse_datetime(self, text):

View file

@ -337,5 +337,5 @@ class Videoob(ReplApplication):
self.change_path([u'search']) self.change_path([u'search'])
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, video in self.do('search_videos', pattern=pattern, nsfw=self.nsfw): for video in self.do('search_videos', pattern=pattern, nsfw=self.nsfw):
self.cached_format(video) self.cached_format(video)

View file

@ -51,7 +51,7 @@ class WebContentEdit(ReplApplication):
_id, backend_name = self.parse_id(id, unique_backend=True) _id, backend_name = self.parse_id(id, unique_backend=True)
backend_names = (backend_name,) if backend_name is not None else self.enabled_backends backend_names = (backend_name,) if backend_name is not None else self.enabled_backends
contents += [content for backend, content in self.do('get_content', _id, backends=backend_names) if content] contents += [content for content in self.do('get_content', _id, backends=backend_names) if content]
if len(contents) == 0: if len(contents) == 0:
print('No contents found', file=self.stderr) print('No contents found', file=self.stderr)
@ -159,7 +159,7 @@ class WebContentEdit(ReplApplication):
_id = _id.encode('utf-8') _id = _id.encode('utf-8')
self.start_format() self.start_format()
for backend, revision in self.do('iter_revisions', _id, backends=backend_names): for revision in self.do('iter_revisions', _id, backends=backend_names):
self.format(revision) self.format(revision)
def do_get(self, line): def do_get(self, line):
@ -192,7 +192,7 @@ class WebContentEdit(ReplApplication):
_id = _id.encode('utf-8') _id = _id.encode('utf-8')
output = codecs.getwriter(self.encoding)(self.stdout) output = codecs.getwriter(self.encoding)(self.stdout)
for contents in [content for backend, content in self.do('get_content', _id, revision, backends=backend_names) if content]: for contents in [content for content in self.do('get_content', _id, revision, backends=backend_names) if content]:
output.write(contents.content) output.write(contents.content)
# add a newline unless we are writing # add a newline unless we are writing

View file

@ -50,7 +50,7 @@ class WeboobCli(ReplApplication):
self.load_backends(cap_s) self.load_backends(cap_s)
for backend, obj in self.do(cmd, *args): for obj in self.do(cmd, *args):
self.format(obj) self.format(obj)
self.flush() self.flush()

View file

@ -147,7 +147,7 @@ class Weboorrents(ReplApplication):
dest = self.obj_to_filename(torrent, dest, '{id}-{name}.torrent') dest = self.obj_to_filename(torrent, dest, '{id}-{name}.torrent')
try: try:
for backend, buf in self.do('get_torrent_file', torrent.id, backends=torrent.backend): for buf in self.do('get_torrent_file', torrent.id, backends=torrent.backend):
if buf: if buf:
if dest == '-': if dest == '-':
print(buf) print(buf)
@ -184,5 +184,5 @@ class Weboorrents(ReplApplication):
pattern = None pattern = None
self.start_format(pattern=pattern) self.start_format(pattern=pattern)
for backend, torrent in self.do('iter_torrents', pattern=pattern): for torrent in self.do('iter_torrents', pattern=pattern):
self.cached_format(torrent) self.cached_format(torrent)

View file

@ -87,7 +87,7 @@ class WetBoobs(ReplApplication):
""" """
self.change_path(['cities']) self.change_path(['cities'])
self.start_format() self.start_format()
for backend, city in self.do('iter_city_search', pattern, caps=CapWeather): for city in self.do('iter_city_search', pattern, caps=CapWeather):
self.cached_format(city) self.cached_format(city)
def complete_current(self, text, line, *ignored): def complete_current(self, text, line, *ignored):
@ -111,7 +111,7 @@ class WetBoobs(ReplApplication):
self.formatter.temperature_display = lambda t: t.asfahrenheit() self.formatter.temperature_display = lambda t: t.asfahrenheit()
self.start_format() self.start_format()
for backend, current in self.do('get_current', _id, backends=backend_name, caps=CapWeather): for current in self.do('get_current', _id, backends=backend_name, caps=CapWeather):
if current: if current:
self.format(current) self.format(current)
@ -136,5 +136,5 @@ class WetBoobs(ReplApplication):
self.formatter.temperature_display = lambda t: t.asfahrenheit() self.formatter.temperature_display = lambda t: t.asfahrenheit()
self.start_format() self.start_format()
for backend, forecast in self.do('iter_forecast', _id, backends=backend_name, caps=CapWeather): for forecast in self.do('iter_forecast', _id, backends=backend_name, caps=CapWeather):
self.format(forecast) self.format(forecast)

View file

@ -32,7 +32,7 @@ class OptimizationNotFound(UserError):
""" """
class Optimization(object): class Optimization(BaseObject):
""" """
Optimization. Optimization.

View file

@ -67,7 +67,7 @@ class BackendsCall(object):
def store_result(self, backend, result): def store_result(self, backend, result):
if isinstance(result, BaseObject): if isinstance(result, BaseObject):
result.backend = backend.name result.backend = backend.name
self.responses.put((backend, result)) self.responses.put(result)
def backend_process(self, function, args, kwargs): def backend_process(self, function, args, kwargs):
backend = self.tasks.get() backend = self.tasks.get()

View file

@ -261,7 +261,7 @@ class ReplApplication(Cmd, ConsoleApplication):
new_backend_names.append(backend) new_backend_names.append(backend)
backend_names = tuple(new_backend_names) backend_names = tuple(new_backend_names)
try: try:
for backend, objiter in self.do(method, _id, backends=backend_names, fields=fields, **kargs): for objiter in self.do(method, _id, backends=backend_names, fields=fields, **kargs):
if objiter: if objiter:
obj = objiter obj = objiter
if objiter.id == _id: if objiter.id == _id:
@ -280,8 +280,8 @@ class ReplApplication(Cmd, ConsoleApplication):
return self.objects return self.objects
elif method is not None: elif method is not None:
kwargs['backends'] = self.enabled_backends kwargs['backends'] = self.enabled_backends
for backend, object in self.weboob.do(self._do_complete, None, None, method, *args, **kwargs): for _object in self.weboob.do(self._do_complete, None, None, method, *args, **kwargs):
self.add_object(object) self.add_object(_object)
return self.objects return self.objects
# XXX: what can we do without method? # XXX: what can we do without method?
else: else:
@ -1069,9 +1069,9 @@ class ReplApplication(Cmd, ConsoleApplication):
collections = [] collections = []
try: try:
for backend, res in self.do('get_collection', objs=self.COLLECTION_OBJECTS, for res in self.do('get_collection', objs=self.COLLECTION_OBJECTS,
split_path=self.working_path.get(), split_path=self.working_path.get(),
caps=CapCollection): caps=CapCollection):
if res: if res:
collections.append(res) collections.append(res)
except CallErrors as errors: except CallErrors as errors:
@ -1092,9 +1092,9 @@ class ReplApplication(Cmd, ConsoleApplication):
split_path = self.working_path.get() split_path = self.working_path.get()
try: try:
for backend, res in self.do('iter_resources', objs=objs, for res in self.do('iter_resources', objs=objs,
split_path=split_path, split_path=split_path,
caps=CapCollection): caps=CapCollection):
yield res yield res
except CallErrors as errors: except CallErrors as errors:
self.bcall_errors_handler(errors, CollectionNotFound) self.bcall_errors_handler(errors, CollectionNotFound)