Example #1
0
 def on_connect(self):
     global conn_seq
     conn_seq += 1
     self.name = self.dest + ("n" + str(conn_seq), )
     self.ctx = Context()
     self.ctx.out = Reporter(self)
     self.ctx.words = global_words(self.ctx)
     self.workers = set()
     simple_event("rpc", "connect", *self.name)
     Collected.__init__(self)
Example #2
0
 def _init(self, bus, short_id=None, id=None, path=()):
     log("onewire", DEBUG, "NEW", bus, short_id, id, path)
     self.bus_id = id
     if short_id:
         self.id = short_id.lower()
     self.bus = bus
     assert path is not None
     self.path = path
     self.is_up = None
     self.ctx = Context()
Example #3
0
    def __init__(self, event, worker):
        super(WorkSequence, self).__init__()
        self.work = []
        self.event = event
        self.worker = worker
        #		if hasattr(event,"id"):
        #			self.id = self.event.id
        if hasattr(event, "ctx"):
            self.ctx = event.ctx()
        else:
            self.ctx = Context()

        if isinstance(self.event, Event):
            en = SName(self.event)
        else:
            en = six.text_type(self.event)
        self.info = u"Worker %d for ‹%s›" % (self.id, en)
Example #4
0
def ready():
    c = Context()
    for f in sys.argv[1:]:
        parse(f, ctx=c)

    #c.logger=parse_logger
    if os.isatty(0):
        i = InteractiveInterpreter
    else:
        i = Interpreter
    print("""Ready. Type «help» if you don't know what to do.""")
    try:
        parse(sys.stdin, interpreter=i, ctx=c)
    except Exception as e:
        fix_exception(e)
        reporter(e)
    shut_down()
Example #5
0
    def __init__(self, input, interpreter, ctx=None):
        """Parse an input stream and pass the commands to the processor @proc."""
        global _npars
        _npars += 1
        super(Parser, self).__init__("n" + str(_npars))

        self.ending = False

        if ctx is None:
            self.ctx = Context()
        else:
            self.ctx = ctx

        if "filename" not in self.ctx:
            self.ctx.filename = u"‹stdin?›"
        self.input = input
        self.proc = interpreter
        self.do_prompt = interpreter.do_prompt
Example #6
0
    def __init__(self, *name):
        if not name:
            name = self.name
        if not name:
            raise RuntimeError("Unnamed object of '%s'" %
                               (self.__class__.__name__, ))

        if self.storage is None:
            raise RuntimeError("You didn't declare a storage for '%s'" %
                               (self.__class__.__name__, ))

        self.name = name = SName(name)
        if name in self.storage:
            self.dup_error(name)

        super(Collected, self).__init__()
        self.storage[name] = self
        self._ectx = Context()
Example #7
0
    def __init__(self, ctx, *name):
        """\
			Events have a context and at least one name. For example:
				Event(ctx, "startup")
				Event(ctx, "switch","toggle","sw12")
				Event(ctx, "switch","dim","livingroom","lamp12")
				Event(ctx, "timer","timeout","t123")
			"""
        self._name_check(name)
        #print("E_INIT",name,"with",ctx)
        self.name = Name(name)
        self.ctx = ctx if ctx is not None else Context()
        if "loglevel" in self.ctx:
            self.loglevel = ctx.loglevel
        self.timestamp = now()

        global event_id
        event_id += 1
        self.id = event_id
Example #8
0
    def _command(self, args=(), sub=(), **kwargs):
        ctx = Context(**kwargs)
        ctx.out = Reporter()
        ctx.words = global_words()  # self.ctx)

        try:
            if sub:
                cmd = CommandProcessor(parent=self, ctx=ctx)
                proc = cmd.complex_statement(args)
                for s in sub:
                    proc.simple_statement(s)
                proc.done()
                cmd.run()
            else:
                CommandProcessor(parent=self, ctx=ctx).simple_statement(args)
        except Exception as e:
            fix_exception(e)
            process_failure(e)
            reraise(e)
        return ctx.out.data
Example #9
0
##  (at your option) any later version.
##
##  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 (included; see the file LICENSE)
##  for more details.
##
##  This header is auto-generated and may self-destruct at any time,
##  courtesy of "make update". The original is in ‘scripts/_boilerplate.py’.
##  Thus, do not remove the next line, or insert any blank lines above.
##BP

from moat.context import Context, default_context

c = Context()
assert not c._store
assert not c
c.foo = "bar"
assert c
assert c.foo == "bar"

d = c(bla="fasel")
assert d.bla == "fasel"
assert d.foo == "bar"
try:
    c.bla
except AttributeError:
    pass
else:
    assert False
Example #10
0
	def __init__(self,parent=None, ctx=None):
		self.name = SName(self.name)
		self.parent = parent
		self.ctx = ctx or Context()
		self.args = None
Example #11
0
	def __init__(self, parent=None, ctx=None):
		self.ctx = ctx or Context()
		self.parent = parent
Example #12
0
 wait_for_all_threads
from moat.collect import Collection, Collected

import gevent
import aiogevent
import asyncio
import qbroker
qbroker.setup(gevent=True)
from qbroker.util. async import Main as _Main

__all__ = ("start_up", "shut_down", "startup_event", "shutdown_event",
           "ShutdownHandler", "mainloop", "Events")

Main = None

startup_event = Event(Context(startup=True), "startup")
shutdown_event = Event(Context(shutdown=True), "shutdown")

active_q_id = 0
running = False
stopping = False


class Events(Collection):
    name = "event"


Events = Events()


class Shutdown_Worker(Worker):
Example #13
0
 def __init__(self):
     self.ctx = Context()