Example #1
0
    def create_temp_data_set(LLQ,
                             ds_type="SEQ",
                             size="5M",
                             ds_format="FB",
                             lrecl=80):
        """Creates a temporary data set with the given low level qualifier.

        Arguments:
            LLQ {str} -- Low Level Qualifier to be used for temporary data set
            ds_type {str} -- The data set type, default: Sequential
            size {str} -- The size of the data set, default: 5M
            format {str} -- The record format of the data set, default: FB
            lrecl {int} -- The record length of the data set, default: 80

        Returns:
            str -- Name of the created data set

        Raises:
            OSError: When non-zero return code is received
            from Datasets.create()
        """
        chars = ascii_uppercase
        HLQ2 = ''.join(choice(chars) for i in range(5))
        HLQ3 = ''.join(choice(chars) for i in range(6))
        temp_ds_name = "{0}.{1}.{2}.{3}".format(Datasets.hlq(), HLQ2, HLQ3,
                                                LLQ)

        rc = Datasets.create(temp_ds_name, ds_type, size, ds_format, "", lrecl)
        if rc != 0:
            raise OSError("Unable to create temporary data set")

        return temp_ds_name
Example #2
0
def _create_data_set(name, extra_args=None):
    """A wrapper around zoautil_py
    Dataset.create() to raise exceptions on failure.
    Arguments:
        name {str} -- The name of the data set to create.
    Raises:
        DatasetCreateError: When data set creation fails.
    """
    if extra_args is None:
        extra_args = {}
    rc = Datasets.create(name, **extra_args)
    if rc > 0:
        raise DatasetCreateError(name, rc)
    return
Example #3
0
    def temp_data_set(self, reclen, space_u):
        """Creates a temporary data set with the given record length and size

        Arguments:
            size {str} -- The size of the data set
            lrecl {int} -- The record length of the data set

        Returns:
            str -- Name of the allocated data set

        Raises:
            OSError: When any exception is raised during the data set allocation
        """
        size = str(space_u * 2) + "K"
        hlq = Datasets.hlq()
        temp_ps = Datasets.temp_name(hlq)
        rc = Datasets.create(temp_ps, "SEQ", size, "VB", "", reclen)
        if rc:
            raise OSError(
                "Failed when allocating temporary sequential data set!")
        return temp_ps
def create_data_set(name, extra_args={}):
    """ A wrapper around zoautil_py data set create to raise exceptions on failure. """
    rc = Datasets.create(name, **extra_args)
    if rc > 0:
        raise DatasetCreateError(name, rc)
    return
Example #5
0
from zoautil_py.types import DDStatement
# Import datetime, needed so we can format the report
from datetime import datetime
# Import os, needed to get the environment variables
import os

#Take the contents of this data set and read it into cc_contents
cc_contents = Datasets.read("MTM2020.PUBLIC.CUST16")

USERID = os.getenv("USER")
output_dataset = USERID + ".OUTPUT.CCINVALD"
#Delete the output dataset if it already exists
if Datasets.exists(output_dataset):
    Datasets.delete(output_dataset)

Datasets.create(output_dataset, "SEQ")

# Create a new SEQUENTIAL DATA SET with the name of output_dataset


#A function that checks to see if the number passed to it is even. Returns True or False (Boolean)
def is_even(num_to_check
            ):  # this is a function. num_to_check is what gets sent to it
    if ((num_to_check %
         2) == 0):  # a simple check to see if num_to_check is even.
        result = True  # We set result to True
        return result  # and then return it.
    else:  # if it isn't
        result = False  # set return to False
        return result  # and return that.
cc_list = cc_contents.splitlines()      # take that giant string and turn it into a List
invalid_cc_list = []                    # A second list to hold invalid entries
for cc_line in cc_list:                 # do everything here for every item in that List
    cc_digits = int(cc_line[5:21])      # Just grabbing some digits. Not a full CC number (HINT!)
    if (luhn(cc_digits)):            # If the card number is valid
        invalid_cc_list.append(cc_line)


