Chromium Code Reviews| Index: scripts/slave/dump_factory_properties.py |
| diff --git a/scripts/slave/dump_factory_properties.py b/scripts/slave/dump_factory_properties.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3fef1b077698ad323f9572811dde8231b0213850 |
| --- /dev/null |
| +++ b/scripts/slave/dump_factory_properties.py |
| @@ -0,0 +1,85 @@ |
| +#!/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.
|
| + |
| +import argparse |
| +import json |
| +import os |
| +import sys |
| + |
| +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
| +sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) |
| + |
| +import common.env |
| + |
| +common.env.Install() |
| + |
| +from common import master_cfg_utils |
| +from master import master_gen |
| + |
| + |
| +class Err(Exception): |
| + pass |
| + |
| + |
| +def main(argv): |
| + |
| + arg_parser = argparse.ArgumentParser() |
| + arg_parser.add_argument('--output', |
| + help='path to write JSON output to instead of stdout') |
| + arg_parser.add_argument('mastername', nargs=1) |
| + arg_parser.add_argument('buildername', nargs=1) |
| + args = arg_parser.parse_args(argv) |
| + |
| + buildername = args.buildername[0] |
| + mastername = args.mastername[0] |
| + |
| + props = {} |
| + message = '' |
| + 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
|
| + try: |
| + props = GetFactoryProperties(mastername, buildername) |
| + except Exception as e: |
| + message = str(e) |
| + result = 1 |
| + |
| + output_str = json.dumps({ |
| + 'factory_properties': props, |
| + 'message': message, |
| + 'result': result |
| + }, 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.
|
| + |
| + if args.output: |
| + with open(args.output, 'w') as fp: |
| + fp.write(output_str + '\n') |
| + else: |
| + 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
|
| + |
| + return result |
| + |
| + |
| +def GetFactoryProperties(mastername, buildername): |
| + master_list = master_cfg_utils.GetMasters() |
| + master_path = None |
| + for name, path in master_list: |
| + if name == mastername: |
| + master_path = path |
| + |
| + if not master_path: |
| + 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
|
| + |
| + 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
|
| + |
| + for builder_dict in config['BuildmasterConfig']['builders']: |
| + if builder_dict['name'] == buildername: |
| + return dict((k, v) for k, v, _ in |
| + builder_dict['factory'].properties.asList()) |
| + |
| + raise Err('builder "%s" not found on in master "%s"' % |
| + (buildername, mastername)) |
| + |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |
| + |
| +basedir = os.path |
| +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.
|