Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
|
iannucci
2015/06/11 00:28:08
probably want to put this in scripts/tools
Dirk Pranke
2015/06/11 01:13:43
ok.
| |
| 2 | |
| 3 import argparse | |
| 4 import json | |
| 5 import os | |
| 6 import sys | |
| 7 | |
| 8 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | |
| 9 sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) | |
| 10 | |
| 11 import common.env | |
| 12 | |
| 13 common.env.Install() | |
| 14 | |
| 15 from common import master_cfg_utils | |
| 16 from master import master_gen | |
| 17 | |
| 18 | |
| 19 class Err(Exception): | |
| 20 pass | |
| 21 | |
| 22 | |
| 23 def main(argv): | |
| 24 | |
| 25 arg_parser = argparse.ArgumentParser() | |
| 26 arg_parser.add_argument('--output', | |
| 27 help='path to write JSON output to instead of stdout') | |
| 28 arg_parser.add_argument('mastername', nargs=1) | |
| 29 arg_parser.add_argument('buildername', nargs=1) | |
| 30 args = arg_parser.parse_args(argv) | |
| 31 | |
| 32 buildername = args.buildername[0] | |
| 33 mastername = args.mastername[0] | |
| 34 | |
| 35 props = {} | |
| 36 message = '' | |
| 37 result = 0 | |
|
iannucci
2015/06/11 00:28:08
maybe 'ok' and make it a bool?
Dirk Pranke
2015/06/11 01:13:43
Actually, looking at this now, it might be better
| |
| 38 try: | |
| 39 props = GetFactoryProperties(mastername, buildername) | |
| 40 except Exception as e: | |
| 41 message = str(e) | |
| 42 result = 1 | |
| 43 | |
| 44 output_str = json.dumps({ | |
| 45 'factory_properties': props, | |
| 46 'message': message, | |
| 47 'result': result | |
| 48 }, sort_keys=2, indent=2) | |
|
iannucci
2015/06/11 00:28:08
while 'sort_keys=2' technically works, you probabl
Dirk Pranke
2015/06/11 01:13:43
whoops, yes.
| |
| 49 | |
| 50 if args.output: | |
| 51 with open(args.output, 'w') as fp: | |
| 52 fp.write(output_str + '\n') | |
| 53 else: | |
| 54 print output_str | |
|
iannucci
2015/06/11 00:28:07
consider
outfile = sys.stdout
if args.output:
o
Dirk Pranke
2015/06/11 01:13:43
That will close sys.stdout() at the end, which mig
| |
| 55 | |
| 56 return result | |
| 57 | |
| 58 | |
| 59 def GetFactoryProperties(mastername, buildername): | |
| 60 master_list = master_cfg_utils.GetMasters() | |
| 61 master_path = None | |
| 62 for name, path in master_list: | |
| 63 if name == mastername: | |
| 64 master_path = path | |
| 65 | |
| 66 if not master_path: | |
| 67 raise Err('master "%s" not found.' % mastername) | |
|
iannucci
2015/06/11 00:28:08
tbh... I would probably just raise Exception (sinc
Dirk Pranke
2015/06/11 01:13:43
Yeah, true, this is left over when I thought I wou
| |
| 68 | |
| 69 config = master_cfg_utils.LoadConfig(master_path, 'master.cfg') | |
|
Paweł Hajdan Jr.
2015/06/11 08:38:19
I think we have a very similar existing tool build
| |
| 70 | |
| 71 for builder_dict in config['BuildmasterConfig']['builders']: | |
| 72 if builder_dict['name'] == buildername: | |
| 73 return dict((k, v) for k, v, _ in | |
| 74 builder_dict['factory'].properties.asList()) | |
| 75 | |
| 76 raise Err('builder "%s" not found on in master "%s"' % | |
| 77 (buildername, mastername)) | |
| 78 | |
| 79 | |
| 80 | |
| 81 if __name__ == '__main__': | |
| 82 sys.exit(main(sys.argv[1:])) | |
| 83 | |
| 84 basedir = os.path | |
| 85 from twisted.application import service | |
|
iannucci
2015/06/11 00:28:08
dare I ask?
Dirk Pranke
2015/06/11 01:13:43
whoops, bad cut and paste, I think.
| |
| OLD | NEW |