X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/de32d0c699858b1502f5f1e793174db8b56f9c1b..fbafb27f249fec2d9ff2967cf50c26aadc2ef4fb:/testtester.py diff --git a/testtester.py b/testtester.py index 4e7f951..96356c8 100644 --- a/testtester.py +++ b/testtester.py @@ -1,28 +1,49 @@ #!/usr/bin/python # vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : +#{{{ TG config/hacks import turbogears import turbogears.database turbogears.update_config(configfile="dev.cfg", modulename="sercom.config") -from sercom.tester import * -from sercom import model -from Queue import Queue - -queue = Queue() - -queue.put(1) -#queue.put(5) -queue.put(None) - -tester = Tester(name='pepe', path='var', home=os.path.join('home', 'sercom'), - queue=queue) +import turbogears.i18n +__builtins__._ = turbogears.i18n.plain_gettext # Nada de gettext lazy +#}}} + +from sercom.tester import Tester +from sercom.model import Entrega, hub +from os.path import join +from datetime import datetime +import time +import logging + +log = logging.getLogger('sercom.tester') + +class Queue(object): + def __init__(self): + self.go_on = True + def get(self): + while self.go_on: + try: + hub.begin() + try: + e = Entrega.selectBy(inicio=None).orderBy(Entrega.q.fecha)[0] + e.inicio = datetime.now() + finally: + hub.commit() + return e.id + except IndexError: + log.debug(_(u'No hay entregas pendientes')) + time.sleep(10) # TODO config? + except Exception, e: + if isinstance(e, SystemExit): + raise + log.exception('Queue: ') + time.sleep(10) # TODO config? + return None + +q = Queue() + +tester = Tester(name='pepe', path='var', home=join('home', 'sercom'), queue=q) tester.run() -model.hub.rollback() -#model.hub.commit() - -#model.hub.begin() -#model.Entrega.get(5).correcta = True -#model.hub.rollback() -