Example #1
0
def run(name, input, interpreter=Interpreter, logger=None):
    global ht
    if logger is None:
        ht = run_logger(name, dot=False)
        logger = ht.log
    if isinstance(input, six.string_types):
        input = input.encode("utf-8")
    if isinstance(input, bytes):
        input = input.decode('utf-8')
    input = StringIO(input)

    def _main():
        global ht
        parse_ctx = Context(filename=name)
        #parse_ctx.logger=parse_logger
        try:
            parse(input, interpreter(Context(out=logwrite(logger))), parse_ctx)
        except Exception as e:
            fix_exception(e)
            print_exception(e, file=sys.stderr)
        finally:
            shut_down()
            if ht is not None:
                ht.try_exit()
                ht = None

    mainloop(_main)
    if ht is not None:
        ht.try_exit()

    sys.exit(exitcode)
Example #2
0
def run(name,input, interpreter=Interpreter, logger=None):
	global ht
	if logger is None:
		ht = run_logger(name,dot=False)
		logger = ht.log
	if isinstance(input,six.string_types):
		input = input.encode("utf-8")
	if isinstance(input,bytes):
		input = input.decode('utf-8')
	input = StringIO(input)

	def _main():
		global ht
		parse_ctx = Context(filename=name)
		#parse_ctx.logger=parse_logger
		try:
			parse(input, interpreter(Context(out=logwrite(logger))),parse_ctx)
		except Exception as e:
			fix_exception(e)
			print_exception(e,file=sys.stderr)
		finally:
			shut_down()
			if ht is not None:
				ht.try_exit()
				ht = None

	mainloop(_main)
	if ht is not None:
		ht.try_exit()

	sys.exit(exitcode)
Example #3
0
File: main.py Project: smurfix/MoaT
	print("Error:",err)
	
def looper():
	while True:
		print("L")
		sleep(1)

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()

from gevent import spawn,sleep
#spawn(looper)
callLater(False,0.1,ready)
mainloop()

Example #4
0
##  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.database import DbStore
from moat.base import Name
from moat.reactor import shut_down,mainloop

s = DbStore(Name("Foo","bar"))
def main():
	s.clear()
	s.set("one",4)
	s.set(("two","three"),(4,5,6))

	def getter(a,b):
		_ = s.get(a)
		assert _ == b, "Check CallBack %r %r %r" % (_,a,b)
	getter("one",4)
	getter(("two","three"),(4,5,6))
	s.set("one",2)
	getter("one",2)

	shut_down()

mainloop(main)

Example #5
0
def looper():
    while True:
        print("L")
        sleep(1)


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()


from gevent import spawn, sleep
#spawn(looper)
callLater(False, 0.1, ready)
mainloop()