From 25904057929fbd0911ca0a594559fdbfa6ed4474 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Mon, 15 Jun 2015 15:09:40 -0400 Subject: [PATCH] Add the ability to set output file Set an output file, handy for scripting. partially implements bp openstack-client-heat-translator Change-Id: I5ddbab7c9266b18f4a0aad0958ccbe7db318e73f --- translator/osc/v1/translate.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/translator/osc/v1/translate.py b/translator/osc/v1/translate.py index ca730c5c..68ef5f72 100644 --- a/translator/osc/v1/translate.py +++ b/translator/osc/v1/translate.py @@ -41,6 +41,10 @@ class TranslateTemplate(command.Command): required=True, choices=['tosca'], help='Format of the template file.') + parser.add_argument( + '--output-file', + metavar='', + help='Path to place the translated content.') return parser def take_action(self, parsed_args): @@ -56,4 +60,9 @@ class TranslateTemplate(command.Command): tosca = ToscaTemplate(parsed_args.template_file) translator = TOSCATranslator(tosca, parsed_params) output = translator.translate() - print(output) + + if parsed_args.output_file: + with open(parsed_args.output_file, 'w+') as f: + f.write(output) + else: + print(output)