示例#1
0
def readYamlFile(somefile):
    """Reads the raw Yaml file."""
    if hasYamlSupport() is not True:
        return None
    read_data = None
    try:
        someFilePath = utils.addExtension(somefile, str('yml'))
        with utils.open_func(file=someFilePath, mode=u'r',
                             encoding=u'utf-8') as ymalfile:
            try:
                if yaml.version_info < (0, 15):
                    read_data = yaml.safe_load(ymalfile)
                else:
                    yml = yaml.YAML(typ='safe',
                                    pure=True)  # 'safe' load and dump
                    read_data = yml.load(ymalfile)
            except AttributeError as libyamlerr:
                libyamlerr = None
                del (libyamlerr)
                read_data = yaml.safe_load(ymalfile)
    except Exception as yamlerr:
        print("")
        print("Error: Failed to load YAML file.")
        # remediation.error_breakpoint(error=yamlerr, context=readYamlFile)
        del yamlerr
        print("")
        read_data = None
    return read_data
示例#2
0
            CONDA_BIN = os.path.dirname(os.environ['CONDA_EXE'])
            ruamel_yaml_path = glob.glob(
                os.path.join(CONDA_BIN, '..', 'lib', 'python*.*',
                             'site-packages', 'ruamel_yaml', '__init__.py'))[0]
            # Based on importlib example, but only needs to load_module since its the whole package, not just
            # a module
            spec = import_util.spec_from_file_location('ruamel_yaml',
                                                       ruamel_yaml_path)
            yaml = spec.loader.load_module()
        except (KeyError, ImportError, IndexError):
            raise ImportError(
                "No YAML parser could be found in this or the conda environment. "
                "Could not find PyYAML or Ruamel YAML in the current environment, "
                "AND could not find Ruamel YAML in the base conda environment through CONDA_EXE path. "
                "Environment not created!")
    loader = yaml.YAML(
        typ="safe").load  # typ="safe" avoids odd typing on output


@contextmanager
def temp_cd():
    """Temporary CD Helper"""
    cwd = os.getcwd()
    with TemporaryDirectory() as td:
        try:
            os.chdir(td)
            yield
        finally:
            os.chdir(cwd)


# Args
示例#3
0
            CONDA_BIN = os.path.dirname(os.environ['CONDA_EXE'])
            ruamel_yaml_path = glob.glob(
                os.path.join(CONDA_BIN, '..', 'lib', 'python*.*',
                             'site-packages', 'ruamel_yaml', '__init__.py'))[0]
            # Based on importlib example, but only needs to load_module since its the whole package, not just
            # a module
            spec = import_util.spec_from_file_location('ruamel_yaml',
                                                       ruamel_yaml_path)
            yaml = spec.loader.load_module()
        except (KeyError, ImportError, IndexError):
            raise ImportError(
                "No YAML parser could be found in this or the conda environment. "
                "Could not find PyYAML or Ruamel YAML in the current environment, "
                "AND could not find Ruamel YAML in the base conda environment through CONDA_EXE path. "
                "Environment not created!")
    loader = yaml.YAML(typ="safe").load(
        Loader=yaml.FullLoader)  # typ="safe" avoids odd typing on output


@contextmanager
def temp_cd():
    """Temporary CD Helper"""
    cwd = os.getcwd()
    with TemporaryDirectory() as td:
        try:
            os.chdir(td)
            yield
        finally:
            os.chdir(cwd)


# Args