Ejemplo n.º 1
0
 def __del__(self):
     """Try to delete the temporary data set
     if VIO wrote to disk during execution.
     """
     try:
         DataSet.delete(self.name)
     except Exception:
         pass
Ejemplo n.º 2
0
def data_set_name(contents, dependencies):
    """Validates provided data set name(s) are valid.
    Returns a list containing the name(s) of data sets."""
    if dependencies.get("batch"):
        return None
    if contents is None:
        if dependencies.get("state") != "present":
            raise ValueError(
                'Data set name must be provided when "state!=present"')
        if dependencies.get("type") != "MEMBER":
            contents = DataSet.temp_name()
        else:
            raise ValueError(
                'Data set and member name must be provided when "type=MEMBER"')
    dsname = str(contents)
    if not re.fullmatch(
            r"^(?:(?:[A-Z$#@]{1}[A-Z0-9$#@-]{0,7})(?:[.]{1})){1,21}[A-Z$#@]{1}[A-Z0-9$#@-]{0,7}$",
            dsname,
            re.IGNORECASE,
    ):
        if not (re.fullmatch(
                r"^(?:(?:[A-Z$#@]{1}[A-Z0-9$#@-]{0,7})(?:[.]{1})){1,21}[A-Z$#@]{1}[A-Z0-9$#@-]{0,7}(?:\([A-Z$#@]{1}[A-Z0-9$#@]{0,7}\)){0,1}$",
                dsname,
                re.IGNORECASE,
        ) and dependencies.get("type") == "MEMBER"):
            raise ValueError(
                "Value {0} is invalid for data set argument.".format(dsname))
    return dsname.upper()
Ejemplo n.º 3
0
    def __init__(
        self,
        record_format="FBA",
        space_primary=100,
        space_secondary=50,
        space_type="trk",
        record_length=121,
    ):
        """Output DD Data type to be used in a DDStatement.
        This should be used in cases where user wants to receive
        output from a program but does not want to store in a
        persistent data set or file.

        Args:
            record_format (str, optional): The record format to use for the dataset.
                    Valid options are: FB, VB, FBA, VBA, U.
                    Defaults to "VB".
            space_primary (int, optional): The amount of primary space to allocate for the dataset.
                    Defaults to 5.
            space_secondary (int, optional):  The amount of secondary space to allocate for the dataset.
                    Defaults to 5.
            space_type (str, optional): The unit of measurement to use when defining primary and secondary space.
                    Defaults to "M".
            record_length (int, optional): The length, in bytes, of each record in the data set.
                    Defaults to 80.
        """
        self.name = None
        name = DataSet.create_temp(
            record_format=record_format,
            space_primary=space_primary,
            space_secondary=space_secondary,
            space_type=space_type,
            record_length=record_length,
        )
        super().__init__(name)
Ejemplo n.º 4
0
    def __init__(
        self,
        content,
        record_format="FB",
        space_primary=5,
        space_secondary=5,
        space_type="M",
        record_length=80,
    ):
        """Stdin DD Data type to be used in a DDStatement.
        This should be used in cases where "DD *" would be used in a jcl.

        Args:
            content (Union[str, list[str]]): The content to write to temporary data set / stdin.
                    Content can be provided as a string or a list of strings where each list item
                    corresponds to a single line.
            record_format (str, optional): The record format to use for the dataset.
                    Valid options are: FB, VB, FBA, VBA, U.
                    Defaults to "FB".
            space_primary (int, optional): The amount of primary space to allocate for the dataset.
                    Defaults to 5.
            space_secondary (int, optional):  The amount of secondary space to allocate for the dataset.
                    Defaults to 5.
            space_type (str, optional): The unit of measurement to use when defining primary and secondary space.
                    Defaults to "M".
            record_length (int, optional): The length, in bytes, of each record in the data set.
                    Defaults to 80.
        """
        self.name = None
        name = DataSet.create_temp(
            record_format=record_format,
            space_primary=space_primary,
            space_secondary=space_secondary,
            space_type=space_type,
            record_length=record_length,
        )
        super().__init__(name)
        if isinstance(content, list):
            content = "\n".join(content)
        DataSet.write(name, content)
Ejemplo n.º 5
0
def perform_data_set_operations(name, state, **extra_args):
    """Calls functions to perform desired operations on
    one or more data sets. Returns boolean indicating if changes were made."""
    changed = False
    if state == "present" and extra_args.get("type") != "MEMBER":
        changed = DataSet.ensure_present(name, **extra_args)
    elif state == "present" and extra_args.get("type") == "MEMBER":
        changed = DataSet.ensure_member_present(name,
                                                extra_args.get("replace"))
    elif state == "absent" and extra_args.get("type") != "MEMBER":
        changed = DataSet.ensure_absent(name, extra_args.get("volumes"))
    elif state == "absent" and extra_args.get("type") == "MEMBER":
        changed = DataSet.ensure_member_absent(name)
    elif state == "cataloged":
        changed = DataSet.ensure_cataloged(name, extra_args.get("volumes"))
    elif state == "uncataloged":
        changed = DataSet.ensure_uncataloged(name)
    return changed
Ejemplo n.º 6
0
 def __del__(self):
     if self.name:
         DataSet.delete(self.name)