2 Define a few common arguments for client-side command-line tools.
11 class Client(common.Command):
13 Base class for XML-RPC command-line clients. It must be inherited and the
14 work() method overriden.
17 def __init__(self, subparsers=None):
18 super(Client, self).__init__(subparsers)
19 required_or_default = common.required_or_default
20 self.parser.add_argument('-H', '--host', metavar='HOST',
21 **required_or_default('HOST', 'the server host'))
22 self.parser.add_argument('-P', '--port', metavar='PORT',
23 **required_or_default('PORT', 'the server port'))
25 def execute(self, *args):
26 return self.object_proxy.execute(self.database, self.uid, self.password, *args)
29 self.host = self.args.host
30 self.port = int(self.args.port)
31 self.database = self.args.database
32 self.user = self.args.user
33 self.password = self.args.password
35 self.url = 'http://%s:%d/xmlrpc/' % (self.host, self.port)
36 self.common_proxy = xmlrpclib.ServerProxy(self.url + 'common')
37 self.object_proxy = xmlrpclib.ServerProxy(self.url + 'object')
40 self.uid = int(self.user)
42 self.uid = self.common_proxy.login(self.database, self.user, self.password)
48 def work(self, *args):
52 """Get the web client's URL to view a specific model."""
56 def __init__(self, subparsers=None):
57 super(Open, self).__init__(subparsers)
58 self.parser.add_argument('-m', '--model', metavar='MODEL',
59 required=True, help='the view type')
60 self.parser.add_argument('-v', '--view-mode', metavar='VIEWMODE',
61 default='tree', help='the view mode')
64 ids = self.execute('ir.actions.act_window', 'search', [
65 ('res_model', '=', self.args.model),
66 ('view_mode', 'like', self.args.view_mode),
68 xs = self.execute('ir.actions.act_window', 'read', ids, [])
70 print x['id'], x['name']
74 d['action_id'] = x['id']
75 print " http://%(host)s:%(port)s/web/webclient/home#action_id=%(action_id)s" % d
78 """Display a record."""
82 def __init__(self, subparsers=None):
83 super(Show, self).__init__(subparsers)
84 self.parser.add_argument('-m', '--model', metavar='MODEL',
85 required=True, help='the model')
86 self.parser.add_argument('-i', '--id', metavar='RECORDID',
87 required=True, help='the record id')
90 xs = self.execute(self.args.model, 'read', [self.args.id], [])
95 print "Record not found."
97 class ConsumeNothing(Client):
98 """Call test.limits.model.consume_nothing()."""
100 command_name = 'consume-nothing'
103 xs = self.execute('test.limits.model', 'consume_nothing')
105 class ConsumeMemory(Client):
106 """Call test.limits.model.consume_memory()."""
108 command_name = 'consume-memory'
110 def __init__(self, subparsers=None):
111 super(ConsumeMemory, self).__init__(subparsers)
112 self.parser.add_argument('--size', metavar='SIZE',
113 required=True, help='size of the list to allocate')
116 xs = self.execute('test.limits.model', 'consume_memory', int(self.args.size))
118 class LeakMemory(ConsumeMemory):
119 """Call test.limits.model.leak_memory()."""
121 command_name = 'leak-memory'
124 xs = self.execute('test.limits.model', 'leak_memory', int(self.args.size))
126 class ConsumeCPU(Client):
127 """Call test.limits.model.consume_cpu_time()."""
129 command_name = 'consume-cpu'
131 def __init__(self, subparsers=None):
132 super(ConsumeCPU, self).__init__(subparsers)
133 self.parser.add_argument('--seconds', metavar='INT',
134 required=True, help='how much CPU time to consume')
137 xs = self.execute('test.limits.model', 'consume_cpu_time', int(self.args.seconds))