From 9b14838b95943454611884a55219bf538239bba9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 23 Apr 2012 17:45:03 +0300 Subject: prepare_build_config.py: Fix mistakes and add more tests. --- node/prepare_build_config.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'node') diff --git a/node/prepare_build_config.py b/node/prepare_build_config.py index 3086453..6949305 100755 --- a/node/prepare_build_config.py +++ b/node/prepare_build_config.py @@ -65,11 +65,11 @@ def validate_config(config, slave_type): raise BuildConfigMismatchException("Incompatible slave type, job owner and build type") -def convert_config_to_shell(config_text): +def convert_config_to_shell(config_text, out_filename): config = {} - out = open(BUILD_CONFIG_FILE, "w") + out = open(out_filename, "w") - for l in cfg.split("\n"): + for l in config_text.split("\n"): l = l.strip() if not l or l[0] == "#": continue @@ -79,15 +79,25 @@ def convert_config_to_shell(config_text): var, val = l.split("=", 1) val = shell_unquote(val) config[var] = val - print "%s=%s" % (var, pipes.quote(val)) + out.write("%s=%s\n" % (var, pipes.quote(val))) out.close() + return config - -if __name__ == "__main__": - config_text = base64.b64decode(sys.argv[1]) - config = convert_config_to_shell(config_text, get_slave_type()) +def main(config_in, is_base64): + if is_base64: + config_in = base64.b64decode(config_in) + config = convert_config_to_shell(config_in, BUILD_CONFIG_FILE) try: - validate_config(config) + validate_config(config, get_slave_type()) except BuildConfigMismatchException, e: print str(e) sys.exit(1) + +if __name__ == "__main__": + optparser = optparse.OptionParser(usage="%prog") + optparser.add_option("--base64", action="store_true", help="Process only jobs matching regex pattern") + options, args = optparser.parse_args(sys.argv[1:]) + if len(args) != 1: + optparser.error("Wrong number of arguments") + main(args[0], opts.base64) + -- cgit v1.2.3