Exemple #1
0
def slurp_braindb(run_dir, brain_alternate=None):
    """
    Consume braindump file and return it's content as a `dict`.

    :param run_dir: [description]
    :type run_dir: [type]
    :param brain_alternate: [description], defaults to None
    :type brain_alternate: [type], optional
    :return: [description]
    :rtype: [type]
    """
    if not run_dir:
        raise ValueError("run_dir is required")

    bdump = Path(run_dir) / (
        "braindump.yml" if brain_alternate is None else brain_alternate
    )

    if bdump.exists() is False:
        # TODO: Remove this except block one backwards compatibility for
        # 4.9 is not needed.
        cfg = _slurp_braindb(run_dir, brain_alternate)
    else:
        if bdump.is_file() is False:
            raise TypeError("%s is not a valid file" % bdump.resolve())

        with bdump.open("r") as fp:
            cfg = braindump.load(fp)
            cfg = {
                k: str(v) if isinstance(v, Path) else v
                for k, v in attr.asdict(cfg).items()
            }

    return cfg
Exemple #2
0
def test_load(s, obj):
    fp = io.StringIO(s)
    b = load(fp)

    assert isinstance(b, Braindump)

    for k, v in obj.items():
        assert k in fields
        assert isinstance(getattr(b, k), fields[k].type)
        assert isinstance(getattr(b, k), fields[k].type)
Exemple #3
0
    def _get_braindump(submit_dir: str):
        try:
            with (Path(submit_dir) / "braindump.yml").open("r") as f:
                bd = braindump.load(f)
        except FileNotFoundError:
            raise WorkflowInstanceError(
                "Unable to load braindump file: {}".format(path)
            )

        return bd
Exemple #4
0
    def get_wf_uuid(self):
        "Get the workflow UUID from the braindump file"
        submitdir = self.find_submitdir()

        braindump_file_path = os.path.join(submitdir, "braindump.yml")

        if not os.path.isfile(braindump_file_path):
            raise EMError("braindump.yml not found")

        with open(braindump_file_path) as f:
            bd = braindump.load(f)

        if bd.wf_uuid is None:
            raise EMError("wf_uuid not found in braindump.yml")

        return bd.wf_uuid