コード例 #1
0
def test_read_yaml_file():
    fd, path = tempfile.mkstemp()
    os.close(fd)

    with open(path, "w") as output:
        output.write("value: 42\n")

    result = pdosq.read_yaml_file(path)
    assert result['value'] == 42

    pdosq.safe_remove(path)
    assert pdosq.read_yaml_file(path, default=None) is None
    assert pdosq.read_yaml_file(path, default={}) == {}
コード例 #2
0
ファイル: provisioning.py プロジェクト: ParadropLabs/Paradrop
def read_provisioning_conf():
    """
    Read provisioning information from the configuration file.

    This file will exist on startup if the node is to be self-provisioned.
    """
    path = os.path.join(settings.CONFIG_HOME_DIR, "provision.yaml")
    return pdosq.read_yaml_file(path, default={})
コード例 #3
0
def read_provisioning_conf():
    """
    Read provisioning information from the configuration file.

    This file will exist on startup if the node is to be self-provisioned.
    """
    path = os.path.join(settings.CONFIG_HOME_DIR, "provision.yaml")
    return pdosq.read_yaml_file(path, default={})
コード例 #4
0
ファイル: hostconfig.py プロジェクト: ParadropLabs/Paradrop
def load(path=None):
    """
    Load host configuration.

    Tries to load host configuration from persistent file.  If that does not
    work, it will try to automatically generate a working configuration.

    Returns a host config object on success or None on failure.
    """
    if path is None:
        path = settings.HOST_CONFIG_FILE

    return pdosq.read_yaml_file(path, default=None)
コード例 #5
0
ファイル: hostconfig.py プロジェクト: gawain93/Paradrop
def load(path=None):
    """
    Load host configuration.

    Tries to load host configuration from persistent file.  If that does not
    work, it will try to automatically generate a working configuration.

    Returns a host config object on success or None on failure.
    """
    if path is None:
        path = settings.HOST_CONFIG_FILE

    return pdosq.read_yaml_file(path, default=None)
コード例 #6
0
ファイル: chute_api.py プロジェクト: Huangyz10/Paradrop
def extract_tarred_chute(data):
    tar = tarfile.TarFile(fileobj=data)
    if not tarfile_is_safe(tar):
        raise Exception("Tarfile contains unsafe paths")

    tempdir = tempfile.mkdtemp()
    tar.extractall(tempdir)

    configfile = os.path.join(tempdir, "paradrop.yaml")
    if not os.path.isfile(configfile):
        raise Exception("No paradrop.yaml file found in chute source")

    paradrop_yaml = pdosq.read_yaml_file(configfile, default={})

    return (tempdir, paradrop_yaml)
コード例 #7
0
ファイル: nexus.py プロジェクト: ParadropLabs/Paradrop
def resolveInfo(nexus, path):
    '''
    Given a path to the config file, load its contents and assign it to the
    config file as appropriate.
    '''

    # Check to make sure we have a default settings file
    if not os.path.isfile(path):
        createDefaultInfo(path)

    contents = pdosq.read_yaml_file(path)

    # Sanity check contents of info and throw it out if bad
    if not validateInfo(contents):
        output.out.err('Saved configuration data invalid, destroying it.')
        os.remove(path)
        createDefaultInfo(path)
        contents = pdosq.read_yaml_file(path, default={})
        writeYaml(contents, path)

    nexus.info.pdid = contents['pdid']
    nexus.info.version = contents['version']
    nexus.info.pdserver = contents['pdserver']
    nexus.info.wampRouter = contents['wampRouter']
コード例 #8
0
def load_chute_configuration(update):
    """
    Load and interpret paradrop.yaml file.
    """
    if not update.has_chute_build():
        return

    config = {}

    workdir = getattr(update, "workdir", None)
    if workdir is not None:
        conf_path = os.path.join(workdir, settings.CHUTE_CONFIG_FILE)
        config = pdosq.read_yaml_file(conf_path, default={})

    # Look for additional build information from the update object
    # and merge with the configuration file.
    if hasattr(update, "build"):
        config.update(update.build)

    # Try to set the owner of the chute.
    if hasattr(update, "user"):
        config['owner'] = update.user

    update.new = build_chute(config)
コード例 #9
0
ファイル: provisioning.py プロジェクト: ParadropLabs/Paradrop
def read_provisioning_result():
    """
    Read provisioning result from the filesystem.
    """
    path = os.path.join(settings.CONFIG_HOME_DIR, "provisioned.yaml")
    return pdosq.read_yaml_file(path, default={})
コード例 #10
0
def read_provisioning_result():
    """
    Read provisioning result from the filesystem.
    """
    path = os.path.join(settings.CONFIG_HOME_DIR, "provisioned.yaml")
    return pdosq.read_yaml_file(path, default={})
コード例 #11
0
def testSaveUpdatesYaml():
    nex = TestingNexus()
    nex.info.a = 1

    dic = pdosq.read_yaml_file(settings.CONFIG_FILE)
    assert dic['a'] == 1