Newer
Older
#!/usr/bin/env python
#coding=utf8
'''
'''
import os, os.path
import sys
from cccli import version, debug
from cccli.command import Command, Alias
from cccli.printer import Printer
from cccli.exception import *
from sjrpc.client import SimpleRpcClient
from sjrpc.utils import RpcHandler, ConnectionProxy, pure
sys.stdin = StringIO.StringIO(line)
# set interactive mode
self.interactive = sys.stderr.isatty() and sys.stdin.isatty()
self.printer.history.load(self.settings.get("history", ""))
self.printer.history.maxsize(self.settings.get("hsize", None))
# load alias
self.alias.load(self.settings.get("alias", ""))
# print debug
self.printer.debug("Interactive: %s"%self.interactive)
self.printer.debug("Loaded history: %s"%len(self.printer.history))
# Connecting
self._connect()
# authentifications
self._auth()
self.printer.history.save(self.settings.get("history", ""))
rpcc = SimpleRpcClient.from_addr(self.settings["server"],
self.settings["port"],
on_disconnect="quit",
if self.rpc.authentify(self.settings["login"], self.settings["pass"]):
def _parse(self):
'''Parse a line'''
prompt = "> " if self.interactive else ""
argv = shlex.split(self.printer.getline(prompt), comments=True)
# alias subsitution
if argv[0] in self.alias:
argv[0] = self.alias[argv[0]]
except ValueError, e:
self.printer.error("Lexer: %s"%str(e))
continue
except EOFError:
break
except SystemExit:
break
except KeyboardInterrupt:
self._exec_command(argv)
if self.interactive:
self.printer.out("tcho!")
def _exec_command(self, argv):
'''Execute command'''
try:
if (argv[0] == "!"):
p = subprocess.Popen(argv[1:], close_fds=True, shell=True)
class CliHandler(RpcHandler):
'''Handle RPC incoming request'''
@pure
def get_tags(self, tags=()):
if "version" in tags:
@pure
def quit(self, rpc=None):