use lock on Browser
This commit is contained in:
parent
2650c32b24
commit
ad240e7aed
2 changed files with 36 additions and 27 deletions
|
|
@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
from weboob.backend import BaseBackend
|
from weboob.backend import BaseBackend
|
||||||
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
|
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
|
||||||
from weboob.capabilities.dating import ICapDating
|
from weboob.capabilities.dating import ICapDating
|
||||||
|
|
@ -67,38 +69,41 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating):
|
||||||
yield message
|
yield message
|
||||||
|
|
||||||
def _iter_messages(self, thread, only_new):
|
def _iter_messages(self, thread, only_new):
|
||||||
try:
|
with self.browser:
|
||||||
if not only_new or self.browser.nb_new_mails():
|
try:
|
||||||
my_name = self.browser.get_my_name()
|
if not only_new or self.browser.nb_new_mails():
|
||||||
contacts = self.browser.get_contact_list()
|
my_name = self.browser.get_my_name()
|
||||||
contacts.reverse()
|
contacts = self.browser.get_contact_list()
|
||||||
|
contacts.reverse()
|
||||||
|
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if only_new and not contact.is_new() or thread and int(thread) != contact.get_id():
|
if only_new and not contact.is_new() or thread and int(thread) != contact.get_id():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mails = self.browser.get_thread_mails(contact.get_id())
|
mails = self.browser.get_thread_mails(contact.get_id())
|
||||||
profile = None
|
profile = None
|
||||||
for i in xrange(len(mails)):
|
for i in xrange(len(mails)):
|
||||||
mail = mails[i]
|
mail = mails[i]
|
||||||
if only_new and mail.get_from() == my_name:
|
if only_new and mail.get_from() == my_name:
|
||||||
break
|
break
|
||||||
|
|
||||||
if not profile:
|
if not profile:
|
||||||
profile = self.browser.get_profile(contact.get_id())
|
profile = self.browser.get_profile(contact.get_id())
|
||||||
mail.signature += u'\n%s' % profile.get_profile_text()
|
mail.signature += u'\n%s' % profile.get_profile_text()
|
||||||
yield mail
|
yield mail
|
||||||
except BrowserUnavailable:
|
except BrowserUnavailable:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def post_reply(self, thread_id, reply_id, title, message):
|
def post_reply(self, thread_id, reply_id, title, message):
|
||||||
for message in self._iter_messages(thread_id, True):
|
for message in self._iter_messages(thread_id, True):
|
||||||
self.queue_messages.append(message)
|
self.queue_messages.append(message)
|
||||||
return self.browser.post(thread_id, message)
|
with self.browser:
|
||||||
|
return self.browser.post(thread_id, message)
|
||||||
|
|
||||||
def get_profile(self, _id):
|
def get_profile(self, _id):
|
||||||
try:
|
try:
|
||||||
return self.browser.get_profile(_id)
|
with self.browser:
|
||||||
|
return self.browser.get_profile(_id)
|
||||||
except BrowserUnavailable:
|
except BrowserUnavailable:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
from logging import debug
|
from logging import debug
|
||||||
from random import randint
|
from random import randint
|
||||||
from weboob.tools.browser import BrowserUnavailable
|
from weboob.tools.browser import BrowserUnavailable
|
||||||
|
|
@ -42,7 +44,8 @@ class ProfilesWalker(object):
|
||||||
self.event = None
|
self.event = None
|
||||||
|
|
||||||
def walk(self):
|
def walk(self):
|
||||||
self.profiles_queue = self.profiles_queue.union(self.browser.search_profiles()).difference(self.visited_profiles)
|
with self.browser:
|
||||||
|
self.profiles_queue = self.profiles_queue.union(self.browser.search_profiles()).difference(self.visited_profiles)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def view_profile(self):
|
def view_profile(self):
|
||||||
|
|
@ -53,7 +56,8 @@ class ProfilesWalker(object):
|
||||||
return # empty queue
|
return # empty queue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
profile = self.browser.get_profile(id)
|
with self.browser:
|
||||||
|
profile = self.browser.get_profile(id)
|
||||||
debug(u'Visited %s (%s)' % (profile.get_name(), id))
|
debug(u'Visited %s (%s)' % (profile.get_name(), id))
|
||||||
|
|
||||||
# Get score from the aum_score module
|
# Get score from the aum_score module
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue