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

addacount now take a password argument and so use TqlCommand

parent 747dfb55
No related branches found
No related tags found
No related merge requests found
......@@ -10,20 +10,30 @@ from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command.command import OptionCommand, TqlCommand
class Command_addaccount(OptionCommand):
class Command_addaccount(TqlCommand):
'''Create an account'''
def __init__(self, cli, argv0):
OptionCommand.__init__(self, cli, argv0)
self.set_usage("%prog [options] <account name> <role>")
TqlCommand.__init__(self, cli, argv0)
self.set_usage("%prog [options] <account name> <role> [password]")
def __call__(self, argv):
# parse args
self.parse_args(argv)
if len(self.args) != 2:
if len(self.args) == 2:
_pass = None
elif len(self.args) == 3:
_pass = self.args[2]
if self.printer.isinteractive():
self.printer.warn("Removing last line from history")
self.printer.history.removelast()
else:
raise cmdBadArgument()
# execute command
self.rpccall("addaccount", self.args[0], self.args[1])
# add account
self.rpccall("addaccount", self.args[0], self.args[1], _status=False)
# set password
if _pass is not None:
self.rpccall("passwd", "a=%s"%self.args[0], _pass)
class Command_delaccount(TqlCommand):
......
......@@ -94,15 +94,23 @@ class TqlCommand(OptionCommand):
def rpccall(self, *args, **kwargs):
'''Call a RPC method an show tql return'''
# check for status printing
if "_status" in kwargs:
_status = kwargs["_status"]
del kwargs["_status"]
elif self.options.status:
_status = True
else:
_status = False
# Do RPC Call
try:
d = self.rpc.call(*args, **kwargs)
if self.options.status:
if _status:
self.show_status(d)
return d
except RpcError as e:
raise cmdError("RPCError: %s"%str(e))
def show_status(self, ans):
'''Show status of an Tql request'''
try:
......
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