Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
#coding=utf8
'''
CloudControl right releated commands
'''
from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command.command import Command
from optparse import OptionParser
class Command_rights(Command):
'''List account rights (current by default)'''
def __call__(self, argv):
# Parse argline
try:
oparser = OptionParser(prog=argv[0])
oparser.add_option("--raw", action="store_true", dest="raw",
help="Don't append filter on request")
(options, args) = oparser.parse_args(argv[1:])
except SystemExit:
return
# append current login if nothing asked
if len(args) == 0:
tql = "a=%s"%self.cli.settings["login"]
else:
tql = "".join(args)
# update tql if mode
if not options.raw:
tql += "&a"
# ask server
try:
al = self.cli.rpc.call("rights", tql)
except RpcError as e:
raise cmdError("RPCError: %s"%str(e))
# display answer
for (a, rl) in al.items():
self.printer.out("%srights of %s%s"%(color["lblue"], a, color["reset"]))
for i,r in enumerate(rl):
tags = " ".join([ "%s%s:%s%s"%(color["green"], t, color["reset"], v) for (t,v) in r.items() ])
self.printer.out("[%s] %s"%(i,tags))
def usage(self):
return "usage: rights [--raw] [--help] [tql]"
class Command_addright(Command):
'''Add/edit a right'''
def __call__(self, argv):
if len(argv) != 5:
raise cmdBadArgument()
try:
self.cli.rpc.call("addright", argv[1], argv[2], argv[3], argv[4])
except RpcError as e:
raise cmdError("RPCError: %s"%str(e))
def usage(self):
return "usage: addright <tql> <right tql> <method> <target>"
class Command_delright(Command):
'''Delete a right'''
def __call__(self, argv):
if len(argv) != 3:
raise cmdBadArgument()
try:
self.cli.rpc.call("delright", argv[1], int(argv[2]))
except RpcError as e:
raise cmdError("RPCError: %s"%str(e))
def usage(self):
return "usage: delright <account> <index>"