def _create_single_blueprint(config, template_file, var_files, no_prompt, extra_vars=None, suppress_warnings=False): blueprint_dir = os.path.expanduser(config['blueprint_dir']) gen = BlueprintGenerator([os.path.join(blueprint_dir, 'templates')]) if not os.path.exists(os.path.join(blueprint_dir, 'templates', template_file)): click.secho('You gave an invalid template', fg='red') return if template_file.startswith('_'): click.secho('WARNING: Templates beginning with \'_\' are generally not meant to ' 'be used directly. Please be sure this is really what you want.\n', fg='magenta') final_var_files = [] # Build a list with full paths in it instead of relative paths for var_file in var_files: var_file = os.path.join(blueprint_dir, 'var_files', var_file) if os.path.exists(var_file): final_var_files.append(open(var_file, 'r')) else: click.secho('WARNING: Variable file {0} was not found. Ignoring.'.format(var_file), fg='magenta') # Generate the JSON for the blueprint return gen.generate(template_file, final_var_files, # Pass in a list variables=extra_vars, prompt=no_prompt, suppress_warnings=suppress_warnings)
def main(template_file, var_files, prompt, debug): try: # Throw all output to stderr gen = BlueprintGenerator([ os.path.curdir, os.path.join(os.path.curdir, 'templates'), os.path.dirname(os.path.abspath(template_file)) ], output_stream=sys.stderr) # Generate the blueprint blueprint = gen.generate(template_file, var_files=var_files, prompt=prompt, debug=debug) except BlueprintException: raise click.Abort('Error processing blueprint') click.echo(json.dumps(blueprint, indent=2))