#The Report-Writing Part
    #
    # NOTE: DON'T USE APPEND FOR MULTIPLE LINES. 
    #       IT WILL BE SLOW
    #       INSTEAD, THROW EVERYTHING INTO A VARIABLE
    #       AND WRITE THAT OUT ONCE, LIKE THIS.
    #       
    #       TRUST US ON THIS.
    #
    #       YOU SHOULD BE ABLE TO USE THE CODE BELOW, ONLY HAVING TO ADD
    #       A LINE TO WRITE OUT THE FINAL report_output TO YOUR output_dataset
    #       REMEMBER, THE REPORT NEEDS TO HAVE THE DATETIME STRING IN IT ABOVE THE DATA
    #
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
report_output = '\n'.join(invalid_cc_list)
report_output = "INVALID CREDIT CARD REPORT FOR " + dt_string + '\n\n' + report_output
print(report_output)  # Print it out to the screen. 
# When you're ready to write your report out to file, uncomment that last line
Datasets.create("Z09150.OUTPUT.CCINVALD", "SEQ")
Datasets.write("Z09150.OUTPUT.CCINVALD",report_output)
Example #7
0
dd_statements = []
dd_statements.append(
    DDStatement(ddName="sortin01", dataset="USR.MVSCMD.DFSORT.MASTER"))
dd_statements.append(
    DDStatement(ddName="sortin02", dataset="USR.MVSCMD.DFSORT.NEW"))
dd_statements.append(
    DDStatement(ddName="sysin", dataset="USR.MVSCMD.DFSORT.CMD"))
dd_statements.append(
    DDStatement(ddName="sortout", dataset="USR.MVSCMD.DFSORT.MERGE"))
dd_statements.append(DDStatement(ddName="sysout", dataset="*"))

# Delete datasets if already exist
Datasets.delete("USR.MVSCMD.DFSORT.*")

# Create datasets
Datasets.create("USR.MVSCMD.DFSORT.MASTER", type="SEQ")
Datasets.create("USR.MVSCMD.DFSORT.NEW", type="SEQ")
Datasets.create("USR.MVSCMD.DFSORT.CMD", type="SEQ")
Datasets.create("USR.MVSCMD.DFSORT.MERGE", type="SEQ")

# Write command to USR.MVSCMD.DFSORT.CMD
Datasets.write("USR.MVSCMD.DFSORT.CMD", " MERGE FORMAT=CH,FIELDS=(1,9,A)")

# Write example text to USR.MVSCMD.DFSORT.MASTER
Datasets.write("USR.MVSCMD.DFSORT.MASTER", "Chang Joe 278 232 6043")
Datasets.write("USR.MVSCMD.DFSORT.MASTER",
               "DeBeer Jo 348 132 6023",
               append=True)
Datasets.write("USR.MVSCMD.DFSORT.MASTER",
               "White Belinda 178 222 5043",
               append=True)
Example #8
0
# Import datetime, needed so we can format the report
from datetime import datetime
# Import os, needed to get the environment variables
import os

#Take the contents of this data set and read it into cc_contents
cc_contents = Datasets.read("MTM2020.PUBLIC.CUST16")

USERID = os.getenv('USER')
output_dataset = USERID + ".OUTPUT.CCINVALD"
#Delete the output dataset if it already exists
if Datasets.exists(output_dataset):
    Datasets.delete(output_dataset)
# Use this line to create a new SEQUENTIAL DATA SET with the name of output_dataset
# (hint: https://www.ibm.com/support/knowledgecenter/SSKFYE_1.0.1/python_doc_zoautil/api/datasets.html?view=embed)
Datasets.create(output_dataset, type="SEQ")


def luhn(card_number):
    def digits_of(n):
        return [int(d) for d in str(n)]

    digits = digits_of(card_number)
    odd_digits = digits[-1::-2]
    even_digits = digits[-2::-2]
    checksum = 0
    checksum += sum(odd_digits)
    for d in even_digits:
        checksum += sum(digits_of(d * 2))
    return (checksum % 10)