Skip to content
Snippets Groups Projects
Commit 5e43cff7 authored by Seblu's avatar Seblu
Browse files

Bug fixes

 * command ? traceback
 * display warning report bug
 * traceback when no alias
 * traceback when no pass
 * argline was not parsed correctly
 * bad displaying of usage
 * fix lots of traceback with options handling
 * fix displaying of help
 * implement timeout on sjrpc connection and add timeout param (need v6)
parent 1dc65dcb
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ import os, os.path
import sys
import cccli
from cccli import printer,cli
from cccli.clierror import *
import optparse
import ConfigParser
import pprint
......@@ -16,16 +17,20 @@ import re
import warnings
import getpass
settings = {}
settings = {
"port": "1984",
"timeout": "5"
}
try:
# parse rc file
if "HOME" in os.environ and os.access("%s/.cc-cli.conf"%os.environ["HOME"], os.R_OK):
fparser = ConfigParser.SafeConfigParser()
fparser.read("%s/.cc-cli.conf"%os.environ["HOME"])
if "HOME" in os.environ:
settings["alias"] = "%s/.cc-cli.conf"%os.environ["HOME"]
if fparser.has_section("cli"):
settings.update(fparser.items("cli"))
if os.access("%s/.cc-cli.conf"%os.environ["HOME"], os.R_OK):
fparser = ConfigParser.SafeConfigParser()
fparser.read("%s/.cc-cli.conf"%os.environ["HOME"])
if fparser.has_section("cli"):
settings.update(fparser.items("cli"))
# parse env
if "CC_SERVER" in os.environ:
......@@ -62,25 +67,23 @@ try:
dest="port",
default="1984",
help="server port")
oparser.add_option("-t", "--timeout",
action="store",
dest="timeout",
default="10",
help="connection timeout")
(options, args) = oparser.parse_args()
# options handling
for i in ("debug", "login", "server", "port"):
for i in ("debug", "login", "server", "port", "timeout"):
if hasattr(options, i):
o = getattr(options, i)
if o != "":
if o:
settings[i] = o
# show usage if no default conf and no server given
if "login" not in settings or "server" not in settings:
oparser.print_help()
sys.exit(1)
# remove pass to prevent stupid guy
#if "pass" in settings:
# del settings["pass"]
# debug stuff
if "debug" in settings:
cccli.debug = bool(settings["debug"])
......@@ -89,30 +92,42 @@ try:
printer.debug("Debugging on")
printer.debug("Settings: %s"%settings)
# checking needs
if settings["server"] == "":
raise Exception("Invalid server name/ip")
# checking server name
if "server" not in settings:
raise BadArgument("No server address")
# check port value
try:
settings["port"] = int(settings["port"])
except:
raise Exception("Invalid port number")
raise BadArgument("Invalid port number")
# asking for login
if settings["login"] == "":
# check timeout value
try:
settings["timeout"] = int(settings["timeout"])
except:
raise BadArgument("Invalid timeout")
# check login
if "login" not in settings:
settings["login"] = raw_input("Login: ")
# asking for password
if settings["pass"] == "":
# check password
if "pass" not in settings:
settings["pass"] = getpass.getpass("Password: ")
# start cli
cli = cli.Cli(settings, args)
cli.start()
except BadArgument, e:
printer.error("Bad Argument: %s"%str(e))
oparser.print_help()
except KeyboardInterrupt:
exit(1)
except Exception, e:
if cccli.debug:
printer.fatal(str(e), exitcode=-1)
printer.warn("This is a not expected error, please report it!")
raise
printer.warn("This is a not expected error, please report it!")
printer.fatal(str(e))
......@@ -24,12 +24,10 @@ import re
import readline
class Cli(object):
def __init__(self, settings, args):
self._settings = settings
if "alias" in settings:
self.alias = Alias(settings["alias"])
self.alias.load()
self.alias = Alias(settings.get("alias", ""))
self.alias.load()
self._interactive = sys.stderr.isatty() and sys.stdin.isatty()
self._prompt = "> "
self._commands = args
......@@ -44,7 +42,7 @@ class Cli(object):
# run parsing args
if len(self._commands) > 0:
for c in self._commands:
self._parse(c)
self._parse_line(c)
elif self._interactive:
self._interactive_parser()
else:
......@@ -53,9 +51,10 @@ class Cli(object):
def _connect(self):
printer.debug("Connecting...")
rpcc = SimpleRpcClient.from_addr(self._settings["server"],
self._settings["port"],
enable_ssl=True,
on_disconnect=self._on_disconnect
self._settings["port"],
enable_ssl=True,
on_disconnect=self._on_disconnect,
timeout=self._settings["timeout"]
)
rpcc.start(daemonize=True)
self.rpc = ConnectionProxy(rpcc)
......@@ -108,7 +107,7 @@ class Cli(object):
p.wait()
ret = p.returncode
elif (cmd[0] == "?"):
Command("help").call()
Command(["help"], self).call()
else:
self._parse_command(cmd)
......@@ -145,7 +144,6 @@ class Cli(object):
'''Lex command argument'''
return string.split(" ")
class Alias(dict):
''' Alias wrapper'''
def __init__(self, filename):
......
......@@ -15,7 +15,7 @@ class Command(object):
raise BadCommand()
# check valid command chars
if not re.match("^[a-zA-Z0-9]+", argv[0]):
raise BadCommmand("Invalid command name")
raise BadCommand("Invalid command name")
cmdlist = [ x[4:] for x in dir(self) if x.startswith("cmd_") ]
matchlist = [ x for x in cmdlist if re.match("%s.+"%argv[0], x) ]
if argv[0] in cmdlist:
......
......@@ -9,7 +9,7 @@ Standards-Version: 3.8.0
Package: cc-cli
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}, python (<< 3), python-sjrpc (>= 5)
Depends: ${misc:Depends}, ${python:Depends}, python (<< 3), python-sjrpc (>= 6)
XB-Python-Version: ${python:Versions}
Description: CloudControl CLI
This package provides the Command Line Interface to CloudControl.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment