Commit 3393fb73 authored by Romain Bignon's avatar Romain Bignon

abstraction on scheduler

parent e66f47e3
......@@ -57,9 +57,11 @@ class Backend:
raise Backend.ConfigError("Value of '%s' does not match regexp '%s'" % (name, field.regexp))
if not field.default is None:
if isinstance(field.default, int):
if isinstance(field.default, bool):
value = value.lower() in ('1', 'true', 'on', 'yes')
elif isinstance(field.default, int):
value = int(value)
if isinstance(field.default, float):
elif isinstance(field.default, float):
value = float(value)
self.config[name] = value
......
......@@ -22,7 +22,6 @@ import re
from weboob.capabilities.bank import Account
from weboob.tools.browser import BasePage
from weboob.tools.parser import tostring
class AccountsList(BasePage):
LINKID_REGEXP = re.compile(".*ch4=(\w+).*")
......
......@@ -84,7 +84,7 @@ class Article(object):
date_s = unicode(subdivs[1].text)
else:
date_s = unicode(div.find('i').tail)
print date_s
#print date_s
if div.attrib.get('class', '').startswith('bodydiv '):
self.body = tostring(div)
......
......@@ -48,7 +48,7 @@ class Monboob(BaseApplication):
self.weboob.load_backends(ICapMessages)
self.weboob.schedule(self.config.get('interval'), self.process)
self.weboob.repeat(self.config.get('interval'), self.process)
self.weboob.loop()
def process(self):
......
......@@ -19,20 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import os
import sched
import time
from weboob.modules import ModulesLoader
from weboob.scheduler import Scheduler
class Weboob:
WORKDIR = os.path.join(os.path.expanduser('~'), '.weboob')
BACKENDS_FILENAME = 'backends'
def __init__(self, app_name, workdir=WORKDIR):
def __init__(self, app_name, workdir=WORKDIR, scheduler=None):
self.app_name = app_name
self.workdir = workdir
self.backends = {}
self.scheduler = sched.scheduler(time.time, time.sleep)
if scheduler is None:
scheduler = Scheduler()
self.scheduler = scheduler
self.modules_loader = ModulesLoader()
self.modules_loader.load()
......@@ -54,7 +56,10 @@ class Weboob:
yield (name, backend)
def schedule(self, interval, function, *args):
self.scheduler.enter(interval, 1, function, args)
return self.scheduler.schedule(interval, function, *args)
def repeat(self, interval, function, *args):
return self.scheduler.repeat(interval, function, *args)
def loop(self):
self.scheduler.run()
return self.scheduler.run()
# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import sched
import time
class Scheduler(object):
def __init__(self):
self.scheduler = sched.scheduler(time.time, time.sleep)
self.running = False
def schedule(self, interval, function, *args):
return self.scheduler.enter(interval, 1, function, args)
def repeat(self, interval, function, *args):
return self.scheduler.enter(interval, 1, self._repeated_cb, (interval, function, args))
def run(self):
self.running = True
while self.running:
self.scheduler.run()
return True
def want_stop(self):
self.running = False
def _repeated_cb(self, interval, func, args):
func(*args)
self.repeat(interval, func, *args)
......@@ -33,9 +33,7 @@ except ImportError:
class HTMLTreeBuilder(HTMLParser):
def __init__(self, encoding=None):
HTMLParser.__init__(self)
if target is None:
target = ElementTree.TreeBuilder()
self._target = target
self._target = ElementTree.TreeBuilder()
def doctype(self, name, pubid, system):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment