Use the command line (SSH) to query the Gerrit, official address: https://review.openstack.org/Documentation/cmd-query.html
Program examples
Import OS, JSON def Get_patch_info (Gerrit_home, patch_id): cmd_str='ssh%s GERRIT query--format=json-- Comments change:%d'%(gerrit_home, patch_id) = os.popen (cmd_str) # See note process.close () = json.loads (output) # return is dict return Jsn_data
Description: The query result will always return more than one row of query statistics on the last line, even if the query result is empty:
{"Morechanges": false, "runtimemilliseconds":, "RowCount": 1, "type": "Stats"}
If you use the shell, you can use JQ for parsing. JQ is able to format and select JSON results.
Install sudo apt-get install JQ
SSH review.example.com Gerrit Query--format=json--patch-sets--files change:89535 | JQ. > 89535-pretty.txtssh review.example.com Gerrit Query--format=json--patch-sets--files change:89535 > 89535-Pretty.txtcat89535-pretty.txt |JQ. Cat89535-pretty.txt | Jq". Status" #Remove the status of the patchCat89535-pretty.txt | Jq". Patchsets[0].files" #Remove the first Patchset modified file informationCat89535-pretty.txt | Jq"Keys" #List all keysCat89535-pretty.txt | Jq"Has (' owner ')" #whether the key exists
The following transfers are from: http://blog.chinaunix.net/uid-24774106-id-3830242.html
JSON-related I briefly introduced here, I hope to further understand the JQ and use can go to http://stedolan.github.io/jq/manual/, hope to understand the source of implementation, you can go to https://github.com/ STEDOLAN/JQ, it is expected that the author used flex and bison to parse json.
Our sample JSON comes from the first article in the reference document.
With Google search, there is an article in Kernalpanic about Jshon and json.sh provide additional ideas.
Reference documents:
1 How to parse JSON string via command line on Linux
2 Jq-command-line JSON processor
Get patch information from Gerrit using SSH