~openerp-dev/openobject-server/trunk-bug-1098300-dhr

« back to all changes in this revision

Viewing changes to openerpcommand/call.py

  • Committer: Vo Minh Thu
  • Date: 2013-01-11 13:46:57 UTC
  • Revision ID: vmt@openerp.com-20130111134657-im2f3uqjluyo4pm6
[ADD] oe: provides sane (unfucked) command-line interface.

The implementation is far from perfect. Some improvements are waiting in
its previous location: lp:~openerp/openerp-command.

Some docs are provided, see doc/openerp-command.rst and
doc/adding-command.rst.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Call an arbitrary model's method.
 
3
"""
 
4
import ast
 
5
import os
 
6
import pprint
 
7
import sys
 
8
import time
 
9
import xmlrpclib
 
10
 
 
11
import client
 
12
 
 
13
class Call(client.Client):
 
14
    """\
 
15
    Call an arbitrary model's method.
 
16
 
 
17
    Example:
 
18
      > oe call res.users.read '[1, 3]' '[]' -u 1 -p admin
 
19
    """
 
20
    # TODO The above docstring is completely borked in the
 
21
    # --help message.
 
22
 
 
23
    command_name = 'call'
 
24
 
 
25
    def __init__(self, subparsers=None):
 
26
        super(Call, self).__init__(subparsers)
 
27
        self.parser.add_argument('call', metavar='MODEL.METHOD',
 
28
            help='the model and the method to call, using the '
 
29
            '<model>.<method> format.')
 
30
        self.parser.add_argument('args', metavar='ARGUMENT',
 
31
            nargs='+',
 
32
            help='the argument for the method call, must be '
 
33
            '`ast.literal_eval` compatible. Can be repeated.')
 
34
 
 
35
    def work(self):
 
36
        try:
 
37
            model, method = self.args.call.rsplit('.', 1)
 
38
        except:
 
39
            print "Invalid syntax `%s` must have the form <model>.<method>."
 
40
            sys.exit(1)
 
41
        args = tuple(map(ast.literal_eval, self.args.args)) if self.args.args else ()
 
42
        x = self.execute(model, method, *args)
 
43
        pprint.pprint(x, indent=4)
 
44