← Back to team overview

openerp-dev team mailing list archive

Re: how to access/print selection base values, aka BQI usage

 

On Wednesday 05 January 2011, you wrote:
> Thank you
> I proceeded as proposed, have installed the scripts and rc and can start up
> # bqi inter
> # orm account.account
> INFO:web-service:successful login from 'admin' using database
> 'chricar5_1229' # BQI account.account> print [x[0] for x in
> type['selection']]
> Exception: 'type' object is unsubscriptable
(in this particular case, there was no "type" field of any result, so the 
builtin 'type' was accessed)
> Result:
> null
> 
> I think I miss something
Yes, you have missed some command, before the "print" that would fetch any 
results in the local dict.

At my previous example, I had a step like:
   BQI> do fields_get(['type'])
.. which fetches some data from the server.

> BTW
> BQI account.account> obj_info
> Currently at: account.account
> BQI account.account>
> ...
> it would be nice to optionally get a more detailed info
> * alphabatically sorted columns with attributes
> * defaults
> * constraints
> * available methods
> 
> allow to specify user/password at login (especially individual admin
> password)

Let me start by saying that all command options are listed in the "--help" 
invocation (as expected).
Also, all commands of the interactive mode are listed with the "help" command 
too.
I wrote this script in a way that I would avoid too much code, it was always 
supposed to be used by developers, so excuse me if it's not very user 
friendly.

Most commands do have Tab-completion, so they will present some interesting 
stuff when you press that key. For example, the "orm" commands completes all 
available models (through a ir.model.search() call), while the "module 
upgrade" command completes with all modules /that have appeared in logs/ ;) .

A little background of the RPC calls:
The "do" command is just a straight [1] call of RPC methods on the 
corresponding orm object. Any function-like expression after the 'do' will be 
evaled and sent to the server. 
Note 1: RPC calls don't have (cr, uid, ...) but just the other arguments.
Note 2: so far, you _cannot_ use keyword arguments[2] and also foo(a, b=1) 
will not be accepted by the BQI.
Note 3: XML-RPC doesn't accept None as a value, we use False mostly
Note 4: the names and syntax of functions will therefore be like the code you 
see in the server. No special processing at the BQI end, from "do ".

Then, the result of the "do" command will be stored at a variable at the BQI, 
available to the "print", "with" commands, as well as /subsequent/ "do" or 
"table" commands.
The exact pythonic result of any "do" or "with" command is stored in a name 
called "this". Also, if the result is a dictionary, items of that dictionary 
will be stored in corresponding items, for easier access.

Note also that there is an orm.res_id mode, where each "do" command will 
automatically take the [res_id,] as a first argument.

Example:
BQI> orm res.users
BQI res.users> do read([1,2])
Res is a <type 'list'>. Use the print cmd to inspect it.
BQI res.users> print this
... the whole thing
BQI res.users> print this[0]
.... the first result
BQI res.users> print @0
.... equivalent syntax
BQI res.users> with @0
... let  this = this[0]   , now a dict
BQI res.users> print <Tab>
.... will complete with keys of the dict
BQI res.users> print login
Result:
"admin"
BQI res.users> print login, id, active
Result:
[
    "admin", 
    1, 
    true
]
BQI res.users> print company_id[1]
Result:
"OpenERP Corp."

BQI res.users> do search([])
Res: [1, 13, 9, 3, 14, 11, 12, 21, 17, 19, 20, 18, 8, 10]
BQI res.users>do read(this)  
  # see? you use "this" to reuse your result
Res is a <type 'list'>. Use the print cmd to inspect it.
BQI res.users> table id, login, name from this
id|    login    |        name       
------------------------------------
1 |admin        |Administrator      
13|apr          |Aline              
9 |al           |Anthony    

BQI res.users> ^D 
 ... exit the "inter" command, and since there is no other, stop the server.

You may discover more pythonic ways to write expressions for the "do", "with", 
"print" or "table" commands. I can only tell you that I use eval() and then 
you can use your experience to play around.
....

 Note also that BQI will always keep the log (like the one you see at console) 
in a text file, for further inspection. The format of the file need not be the 
same as the plain text of the console, neither will it have color. Please, 
search for the keyword "blame" to find the recognized errors in those logs.


[1] I needed to have some word before the RPC name, in order to keep the 
cmdline and completion interactive. Hence the "do ..." syntax.
[2] todo for v6.1 of the RPC layer.