Example #1
0
File: cli.py Project: vreon/figment
def prompt(args):
    global prompt_quit

    zone = Zone.from_config(args.zone, args.world)

    while True:
        try:
            command = raw_input(PROMPT)
            if not command or command == 'quit':
                raise EOFError()
        except (EOFError, KeyboardInterrupt):
            sys.stdout.write('\n')
            sys.stdout.flush()
            prompt_quit = True
            break

        zone.enqueue_command(args.entity_id, command)

    sys.stdout.write('\033[m')
    sys.stdout.flush()
Example #2
0
File: cli.py Project: vreon/figment
def listen(args):
    zone = Zone.from_config(args.zone, args.world)
    subscription = zone.subscribe(args.entity_id)
    renderer = zone.renderer_class()

    while True:
        if prompt_quit:
            break

        message = subscription.get_message()
        if not message:
            sleep(0.01)
            continue

        rendered_message = renderer.render(json.loads(message['data']))

        sys.stdout.write(''.join([
            '\r', RESET, ERASE_DOWN, rendered_message, '\n',
            PROMPT, readline.get_line_buffer()
        ]))
        sys.stdout.flush()
Example #3
0
File: cli.py Project: vreon/figment
def run(args):
    if args.verbose or args.debug:
        log.setLevel(logging.DEBUG)

    try:
        zone = Zone.from_config(args.zone, args.world)

        if args.ticker:
            zone.start_ticker()
        else:
            zone.load_modules()
            zone.load_snapshot()
            zone.start()
    except (EOFError, KeyboardInterrupt):
        print()
    except Exception:
        if args.debug:
            import pdb
            import sys
            import traceback
            log.critical(traceback.format_exc())
            pdb.post_mortem(sys.exc_info()[2])
        else:
            raise