Esempio n. 1
0
    def __init__(self, name=None, logfunc=None, user=None, **kwds):
        wx.App.__init__(self, redirect=False, **kwds)

        self.Bind(EVT_PIA_SERVICE, self.__service_ctx)
        self.Bind(EVT_PIA_ASYNC, self.__service_async)

        self.mgr = piagent.scaffold_gui(utils.notify(self.__service),
                                        utils.notify(self.__service_shutdown),
                                        utils.stringify(logfunc),
                                        utils.stringify(None), False, False)

        self.__env_bg = self.mgr.bgcontext('main', utils.statusify(None),
                                           utils.stringify(logfunc), name
                                           or 'App')
        self.__env_fg = self.mgr.context('main', utils.statusify(None),
                                         utils.stringify(logfunc), name
                                         or 'App')

        piw.setenv(self.__env_fg.getenv())

        self.__stdio = (sys.stdout, sys.stderr)
        sys.stdout = session.Logger()
        sys.stderr = sys.stdout

        self.__thing = piw.thing()
        self.__thing.set_slow_trigger_handler(utils.notify(self.__trigger))
        self.__queue = []
        self.__lock = picross.mutex()

        self.run_bg_sync(self.__setup)
Esempio n. 2
0
    def setUp(self):
        self.context = self.manager.context(utils.notify(None),
                                            utils.stringify(self.logger),
                                            'test')
        piw.setenv(self.context.getenv())

        if self.logger is not None:
            self.oldstd = sys.stdout, sys.stderr
            sys.stdout, sys.stderr = self.logger.Logger(), sys.stdout
Esempio n. 3
0
 def __main(env,name,ordinal,enclosure,mordinal):
     piw.setenv(env)
     root = klass(name,ordinal)
     piw.tsd_server(name,root)
     root.advertise('<main>')
     if enclosure:
         root.set_enclosure(enclosure)
     if mordinal:
         root.set_ordinal(int(mordinal))
     return root
Esempio n. 4
0
    def run(self):
        piw.setenv(self.context.getenv())
        gc.disable()

        while True:
            for p in self.passes():
                self.event1.wait(self.delay)
                self.event1.clear()
                if not self.running:
                    break
                self.run_pass(p)
Esempio n. 5
0
 def run_bg_sync(self,func,*args,**kwds):
     s = piw.tsd_snapshot()
     try:
         piw.setenv(self.__env_bg.getenv())
         piw.tsd_lock()
         try:
             return func(*args,**kwds)
         finally:
             piw.tsd_unlock()
     finally:
         s.install()
Esempio n. 6
0
    def __run(self,func,*args,**kwds):
        current_context = piw.tsd_snapshot()

        try:
            piw.setenv(self.context.getenv())
            piw.tsd_lock()
            try:
                return func(*args,**kwds)
            finally:
                piw.tsd_unlock()
        finally:
            current_context.install()
Esempio n. 7
0
def run_session(session,
                user=None,
                mt=1,
                name='ctx',
                logger=None,
                clock=True,
                rt=True):
    def logfunc(msg):
        if logger:
            logger(msg)
        else:
            print

    context = None

    def ctxdun(status):
        context.release()

    scaffold = piagent.scaffold_mt(mt, utils.stringify(logfunc),
                                   utils.stringify(None), clock, rt)
    context = scaffold.context('main', utils.statusify(ctxdun),
                               utils.stringify(logfunc), name)
    stdio = (sys.stdout, sys.stderr)
    x = None

    try:
        if logger:
            sys.stdout = Logger()
            sys.stderr = sys.stdout

        piw.setenv(context.getenv())
        piw.tsd_lock()

        try:
            x = session(scaffold)
            context.trigger()
        finally:
            piw.tsd_unlock()

        scaffold.wait()

    finally:
        sys.stdout, sys.stderr = stdio

    return x
Esempio n. 8
0
 def __main(env, name, ordinal):
     piw.setenv(env)
     root = klass(name, ordinal)
     piw.tsd_server(name, root)
     root.advertise('<main>')
     return root
Esempio n. 9
0
 def __service_ctx(self,evt):
     self.mgr.process_ctx()
     piw.setenv(self.__env_fg.getenv())