Source code for zot.bots.cli

# zot/bots/cli.py
#
#

""" basic package for the program. """

__copyright__ = "Copyright 2015, B.H.J Thate"

## IMPORTS

from zot.defines import BLA, GREEN, ENDC, pfc
from zot.errors import RemoteDisconnect
from zot.runtime import fleet, cfg
from zot.utils import short_date
from zot.object import Object
from zot.bot import BOT

import logging
import time
import sys

## CLI

[docs]class CLI(BOT): """ bot running on the console. """ cc = "" def _raw(zelf, *args, **kwargs): sys.stdout.write(args[0] + "\n") ; sys.stdout.flush()
[docs] def say(zelf, *args, **kwargs): zelf._raw(args[1])
[docs] def prompt(zelf, *args, **kwargs): zelf.wait() return "%s %s<%s " % (short_date(time.ctime(time.time())).split()[1], GREEN, ENDC)
[docs] def event(zelf, *args, **kwargs): event = Object() event._target = zelf event.origin = "root@shell" event.cc = zelf.cc zelf.ready() event.txt = input(zelf.prompt()) return event
[docs] def start(zelf, *args, **kwargs): fleet.append(zelf) if not cfg.shell: thrs = zelf.single(" ".join(cfg.runargs)) if thrs: zelf.collect(thrs) return BOT.start(zelf)