Monty Taylor | f45f6ca | 2012-05-01 17:11:48 -0400 | [diff] [blame] | 1 | import argparse |
| 2 | import paramiko |
| 3 | import json |
| 4 | |
| 5 | parser = argparse.ArgumentParser() |
| 6 | parser.add_argument("--host", dest="host", default="review.openstack.org", |
| 7 | help="gerrit host to connect to") |
| 8 | parser.add_argument("--port", dest="port", action='store', type=int, |
| 9 | default=29418, help="gerrit port to connect to") |
| 10 | parser.add_argument("groups", nargs=1) |
| 11 | |
| 12 | options = parser.parse_args() |
| 13 | |
| 14 | |
| 15 | client = paramiko.SSHClient() |
| 16 | client.load_system_host_keys() |
| 17 | client.set_missing_host_key_policy(paramiko.WarningPolicy()) |
| 18 | client.connect(options.host, port=options.port) |
| 19 | |
| 20 | group = options.groups[0] |
| 21 | query = "select group_uuid from account_groups where name = '%s'" % group |
| 22 | command = 'gerrit gsql --format JSON -c "%s"' % query |
| 23 | stdin, stdout, stderr = client.exec_command(command) |
| 24 | |
| 25 | for line in stdout: |
| 26 | row = json.loads(line) |
| 27 | if row['type'] == 'row': |
| 28 | print row['columns']['group_uuid'] |
| 29 | ret = stdout.channel.recv_exit_status() |