def _create_single_blueprint(config, template_file, var_files, no_prompt):
    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
                        prompt=no_prompt)
Esempio n. 2
0
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))
Esempio n. 4
0
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))
def main():
    parser = argparse.ArgumentParser(
        description='invoke the stackdio blueprint generator')

    parser.add_argument('template_file',
                        help='The template file to generate from')

    parser.add_argument('var_files',
                        metavar='var_file',
                        nargs='*',
                        help='The variable files with your custom config.  They will be loaded '
                             'from left to right, so variables in the rightmost var files will '
                             'override those in var files to the left.')

    parser.add_argument('-p', '--prompt',
                        action='store_true',
                        help='Prompt user for missing variables')

    parser.add_argument('-d', '--debug',
                        action='store_true',
                        help='Print out json string before parsing the json')

    args = parser.parse_args()

    try:
        # Throw all output to stderr
        gen = BlueprintGenerator([os.path.curdir,
                                  os.path.join(os.path.curdir, 'templates'),
                                  os.path.dirname(os.path.abspath(args.template_file))],
                                 output_stream=sys.stderr)

        # Generate the blueprint
        blueprint = gen.generate(args.template_file,
                                 var_files=args.var_files,
                                 prompt=args.prompt,
                                 debug=args.debug)
    except BlueprintException:
        sys.exit(1)

    print(json.dumps(blueprint, indent=2))