Esempio n. 1
0
def load_single_config(path="."):

    config = default_config
    description = None

    # If path is explicitly "None", try current dir
    if not path: path = "."

    info("Loading config from", path)
    try:
        # Try loading the first valid config
        config, path = validate_vm.load_config(path)[0]
        info(
            "vm config loaded from",
            path,
            ":",
        )
    except Exception as e:
        info("No JSON config found - using default:", )

    if config.has_key("description"):
        description = config["description"]
    else:
        description = str(config)

    info('"', description, '"')

    return config
Esempio n. 2
0
def load_config(path):

    config = {}
    description = None

    # If path is explicitly "None", try current dir
    if not path: path = default_json

    info("Trying to load config from", path)

    if os.path.isfile(path):

        try:
            # Try loading the first valid config
            config = validate_vm.load_config(path)
            info ("Successfully loaded vm config")

        except Exception as e:
            print_exception()
            info("Could not parse VM config file(s): " + path)
            program_exit(73, str(e))

    elif os.path.isdir(path):
        try:
            configs = validate_vm.load_config(path, VERB)
            info ("Found ", len(configs), "config files")
            config = configs[0]
            info ("Trying the first valid config ")
        except Exception as e:
            info("No valid config found: ", e)
            program_exit(73, "No valid config files in " + path)


    if config.has_key("description"):
        description = config["description"]
    else:
        description = str(config)

    info('"',description,'"')

    return config