Instruction:
Can you tell what is the following Python 3 function doing
def insertBulkBlock(self):
        try:
            body = request.body.read()
            indata = cjson.decode(body)
            if (indata.get("file_parent_list", []) and indata.get("dataset_parent_list", [])):
                dbsExceptionHandler("dbsException-invalid-input2", "insertBulkBlock: dataset and file parentages cannot be in the input at the same time",
                    self.logger.exception, "insertBulkBlock: datset and file parentages cannot be in the input at the same time.")
            indata = validateJSONInputNoCopy("blockBulk", indata)
            self.dbsBlockInsert.putBlock(indata)
        except cjson.DecodeError as dc:
            dbsExceptionHandler("dbsException-invalid-input2", "Wrong format/data from insert BulkBlock input",  self.logger.exception, str(dc))
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.message)
        except HTTPError as he:
            raise he
        except Exception as ex:
            #illegal variable name/number
            if str(ex).find("ORA-01036") != -1:
                dbsExceptionHandler("dbsException-invalid-input2", "illegal variable name/number from input",  self.logger.exception, str(ex))
            else:
                sError = "DBSWriterModel/insertBulkBlock. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
                dbsExceptionHandler('dbsException-server-error',  dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to insert a bulk block of datset and file parentages.


Instruction:
How would you explain what the following Python 3 function does
def insertBlock(self):
        try:
            body = request.body.read()
            indata = cjson.decode(body)
            indata = validateJSONInputNoCopy("block", indata)
            self.dbsBlock.insertBlock(indata)
        except cjson.DecodeError as dc:
            dbsExceptionHandler("dbsException-invalid-input2", "Wrong format/data from insert Block input",  self.logger.exception, str(dc))
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.message)
        except Exception as ex:
            sError = "DBSWriterModel/insertBlock. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error',  dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to insert a block into DBS


Instruction:
Write a Python 3 function that can
insert a list of files into DBS.

Response:
def insertFile(self, qInserts=False):
        """
        API to insert a list of file into DBS in DBS. Up to 10 files can be inserted in one request.

        :param qInserts: True means that inserts will be queued instead of done immediately. INSERT QUEUE Manager will perform the inserts, within few minutes.
        :type qInserts: bool
        :param filesList: List of dictionaries containing following information
        :type filesList: list of dicts
        :key logical_file_name: File to be inserted (str) (Required)
        :key is_file_valid: (optional, default = 1): (bool)
        :key block: required: /a/b/c#d (str)
        :key dataset: required: /a/b/c (str)
        :key file_type: (optional, default = EDM) one of the predefined types, (str)
        :key check_sum: (optional, default = '-1') (str)
        :key event_count: (optional, default = -1) (int)
        :key file_size: (optional, default = -1.) (float)
        :key adler32: (optional, default = '') (str)
        :key md5: (optional, default = '') (str)
        :key auto_cross_section: (optional, default = -1.) (float)
        :key file_lumi_list: (optional, default = []) [{'run_num': 123, 'lumi_section_num': 12},{}....]
        :key file_parent_list: (optional, default = []) [{'file_parent_lfn': 'mylfn'},{}....]
        :key file_assoc_list: (optional, default = []) [{'file_parent_lfn': 'mylfn'},{}....]
        :key file_output_config_list: (optional, default = []) [{'app_name':..., 'release_version':..., 'pset_hash':...., output_module_label':...},{}.....]

        """
        if qInserts in (False, 'False'): qInserts=False
        try:
            body = request.body.read()
            indata = cjson.decode(body)["files"]
            if not isinstance(indata, (list, dict)):
                dbsExceptionHandler("dbsException-invalid-input", "Invalid Input DataType", self.logger.exception, \
                                      "insertFile expects input as list or dirc")
            businput = []
            if isinstance(indata, dict):
                indata = [indata]
            indata = validateJSONInputNoCopy("files", indata)
            for f in indata:
                f.update({
                     #"dataset":f["dataset"],
                     "creation_date": f.get("creation_date", dbsUtils().getTime()),
                     "create_by" : dbsUtils().getCreateBy(),
                     "last_modification_date": f.get("last_modification_date", dbsUtils().getTime()),
                     "last_modified_by": f.get("last_modified_by", dbsUtils().getCreateBy()),
                     "file_lumi_list":f.get("file_lumi_list", []),
                     "file_parent_list":f.get("file_parent_list", []),
                     "file_assoc_list":f.get("assoc_list", []),
                     "file_output_config_list":f.get("file_output_config_list", [])})
                businput.append(f)
            self.dbsFile.insertFile(businput, qInserts)
        except cjson.DecodeError as dc:
            dbsExceptionHandler("dbsException-invalid-input2", "Wrong format/data from insert File input",  self.logger.exception, str(dc))
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.message)
        except HTTPError as he:
            raise he
        except Exception as ex:
            sError = "DBSWriterModel/insertFile. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error',  dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)


Instruction:
Can you tell what is the following Python 3 function doing
def updateFile(self, logical_file_name=[], is_file_valid=1, lost=0, dataset=''):
        if lost in [1, True, 'True', 'true', '1', 'y', 'yes']:
            lost = 1
            if is_file_valid in [1, True, 'True', 'true', '1', 'y', 'yes']:
                dbsExceptionHandler("dbsException-invalid-input2", dbsExceptionCode["dbsException-invalid-input2"], self.logger.exception,\
                                    "Lost file must set to invalid" )
        else: lost = 0

        for f in logical_file_name, dataset:
            if '*' in f or '%' in f:
                dbsExceptionHandler("dbsException-invalid-input2", dbsExceptionCode["dbsException-invalid-input2"], self.logger.exception, "No \
                    wildcard allow in LFN or dataset for updatefile API." )
        try:
            self.dbsFile.updateStatus(logical_file_name, is_file_valid, lost, dataset)
        except HTTPError as he:
            raise he
        except Exception as ex:
            sError = "DBSWriterModel/updateFile. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error',  dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to update status of a file.


Instruction:
How would you implement a function in Python 3 that
creates a new record set from a CIDR string.

Response:
def create_from_string(cls, cidr, label=None, whitelist=False):
        """
        Converts a CIDR like 192.168.0.0/24 into 2 parts:
            start: 3232235520
            stop: 3232235775
        """
        network = netaddr.IPNetwork(cidr)
        start = network.first
        stop = start + network.size - 1
        obj = cls.objects.create(label=label, start=start, stop=stop,
                                 whitelist=whitelist)
        return obj


Instruction:
Make a summary of the following Python 3 code
def qs_for_ip(cls, ip_str):
        ip = int(netaddr.IPAddress(ip_str))

        # ignore IPv6 addresses for now (4294967295 is 0xffffffff, aka the
        # biggest 32-bit number)
        if ip > 4294967295:
            return cls.objects.none()

        ip_range_query = {
            'start__lte': ip,
            'stop__gte': ip
        }

        return cls.objects.filter(**ip_range_query)

Response: Returns a queryset with matching IPNetwork objects for the given IP.


Instruction:
Can you implement a function in Python 3 that
returns True if the provided IP is in the blacklist and does not exist in the whitelist. Otherwise return False.

Response:
def matches_ip(cls, ip_str, read_preference=None):
        """
        Return True if provided IP exists in the blacklist and doesn't exist
        in the whitelist. Otherwise, return False.
        """
        qs = cls.qs_for_ip(ip_str).only('whitelist')
        if read_preference:
            qs = qs.read_preference(read_preference)

        # Return True if any docs match the IP and none of them represent
        # a whitelist
        return bool(qs) and not any(obj.whitelist for obj in qs)


Instruction:
Explain what the following Python 3 code does
def execute(self, conn, block_id="", transaction=False):
        if not conn:
            dbsExceptionHandler("dbsException-db-conn-failed", "Oracle/FileBuffer/List. Expects db connection from upper layer.")

	sql = self.sql
        binds = { "block_id" : block_id}
        cursors = self.dbi.processData(sql, binds, conn, transaction, returnCursor=True)
        result = self.formatCursor(cursors[0])
        return result

Response: Execute a read - only command.


Instruction:
Write a Python 3 script to
return a list of all primary datasets that match the given pattern.

Response:
def execute(self, conn, primary_ds_name="", primary_ds_type="", transaction=False):
        """
        Lists all primary datasets if pattern is not provided.
        """
        sql = self.sql
        binds = {}
        #import pdb
        #pdb.set_trace()
        if primary_ds_name and primary_ds_type in ('', None, '%'):
            op = ("=", "like")["%" in primary_ds_name]
            sql += "WHERE P.PRIMARY_DS_NAME %s :primary_ds_name" % op
            binds.update(primary_ds_name=primary_ds_name)
        elif primary_ds_type and primary_ds_name in ('', None, '%'):
            op = ("=", "like")["%" in primary_ds_type]
            sql += "WHERE PT.PRIMARY_DS_TYPE %s :primary_ds_type" % op
            binds.update(primary_ds_type=primary_ds_type)
        elif primary_ds_name and primary_ds_type:
            op = ("=", "like")["%" in primary_ds_name]
            op1 = ("=", "like")["%" in primary_ds_type]
            sql += "WHERE P.PRIMARY_DS_NAME %s :primary_ds_name and PT.PRIMARY_DS_TYPE %s :primary_ds_type"\
                %(op, op1)
            binds.update(primary_ds_name=primary_ds_name)
            binds.update(primary_ds_type=primary_ds_type)
        else:
            pass
	cursors = self.dbi.processData(sql, binds, conn, transaction, returnCursor=True)
        result = []
        for c in cursors:
            result.extend(self.formatCursor(c, size=100))
        return result


Instruction:
Explain what the following Python 3 code does
def configure_proxy(self, curl_object):
        curl_object.setopt(curl_object.PROXY, self._proxy_hostname)
        curl_object.setopt(curl_object.PROXYPORT, self._proxy_port)
        curl_object.setopt(curl_object.PROXYTYPE, curl_object.PROXYTYPE_SOCKS5)
        if self._proxy_user and self._proxy_passwd:
            curl_object.setopt(curl_object.PROXYUSERPWD, '%s:%s' % (self._proxy_user, self._proxy_port))

Response: configure pycurl proxy settings


Instruction:
How would you code a function in Python 3 to
insert a new entry in DB.

Response:
def execute( self, conn, daoinput, transaction = False ):
        """
        daoinput must be validated to have the following keys:
        child_parent_id__list[[cid, pid],...], block_name
        """
        binds = {}
        bindlist=[]

        if isinstance(daoinput, dict) and "block_name" in daoinput.keys():
            binds = {"block_name": daoinput["block_name"]}
            r = self.dbi.processData(self.sql_sel, binds, conn, False)
            bfile = self.format(r)
            bfile_list = []
            for f in bfile:
                bfile_list.append(f[0])
            if "child_parent_id_list" in daoinput.keys():
                files = []
                for i in daoinput["child_parent_id_list"]:
                    files.append(i[0])
                if set(files)-set(bfile_list):
                    dbsExceptionHandler('dbsException-invalid-input2', "Files required in the same block for FileParent/insert2 dao.", self.logger.exception)
            else:
                dbsExceptionHandler('dbsException-invalid-input2', "child_parent_id_list required for FileParent/insert2 dao.", self.logger.exception)
        else:
            dbsExceptionHandler('dbsException-invalid-input2', "Block_name required in the same block for FileParent/insert2 dao.", self.logger.exception)
        binds = {}
        for pf in daoinput["child_parent_id_list"]:
            binds = {"this_file_id":pf[0], "parent_file_id": pf[1]}
            bindlist.append(binds)
        self.dbi.processData(self.sql, bindlist, conn, transaction)


Instruction:
Here you have a function in Python 3, explain what it does
def execute(self, conn, acquisition_era_name,end_date, transaction = False):
	if not conn:
	    dbsExceptionHandler("dbsException-failed-connect2host", "dbs/dao/Oracle/AcquisitionEra/updateEndDate expects db connection from upper layer.", self.logger.exception)
        binds = { "acquisition_era_name" :acquisition_era_name  , "end_date" : end_date  }
        result = self.dbi.processData(self.sql, binds, conn, transaction)

Response: Update the end date of a given acquisitionera


Instruction:
Can you write a function in Python 3 where it
updates the migration block and the related resources.

Response:
def execute(self, conn, daoinput, transaction = False):
        """
	    daoinput keys:
	    migration_status, migration_block_id, migration_request_id
        """
        #print daoinput['migration_block_id']
        if not conn:
	    dbsExceptionHandler("dbsException-failed-connect2host", "Oracle/MigrationBlock/Update. Expects db connection from upper layer." ,self.logger.exception)
        if daoinput['migration_status'] == 1:
           sql = self.sql + "  (MIGRATION_STATUS = 0  or MIGRATION_STATUS = 3)"
        elif daoinput['migration_status'] == 2 or daoinput['migration_status'] == 3 or daoinput['migration_status'] == 9:
            sql = self.sql + " MIGRATION_STATUS = 1 "
        else:
            dbsExceptionHandler("dbsException-conflict-data", "Oracle/MigrationBlock/Update. Expected migration status to be 1, 2, 3, 0r 9" ,self.logger.exception )
        #print sql
        if 'migration_request_id' in daoinput:
            sql3 = sql + "and MIGRATION_REQUEST_ID =:migration_request_id"
            result = self.dbi.processData(sql3, daoinput, conn, transaction)
        elif 'migration_block_id' in daoinput:
            if type(daoinput['migration_block_id']) is not list:
                sql2 = sql+ " and MIGRATION_BLOCK_ID =:migration_block_id"
                result = self.dbi.processData(sql2, daoinput, conn, transaction)
            else:
                bk_id_generator, binds2 =  create_token_generator(daoinput['migration_block_id'])
                newdaoinput = {}
                newdaoinput.update({"migration_status":daoinput["migration_status"],
                    "last_modification_date":daoinput["last_modification_date"]})
                newdaoinput.update(binds2)
                sql2 = sql+ """ and MIGRATION_BLOCK_ID in ({bk_id_generator} SELECT TOKEN FROM TOKEN_GENERATOR)
                            """.format(bk_id_generator=bk_id_generator)
                result = self.dbi.processData(sql2, newdaoinput, conn, transaction)
        else:
            dbsExceptionHandler("dbsException-conflict-data", "Oracle/MigrationBlock/Update. Required IDs not in the input", self.logger.exception)


Instruction:
How would you implement a function in Python 3 that
gets list of file_id from DB.

Response:
def execute(self, conn, file_id_list, transaction=False):
	"""
	file_id_list : file_id_list
	"""
	sql=self.sql
	binds={}
	if file_id_list:
	    count=0
	    for an_id in file_id_list:
		if count > 0: sql += ", "
		sql += ":file_id_%s" %count
		binds.update({"file_id_%s" %count : an_id})
		count+=1
	    sql += ")"
	else:
            dbsExceptionHandler('dbsException-invalid-input', "Oracle/FileParentBlock/List. this_file_id not provided", self.logger.exception)

        result = self.dbi.processData(sql, binds, conn, transaction)
        plist = self.formatDict(result)
	return plist


Instruction:
Create a Python 3 function to
execute the SQL query and returns the output module config id for the given application release version and global tag.

Response:
def execute(self, conn, app, release_version, pset_hash, output_label, global_tag, transaction = False):
        """
        returns id for a given application

        This always requires all four variables to be set, because
        you better have them in blockInsert
        """
        binds = {}
        binds["app_name"]=app
        binds["release_version"]=release_version
        binds["pset_hash"]=pset_hash
        binds["output_module_label"]=output_label
        binds["global_tag"]=global_tag

        result = self.dbi.processData(self.sql, binds, conn, transaction)

        plist = self.formatDict(result)

	if len(plist) < 1: return -1
        return plist[0]["output_mod_config_id"]


Instruction:
Make a summary of the following Python 3 code
def updateStatus(self, block_name="", open_for_writing=0):
        if open_for_writing not in [1, 0, '1', '0']:
            msg = "DBSBlock/updateStatus. open_for_writing can only be 0 or 1 : passed %s."\
                   % open_for_writing
            dbsExceptionHandler('dbsException-invalid-input', msg)
        conn = self.dbi.connection()
        trans = conn.begin()
        try :
            open_for_writing = int(open_for_writing)
            self.updatestatus.execute(conn, block_name, open_for_writing, dbsUtils().getTime(), trans)
            trans.commit()
            trans = None
        except Exception as ex:
            if trans:
                trans.rollback()
            if conn:conn.close()
            raise ex
        finally:
            if conn:conn.close()

Response: Update status of a specific entry in DBS.


Instruction:
Can you implement a function in Python 3 that
updates the origin_site_name for a given block name

Response:
def updateSiteName(self, block_name, origin_site_name):
        """
        Update the origin_site_name for a given block name
        """
        if not origin_site_name:
            dbsExceptionHandler('dbsException-invalid-input',
                                "DBSBlock/updateSiteName. origin_site_name is mandatory.")
        conn = self.dbi.connection()
        trans = conn.begin()
        try:
            self.updatesitename.execute(conn, block_name, origin_site_name)
        except:
            if trans:
                trans.rollback()
            raise
        else:
            if trans:
                trans.commit()
        finally:
            if conn:
                conn.close()


Instruction:
Can you tell what is the following Python 3 function doing
def listBlockParents(self, block_name=""):
        if not block_name:
            msg = " DBSBlock/listBlockParents. Block_name must be provided as a string or a list. \
                No wildcards allowed in block_name/s."
            dbsExceptionHandler('dbsException-invalid-input', msg)
        elif isinstance(block_name, basestring):
            try:
                block_name = str(block_name)
                if '%' in block_name or '*' in block_name:
                    dbsExceptionHandler("dbsException-invalid-input", "DBSReaderModel/listBlocksParents: \
                    NO WILDCARDS allowed in block_name.")
            except:
                dbsExceptionHandler("dbsException-invalid-input", "DBSBlock/listBlockParents. Block_name must be \
                provided as a string or a list. No wildcards allowed in block_name/s .")
        elif type(block_name) is list:
            for b in block_name:
                if '%' in b or '*' in b:
                    dbsExceptionHandler("dbsException-invalid-input", "DBSReaderModel/listBlocksParents: \
                            NO WILDCARDS allowed in block_name.")
        else:
            msg = "DBSBlock/listBlockParents. Block_name must be provided as a string or a list. \
                No wildcards allowed in block_name/s ."
            dbsExceptionHandler("dbsException-invalid-input", msg)
        conn = self.dbi.connection()
        try:
            results = self.blockparentlist.execute(conn, block_name)
            return results
        finally:
            if conn:
                conn.close()

Response: API to list parents of a block.


Instruction:
How would you implement a function in Python 3 that
lists all parents of a block

Response:
def listBlockChildren(self, block_name=""):
        """
        list parents of a block
        """
        if (not block_name) or re.search("['%','*']", block_name):
            dbsExceptionHandler("dbsException-invalid-input", "DBSBlock/listBlockChildren. Block_name must be provided." )
        conn = self.dbi.connection()
        try:
            results = self.blockchildlist.execute(conn, block_name)
            return results
        finally:
            if conn:
                conn.close()


Instruction:
Explain what the following Python 3 code does
def listBlocks(self, dataset="", block_name="", data_tier_name="", origin_site_name="",
                   logical_file_name="", run_num=-1, min_cdate=0, max_cdate=0,
                   min_ldate=0, max_ldate=0, cdate=0,  ldate=0, open_for_writing=-1, detail=False):
        """
        dataset, block_name, data_tier_name or logical_file_name must be passed.
        """
        if (not dataset) or re.search("['%','*']", dataset):
            if (not block_name) or re.search("['%','*']", block_name):
                if (not logical_file_name) or re.search("['%','*']", logical_file_name):
                    if not data_tier_name or re.search("['%','*']", data_tier_name):
                        msg = "DBSBlock/listBlock. You must specify at least one parameter(dataset, block_name,\
			       	data_tier_name, logical_file_name) with listBlocks api"
                        dbsExceptionHandler('dbsException-invalid-input2', msg, self.logger.exception, msg)

        if data_tier_name:
            if not (min_cdate and max_cdate) or (max_cdate-min_cdate)>32*24*3600:
                msg = "min_cdate and max_cdate are mandatory parameters. If data_tier_name parameter is used \
                       the maximal time range allowed is 31 days"
                dbsExceptionHandler('dbsException-invalid-input2', msg, self.logger.exception, msg)
            if detail:
                msg = "DBSBlock/listBlock. Detail parameter not allowed togther with data_tier_name"
                dbsExceptionHandler('dbsException-invalid-input2', msg, self.logger.exception, msg)

        with self.dbi.connection() as conn:
            dao = (self.blockbrieflist, self.blocklist)[detail]
            for item in dao.execute(conn, dataset, block_name, data_tier_name, origin_site_name, logical_file_name, run_num,
                                 min_cdate, max_cdate, min_ldate, max_ldate, cdate,  ldate):
                yield item

Response: API to list all blocks in DBS.


Instruction:
Can you generate a brief explanation for the following Python 3 code
def insertBlock(self, businput):
        if not ("block_name" in businput and "origin_site_name" in businput  ):
            dbsExceptionHandler('dbsException-invalid-input', "business/DBSBlock/insertBlock must have block_name and origin_site_name as input")
        conn = self.dbi.connection()
        tran = conn.begin()
        try:
            blkinput = {
                "last_modification_date":businput.get("last_modification_date",  dbsUtils().getTime()),
                #"last_modified_by":businput.get("last_modified_by", dbsUtils().getCreateBy()),
                "last_modified_by":dbsUtils().getCreateBy(),
                #"create_by":businput.get("create_by", dbsUtils().getCreateBy()),
                "create_by":dbsUtils().getCreateBy(),
                "creation_date":businput.get("creation_date", dbsUtils().getTime()),
                "open_for_writing":businput.get("open_for_writing", 1),
                "block_size":businput.get("block_size", 0),
                "file_count":businput.get("file_count", 0),
                "block_name":businput.get("block_name"),
                "origin_site_name":businput.get("origin_site_name")
            }
            ds_name = businput["block_name"].split('#')[0]
            blkinput["dataset_id"] = self.datasetid.execute(conn,  ds_name, tran)
            if blkinput["dataset_id"] == -1 :
                msg = "DBSBlock/insertBlock. Dataset %s does not exists" % ds_name
                dbsExceptionHandler('dbsException-missing-data', msg)
            blkinput["block_id"] =  self.sm.increment(conn, "SEQ_BK", tran)
            self.blockin.execute(conn, blkinput, tran)

            tran.commit()
            tran = None
        except Exception as e:
            if str(e).lower().find("unique constraint") != -1 or str(e).lower().find("duplicate") != -1:
                pass
            else:
                if tran:
                    tran.rollback()
                if conn: conn.close()
                raise

        finally:
            if tran:
                tran.rollback()
            if conn:
                conn.close()

Response: Insert a new block into DBS.


Instruction:
Write a Python 3 function for
listing all data tiers in DBS.

Response:
def listDataTiers(self, data_tier_name=""):
        """
        List data tier(s)
        """
        if not isinstance(data_tier_name, basestring) :
            dbsExceptionHandler('dbsException-invalid-input',
                                'data_tier_name given is not valid : %s' % data_tier_name)
        else:
            try:
                data_tier_name = str(data_tier_name)
            except:
                dbsExceptionHandler('dbsException-invalid-input',
                                    'data_tier_name given is not valid : %s' % data_tier_name)
        conn = self.dbi.connection()
        try:
            result = self.dataTier.execute(conn, data_tier_name.upper())
            return result
        finally:
            if conn:
                conn.close()


Instruction:
Create a Python 3 function for
returning a list of all the available types for the given site.

Response:
def execute(self, conn, site_name= "", transaction = False):
        """
        Lists all sites types if site_name is not provided.
        """
        sql = self.sql
        if site_name == "":
            result = self.dbi.processData(sql, conn=conn, transaction=transaction)
        else:
            sql += "WHERE S.SITE_NAME = :site_name"
            binds = { "site_name" : site_name }
            result = self.dbi.processData(sql, binds, conn, transaction)
        return self.formatDict(result)


Instruction:
Make a summary of the following Python 3 code
def listDataType(self, dataType="", dataset=""):
        conn = self.dbi.connection()
        try:
            if dataset and dataType:
                dbsExceptionHandler('dbsException-invalid-input',
                    "DBSDataType/listDataType. Data Type can be only searched by data_type or by dataset, not both.")
            else:
                result = self.dataType.execute(conn, dataType, dataset)
                return result
        finally:
            if conn:
                conn.close()

Response: List data type of a specific resource.


Instruction:
Can you generate the documentation for the following Python 3 function
def getBlocks(self):
        try:
            conn = self.dbi.connection()
            result = self.buflistblks.execute(conn)
            return result
        finally:
            if conn:
                conn.close()

Response: Get the blocks that need to be migrated


Instruction:
Given the following Python 3 function, write the documentation
def getBufferedFiles(self, block_id):

        try:
            conn = self.dbi.connection()
            result = self.buflist.execute(conn, block_id)
            return result
        finally:
            if conn:
                conn.close()

Response: Get some files from the insert buffer


Instruction:
Implement a Python 3 function for
returning a list of all the items in the database that match the given datatier name

Response:
def execute(self, conn, data_tier_name='', transaction = False, cache=None):
        """
        returns id for a given datatier name
        """
	if cache:
            ret=cache.get("DATA_TIERS")
            if not ret==None:
                return ret
        sql = self.sql
	binds={}
	if data_tier_name:
            op = ('=', 'like')['%' in data_tier_name]
	    sql += "WHERE DT.DATA_TIER_NAME %s :datatier" %op
	    binds = {"datatier":data_tier_name}
        result = self.dbi.processData(sql, binds, conn, transaction)
        plist = self.formatDict(result)
        return plist


Instruction:
Can you tell what is the following Python 3 function doing
def execute(self, conn, migration_url="", migration_input="", create_by="", migration_request_id="", transaction=False):
        binds = {}
	result = self.dbi.processData(self.sql, binds, conn, transaction)
        result = self.formatDict(result)
	if len(result) == 0 :
	    return []
	if result[0]["migration_request_id"] in ('', None) :
	    return []
        return result

Response: Executes the SQL query and returns the result.


Instruction:
Write a Python 3 script to
return a list of all processing eras in the database.

Response:
def listProcessingEras(self, processing_version=''):
        """
        Returns all processing eras in dbs
        """
        conn = self.dbi.connection()
        try:
            result = self.pelst.execute(conn, processing_version)
            return result
        finally:
            if conn:
                conn.close()


Instruction:
Explain what the following Python 3 code does
def insertProcessingEra(self, businput):
        conn = self.dbi.connection()
        tran = conn.begin()
        try:
            businput["processing_era_id"] = self.sm.increment(conn, "SEQ_PE", tran)
            businput["processing_version"] = businput["processing_version"]
            self.pein.execute(conn, businput, tran)
            tran.commit()
            tran = None
        except KeyError as ke:
            dbsExceptionHandler('dbsException-invalid-input',
                                "Invalid input:" + ke.args[0])
        except Exception as ex:
            if (str(ex).lower().find("unique constraint") != -1 or
                str(ex).lower().find("duplicate") != -1):
                        # already exist
                self.logger.warning("DBSProcessingEra/insertProcessingEras. " +
                                "Unique constraint violation being ignored...")
                self.logger.warning(ex)
            else:
                if tran:
                    tran.rollback()
                    tran = None
                raise
        finally:
            if tran:
                tran.rollback()
            if conn:
                conn.close()

Response: Insert a new processingEra into the database.


Instruction:
Explain what the following Python 3 code does
def listPhysicsGroups(self, physics_group_name=""):
        if not isinstance(physics_group_name, basestring):
            dbsExceptionHandler('dbsException-invalid-input',
                'physics group name given is not valid : %s' %
                 physics_group_name)
        else:
            try:
                physics_group_name = str(physics_group_name)
            except:
                 dbsExceptionHandler('dbsException-invalid-input',
                                 'physics group name given is not valid : %s' %
                                  physics_group_name)

        conn = self.dbi.connection()
        try:
            result = self.pglist.execute(conn, physics_group_name)
            return result
        finally:
            if conn:
                conn.close()

Response: Get all physics groups in DBS.


Instruction:
How would you explain what the following Python 3 function does
def create_token_generator(input_list):
    ###Generator trick from http://betteratoracle.com/posts/20-how-do-i-bind-a-variable-in-list
    ###The maximum length of the comma separated list is 4000 characters, therefore we need to split the list
    ###ORA-01460: unimplemented or unreasonable conversion requested will thrown if list is larger
    oracle_limit = 4000
    grp_list = []
    if type(input_list[0]) == int :
        input_str = ','.join(map(str, input_list))
    else:
        input_str = ','.join(input_list)

    if len(input_str) >= oracle_limit:
        index = 0
        while True:
            begin, end = index, index+oracle_limit
	    if end > len(input_str):
                end = len(input_str)
                grp_list.append(input_str[begin:end])
                break
	    else:
		index = input_str.rfind(',', begin, end)
		if index == -1:
			break
		grp_list.append(input_str[begin:index])
		index += 1 #to remove the leading comma
    else:
        grp_list.append(input_str)

    token_generator = """
    WITH TOKEN_GENERATOR AS (
    """
    binds = {}
    for index, chunk in enumerate(grp_list):
        if index:
            token_generator += """
            UNION ALL
            """
        bind = "token_%s" % index
        token_generator += """SELECT REGEXP_SUBSTR(:{bind}, '[^,]+', 1, LEVEL) token
        FROM DUAL
        CONNECT BY LEVEL <= LENGTH(:{bind}) - LENGTH(REPLACE(:{bind}, ',', '')) + 1
        """.format(bind=bind)
        binds.update({bind: chunk})
    token_generator += ")"

    return token_generator, binds

Response: Create SQL Generator to select from list of values in Oracle


Instruction:
Explain what the following Python 3 code does
def getServices(self):
        try:
            conn = self.dbi.connection()
            result = self.serviceslist.execute(conn)
            return result
        except Exception as ex:
            msg = (("%s DBSServicesRegistry/getServices." +
                    " %s\n. Exception trace: \n %s") %
                   (DBSEXCEPTIONS['dbsException-3'], ex,
                    traceback.format_exc()))
            self.logger.exception(msg )
            raise Exception ("dbsException-3", msg )
        finally:
            conn.close()

Response: Simple method that returns list of all known DBS instances


Instruction:
Can you write a function in Python 3 where it
adds a service to the service registry

Response:
def addService(self):
        """
        Add a service to service registry
        """

        conn = self.dbi.connection()
        tran = conn.begin()
        try:

            body = request.body.read()
            service = cjson.decode(body)
            addthis = {}
            addthis['service_id'] = self.sm.increment(conn, "SEQ_RS", tran)
            addthis['name'] = service.get('NAME', '')
            if addthis['name'] == '':
                msg = (("%s DBSServicesRegistry/addServices." +
                        " Service Must be Named\n") %
                       DBSEXCEPTIONS['dbsException-3'])
                raise Exception("dbsException-3", msg)
            addthis['type'] = service.get('TYPE', 'GENERIC')
            addthis['location'] = service.get('LOCATION', 'HYPERSPACE')
            addthis['status'] = service.get('STATUS', 'UNKNOWN')
            addthis['admin'] = service.get('ADMIN', 'UNADMINISTRATED')
            addthis['uri'] = service.get('URI', '')
            if addthis['uri'] == '':
                msg = (("%s DBSServicesRegistry/addServices." +
                        " Service URI must be provided.\n") %
                       DBSEXCEPTIONS['dbsException-3'])
                self.logger.exception(msg)
                raise Exception("dbsException-3", msg)
            addthis['db'] = service.get('DB', 'NO_DATABASE')
            addthis['version'] = service.get('VERSION', 'UNKNOWN' )
            addthis['last_contact'] = dbsUtils().getTime()
            addthis['comments'] = service.get('COMMENTS', 'NO COMMENTS')
            addthis['alias'] = service.get('ALIAS', 'No Alias')
            self.servicesadd.execute(conn, addthis, tran)
            tran.commit()
        except exceptions.IntegrityError as ex:
            if (str(ex).find("unique constraint") != -1 or
                str(ex).lower().find("duplicate") != -1) :
                #Update the service instead
                try:
                    self.servicesupdate.execute(conn, addthis, tran)
                    tran.commit()
                except Exception as ex:
                    msg = (("%s DBSServiceRegistry/addServices." +
                            " %s\n. Exception trace: \n %s") %
                           (DBSEXCEPTIONS['dbsException-3'], ex,
                            traceback.format_exc()))
                    self.logger.exception(msg )
                    raise Exception ("dbsException-3", msg )
        except Exception as ex:
            tran.rollback()
            msg = (("%s DBSServiceRegistry/addServices." +
                    " %s\n. Exception trace: \n %s") %
                   (DBSEXCEPTIONS['dbsException-3'], ex,
                    traceback.format_exc()))
            self.logger.exception(msg )
            raise Exception ("dbsException-3", msg )
        finally:
            conn.close()


Instruction:
Here you have a function in Python 3, explain what it does
def execute(self, conn, daoinput, transaction = False):
        if not conn:
	    dbsExceptionHandler("dbsException-failed-connect2host", "Oracle/MigrationRequests/UpdateRequestStatus. Expects db connection from upper layer.",
                                self.logger.exception)
        if daoinput['migration_status'] == 1:
           sql = self.sql2
        elif daoinput['migration_status'] == 2:
            sql = self.sql + " and MIGRATION_STATUS = 1 "
        elif daoinput['migration_status'] == 3:
            sql = self.sql3 + " and MIGRATION_STATUS = 1 "
        else:
            dbsExceptionHandler("dbsException-conflict-data", "Oracle/MigrationRequest/UpdateRequestStatus. Expected migration status to be 1, 2 or 3",
                                self.logger.exception)

	result = self.dbi.processData(sql, daoinput, conn, transaction)

Response: Update the migration request status.


Instruction:
Can you write a function in Python 3 where it
lists all the available migration resources.

Response:
def execute(self, conn, migration_url="", migration_input="", create_by="", migration_request_id="", oldest= False, transaction=False):
        """
        Lists all requests if pattern is not provided.
        """
        sql = self.sql
        binds = {}
	if migration_request_id:
	    sql += " WHERE MR.MIGRATION_REQUEST_ID=:migration_request_id"
	    binds['migration_request_id']=migration_request_id
        elif oldest:
            #FIXME: Need to write the sql.YG
            #current_date = dbsUtils().getTime()
            #we require waiting time for
            #retry_count=0 is 1 minutes
            #retry_count=1 is 2 minutes
            #retyr_count=2 is 4 minutes

            sql += """
                       WHERE MR.MIGRATION_STATUS=0
                       or (MR.migration_status=3 and MR.retry_count=0 and MR.last_modification_date <= :current_date-60)
                       or (MR.migration_status=3 and MR.retry_count=1 and MR.last_modification_date <= :current_date-120)
                       or (MR.migration_status=3 and MR.retry_count=2 and MR.last_modification_date <= :current_date-240)
                       ORDER BY MR.creation_date
                   """
            binds['current_date'] = dbsUtils().getTime()
            #print "time= " + str(binds['current_date'])
        else:
	    if  migration_url or migration_input or create_by:
		sql += " WHERE "
	    if migration_url:
		sql += " MR.MIGRATION_URL=:migration_url"
		binds['migration_url']=migration_url
	    if  migration_input:
		if migration_url:
		    sql += " AND "
		op = ("=", "like")["%" in migration_input]
		sql += " MR.MIGRATION_INPUT %s :migration_input" % op
		binds['migration_input']=migration_input
	    if create_by:
		if  migration_url or migration_input:
		    sql += " AND "
		sql += " MR.CREATE_BY=:create_by" %create_by
		binds['create_by']=create_by
	cursors = self.dbi.processData(sql, binds, conn, transaction, returnCursor=True)
        result = []
        for c in cursors:
            result.extend(self.formatCursor(c, size=100))
        return result


Instruction:
How would you explain what the following Python 3 function does
def execute(self, conn, logical_file_name, transaction=False):
	if not conn:
	    dbsExceptionHandler("dbsException-db-conn-failed", "Oracle/FileBuffer/DeleteDupicates. Expects db connection from upper layer.")

	print(self.sql)
        self.dbi.processData(self.sql, logical_file_name, conn, transaction)

Response: Delete duplicate entries from DB.


Instruction:
Can you implement a function in Python 3 that
gets all the related resources for a given block.

Response:
def execute(self, conn, block_name="", transaction = False):
        """
        block: /a/b/c#d
        """
        if not conn:
	    dbsExceptionHandler("dbsException-failed-connect2host", "Oracle/BlockParent/List. Expects db connection from upper layer.", self.logger.exception)

        sql = self.sql

	if isinstance(block_name, basestring):
	    binds = {'block_name' :block_name}
        elif type(block_name) is list:
            binds = [{'block_name':x} for x in block_name]
        else:
            msg = "Oracle/BlockParent/List. Block_name must be provided either as a string or as a list."
            dbsExceptionHandler('dbsException-invalid-input', msg, self.logger.exception)
	result = self.dbi.processData(sql, binds, conn, transaction)
        return self.formatDict(result)


Instruction:
Given the following Python 3 function, write the documentation
def execute(self, conn,  origin_site_name="", dataset="", block_name="", transaction = False):
        if not conn:
            dbsExceptionHandler("dbsException-db-conn-failed",
                                "Oracle/Block/List.  Expects db connection from upper layer.", self.logger.exception)
        binds = {}
        if origin_site_name:
            wheresql = 'WHERE B.ORIGIN_SITE_NAME = :origin_site_name'
            binds.update(origin_site_name=origin_site_name)

        if dataset:
            if 'wheresql' in locals():
                wheresql += ' AND DS.DATASET = :dataset'
            else:
                wheresql = 'WHERE DS.DATASET = :dataset'
            binds.update(dataset=dataset)

        if block_name:
            if 'wheresql' in locals():
                wheresql += ' AND B.BLOCK_NAME = :block_name'
            else:
                wheresql = 'WHERE B.BLOCK_NAME = :block_name'
            binds.update(block_name=block_name)

        sql = '{sql} {wheresql}'.format(sql=self.sql, wheresql=wheresql)

        cursors = self.dbi.processData(sql, binds, conn, transaction, returnCursor=True)
        result = []
        for cursor in cursors:
            result.extend(self.formatCursor(cursor, size=100))
        return result

Response: Returns list of all available buffer entries for a given origin site name dataset and block name.


Instruction:
Make a summary of the following Python 3 code
def listPrimaryDatasets(self, primary_ds_name="", primary_ds_type=""):
        conn = self.dbi.connection()
        try:
            result = self.primdslist.execute(conn, primary_ds_name, primary_ds_type)
            if conn: conn.close()
            return result
        finally:
            if conn:
                conn.close()

Response: Returns a list of all primary datasets.


Instruction:
Make a summary of the following Python 3 code
def listPrimaryDSTypes(self, primary_ds_type="", dataset=""):
        conn = self.dbi.connection()
        try:
            result = self.primdstypeList.execute(conn, primary_ds_type, dataset)
            if conn: conn.close()
            return result
        finally:
            if conn:
                conn.close()

Response: Returns a list of primary dataset types.


Instruction:
Given the following Python 3 function, write the documentation
def insertPrimaryDataset(self, businput):
        conn = self.dbi.connection()
        tran = conn.begin()
        #checking for required fields
        if "primary_ds_name" not in businput:
            dbsExceptionHandler("dbsException-invalid-input",
                " DBSPrimaryDataset/insertPrimaryDataset. " +
                "Primary dataset Name is required for insertPrimaryDataset.")
        try:
            businput["primary_ds_type_id"] = (self.primdstypeList.execute(conn, businput["primary_ds_type"]
                ))[0]["primary_ds_type_id"]
            del businput["primary_ds_type"]
            businput["primary_ds_id"] = self.sm.increment(conn, "SEQ_PDS")
            self.primdsin.execute(conn, businput, tran)
            tran.commit()
            tran = None
        except KeyError as ke:
            dbsExceptionHandler("dbsException-invalid-input",
                " DBSPrimaryDataset/insertPrimaryDataset. Missing: %s" % ke)
            self.logger.warning(" DBSPrimaryDataset/insertPrimaryDataset. Missing: %s" % ke)
        except IndexError as ie:
            dbsExceptionHandler("dbsException-missing-data",
                " DBSPrimaryDataset/insertPrimaryDataset. %s" % ie)
            self.logger.warning(" DBSPrimaryDataset/insertPrimaryDataset. Missing: %s" % ie)
        except Exception as ex:
            if (str(ex).lower().find("unique constraint") != -1 or
                str(ex).lower().find("duplicate") != -1):
                self.logger.warning("DBSPrimaryDataset/insertPrimaryDataset:" +
                        " Unique constraint violation being ignored...")
                self.logger.warning(ex)
            else:
                if tran:
                    tran.rollback()
                if conn: conn.close()
                raise
        finally:
            if tran:
                tran.rollback()
            if conn:
                conn.close()

Response: Insert a new primary dataset into the database.


Instruction:
Can you generate the documentation for the following Python 3 function
def execute(self, conn, name='', transaction = False):
        binds={}
        if name:
            op = ('=', 'like')['%' in name]
            sql = self.sql + "  WHERE pg.physics_group_name %s :physicsgroup" % (op)
            binds = {"physicsgroup": name}
        else:
            sql = self.sql
        self.logger.debug(sql)
        result = self.dbi.processData(sql, binds, conn, transaction)
        plist = self.formatDict(result)
        self.logger.debug(plist)
	if len(plist) < 1: return []
        return plist

Response: returns a list of physics group names


Instruction:
How would you explain what the following Python 3 function does
def insertOutputConfig(self, businput):
        if not ("app_name" in businput  and "release_version" in businput\
            and "pset_hash" in businput and "output_module_label" in businput
            and "global_tag" in businput):
            dbsExceptionHandler('dbsException-invalid-input', "business/DBSOutputConfig/insertOutputConfig require:\
                app_name, release_version, pset_hash, output_module_label and global_tag")

        conn = self.dbi.connection()
        tran = conn.begin()
        try:
            # Proceed with o/p module insertion
            businput['scenario'] = businput.get("scenario", None)
            businput['pset_name'] = businput.get("pset_name", None)
            self.outmodin.execute(conn, businput, tran)
            tran.commit()
            tran = None
        except SQLAlchemyIntegrityError as ex:
            if str(ex).find("unique constraint") != -1 or str(ex).lower().find("duplicate") != -1:
                #if the validation is due to a unique constrain break in OUTPUT_MODULE_CONFIGS
                if str(ex).find("TUC_OMC_1") != -1: pass
                #otherwise, try again
                else:
                    try:
                        self.outmodin.execute(conn, businput, tran)
                        tran.commit()
                        tran =  None
                    except SQLAlchemyIntegrityError as ex1:
                        if str(ex1).find("unique constraint") != -1 and str(ex1).find("TUC_OMC_1") != -1: pass
                    except Exception as e1:
                        if tran:
                            tran.rollback()
                            tran = None
                        raise
            else:
                raise
        except Exception as e:
            if tran:
                tran.rollback()
            raise
        finally:
            if tran:
                tran.rollback()
            if conn:
                conn.close()

Response: Insert the Output Config into DBS.


Instruction:
How would you implement a function in Python 3 that
gets a list of supported REST APIs.

Response:
def getHelp(self, call=""):
        """
        API to get a list of supported REST APIs. In the case a particular API is specified,
        the docstring of that API is displayed.

        :param call: call to get detailed information about (Optional)
        :type call: str
        :return: List of APIs or detailed information about a specific call (parameters and docstring)
        :rtype: List of strings or a dictionary containing params and doc keys depending on the input parameter

        """
        if call:
            params = self.methods['GET'][call]['args']
            doc = self.methods['GET'][call]['call'].__doc__
            return dict(params=params, doc=doc)
        else:
            return self.methods['GET'].keys()


Instruction:
Given the following Python 3 function, write the documentation
def listDatasets(self, dataset="", parent_dataset="", is_dataset_valid=1,
        release_version="", pset_hash="", app_name="", output_module_label="", global_tag="",
        processing_version=0, acquisition_era_name="", run_num=-1,
        physics_group_name="", logical_file_name="", primary_ds_name="", primary_ds_type="",
        processed_ds_name='', data_tier_name="", dataset_access_type="VALID", prep_id='', create_by="", last_modified_by="",
        min_cdate='0', max_cdate='0', min_ldate='0', max_ldate='0', cdate='0',
        ldate='0', detail=False, dataset_id=-1):
        """
        API to list dataset(s) in DBS
        * You can use ANY combination of these parameters in this API
        * In absence of parameters, all valid datasets known to the DBS instance will be returned

        :param dataset:  Full dataset (path) of the dataset.
        :type dataset: str
        :param parent_dataset: Full dataset (path) of the dataset
        :type parent_dataset: str
        :param release_version: cmssw version
        :type release_version: str
        :param pset_hash: pset hash
        :type pset_hash: str
        :param app_name: Application name (generally it is cmsRun)
        :type app_name: str
        :param output_module_label: output_module_label
        :type output_module_label: str
        :param global_tag: global_tag
        :type global_tag: str
        :param processing_version: Processing Version
        :type processing_version: str
        :param acquisition_era_name: Acquisition Era
        :type acquisition_era_name: str
        :param run_num: Specify a specific run number or range. Possible format are: run_num, 'run_min-run_max' or ['run_min-run_max', run1, run2, ...]. run_num=1 is not allowed.
        :type run_num: int,list,str
        :param physics_group_name: List only dataset having physics_group_name attribute
        :type physics_group_name: str
        :param logical_file_name: List dataset containing the logical_file_name
        :type logical_file_name: str
        :param primary_ds_name: Primary Dataset Name
        :type primary_ds_name: str
        :param primary_ds_type: Primary Dataset Type (Type of data, MC/DATA)
        :type primary_ds_type: str
        :param processed_ds_name: List datasets having this processed dataset name
        :type processed_ds_name: str
        :param data_tier_name: Data Tier
        :type data_tier_name: str
        :param dataset_access_type: Dataset Access Type ( PRODUCTION, DEPRECATED etc.)
        :type dataset_access_type: str
        :param prep_id: prep_id
        :type prep_id: str
        :param create_by: Creator of the dataset
        :type create_by: str
        :param last_modified_by: Last modifier of the dataset
        :type last_modified_by: str
        :param min_cdate: Lower limit for the creation date (unixtime) (Optional)
        :type min_cdate: int, str
        :param max_cdate: Upper limit for the creation date (unixtime) (Optional)
        :type max_cdate: int, str
        :param min_ldate: Lower limit for the last modification date (unixtime) (Optional)
        :type min_ldate: int, str
        :param max_ldate: Upper limit for the last modification date (unixtime) (Optional)
        :type max_ldate: int, str
        :param cdate: creation date (unixtime) (Optional)
        :type cdate: int, str
        :param ldate: last modification date (unixtime) (Optional)
        :type ldate: int, str
        :param detail: List all details of a dataset
        :type detail: bool
        :param dataset_id: dataset table primary key used by CMS Computing Analytics.
        :type dataset_id: int, long, str
        :returns: List of dictionaries containing the following keys (dataset). If the detail option is used. The dictionary contain the following keys (primary_ds_name, physics_group_name, acquisition_era_name, create_by, dataset_access_type, data_tier_name, last_modified_by, creation_date, processing_version, processed_ds_name, xtcrosssection, last_modification_date, dataset_id, dataset, prep_id, primary_ds_type)
        :rtype: list of dicts

        """
        dataset = dataset.replace("*", "%")
        parent_dataset = parent_dataset.replace("*", "%")
        release_version = release_version.replace("*", "%")
        pset_hash = pset_hash.replace("*", "%")
        app_name = app_name.replace("*", "%")
        output_module_label = output_module_label.replace("*", "%")
        global_tag = global_tag.replace("*", "%")
        logical_file_name = logical_file_name.replace("*", "%")
        physics_group_name = physics_group_name.replace("*", "%")
        primary_ds_name = primary_ds_name.replace("*", "%")
        primary_ds_type = primary_ds_type.replace("*", "%")
        data_tier_name = data_tier_name.replace("*", "%")
        dataset_access_type = dataset_access_type.replace("*", "%")
        processed_ds_name = processed_ds_name.replace("*", "%")
        acquisition_era_name = acquisition_era_name.replace("*", "%")
        #processing_version =  processing_version.replace("*", "%")
        #create_by and last_modified_by have be full spelled, no wildcard will allowed.
        #We got them from request head so they can be either HN account name or DN.
        #This is depended on how an user's account is set up.
        #
        # In the next release we will require dataset has no wildcard in it.
        # DBS will reject wildcard search with dataset name with listDatasets call.
        # One should seperate the dataset into primary , process and datatier if any wildcard.
        # YG Oct 26, 2016
        # Some of users were overwhiled by the API change. So we split the wildcarded dataset in the server instead of by the client.
        # YG Dec. 9 2016
        #
        # run_num=1 caused full table scan and CERN DBS reported some of the queries ran more than 50 hours
        # We will disbale all the run_num=1 calls in DBS. Run_num=1 will be OK when logical_file_name is given.
        # YG Jan. 15 2019
        #
        if (run_num != -1 and logical_file_name ==''):
            for r in parseRunRange(run_num):
                if isinstance(r, basestring) or isinstance(r, int) or isinstance(r, long):
                    if r == 1 or r == '1':
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
                elif isinstance(r, run_tuple):
                    if r[0] == r[1]:
                        dbsExceptionHandler('dbsException-invalid-input', "DBS run range must be apart at least by 1.",
                          self.logger.exception)
                    elif r[0] <= 1 <= r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)

        if( dataset and ( dataset == "/%/%/%" or dataset== "/%" or dataset == "/%/%" ) ):
            dataset=''
        elif( dataset and ( dataset.find('%') != -1 ) ) :
            junk, primary_ds_name, processed_ds_name, data_tier_name = dataset.split('/')
            dataset = ''
        if ( primary_ds_name == '%' ):
            primary_ds_name = ''
        if( processed_ds_name == '%' ):
            processed_ds_name = ''
        if ( data_tier_name == '%' ):
            data_tier_name = ''

        try:
            dataset_id = int(dataset_id)
        except:
            dbsExceptionHandler("dbsException-invalid-input2", "Invalid Input for dataset_id that has to be an int.",
                                self.logger.exception, 'dataset_id has to be an int.')
        if create_by.find('*')!=-1 or create_by.find('%')!=-1 or last_modified_by.find('*')!=-1\
                or last_modified_by.find('%')!=-1:
            dbsExceptionHandler("dbsException-invalid-input2", "Invalid Input for create_by or last_modified_by.\
            No wildcard allowed.",  self.logger.exception, 'No wildcards allowed for create_by or last_modified_by')
        try:
            if isinstance(min_cdate, basestring) and ('*' in min_cdate or '%' in min_cdate):
                min_cdate = 0
            else:
                try:
                    min_cdate = int(min_cdate)
                except:
                    dbsExceptionHandler("dbsException-invalid-input", "invalid input for min_cdate")

            if isinstance(max_cdate, basestring) and ('*' in max_cdate or '%' in max_cdate):
                max_cdate = 0
            else:
                try:
                    max_cdate = int(max_cdate)
                except:
                    dbsExceptionHandler("dbsException-invalid-input", "invalid input for max_cdate")

            if isinstance(min_ldate, basestring) and ('*' in min_ldate or '%' in min_ldate):
                min_ldate = 0
            else:
                try:
                    min_ldate = int(min_ldate)
                except:
                    dbsExceptionHandler("dbsException-invalid-input", "invalid input for min_ldate")

            if isinstance(max_ldate, basestring) and ('*' in max_ldate or '%' in max_ldate):
                max_ldate = 0
            else:
                try:
                    max_ldate = int(max_ldate)
                except:
                    dbsExceptionHandler("dbsException-invalid-input", "invalid input for max_ldate")

            if isinstance(cdate, basestring) and ('*' in cdate or '%' in cdate):
                cdate = 0
            else:
                try:
                    cdate = int(cdate)
                except:
                    dbsExceptionHandler("dbsException-invalid-input", "invalid input for cdate")

            if isinstance(ldate, basestring) and ('*' in ldate or '%' in ldate):
                ldate = 0
            else:
                try:
                    ldate = int(ldate)
                except:
                    dbsExceptionHandler("dbsException-invalid-input", "invalid input for ldate")
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listDatasets.  %s \n. Exception trace: \n %s" \
                % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

        detail = detail in (True, 1, "True", "1", 'true')
        try:
            return self.dbsDataset.listDatasets(dataset, parent_dataset, is_dataset_valid, release_version, pset_hash,
                app_name, output_module_label, global_tag, processing_version, acquisition_era_name,
                run_num, physics_group_name, logical_file_name, primary_ds_name, primary_ds_type, processed_ds_name,
                data_tier_name, dataset_access_type, prep_id, create_by, last_modified_by,
                min_cdate, max_cdate, min_ldate, max_ldate, cdate, ldate, detail, dataset_id)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listdatasets. %s.\n Exception trace: \n %s" % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: This function returns a list of all valid datasets in the DBS instance.


Instruction:
Can you generate the documentation for the following Python 3 function
def listDatasetArray(self):
        ret = []
        try :
            body = request.body.read()
            if body:
                data = cjson.decode(body)
                data = validateJSONInputNoCopy("dataset", data, read=True)
                #Because CMSWEB has a 300 seconds responding time. We have to limit the array siz to make sure that
                #the API can be finished in 300 second.
                # YG Nov-05-2015
                max_array_size = 1000
                if ( 'dataset' in data.keys() and isinstance(data['dataset'], list) and len(data['dataset'])>max_array_size)\
                    or ('dataset_id' in data.keys() and isinstance(data['dataset_id'], list) and len(data['dataset_id'])>max_array_size):
                    dbsExceptionHandler("dbsException-invalid-input",
                                        "The Max list length supported in listDatasetArray is %s." %max_array_size, self.logger.exception)
                ret = self.dbsDataset.listDatasetArray(data)
        except cjson.DecodeError as De:
            dbsExceptionHandler('dbsException-invalid-input2', "Invalid input", self.logger.exception, str(De))
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except HTTPError as he:
            raise he
        except Exception as ex:
            sError = "DBSReaderModel/listDatasetArray. %s \n Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)
        for item in ret:
                    yield item

Response: API to list datasets in DBS.


Instruction:
Given the following Python 3 function, write the documentation
def listBlocks(self, dataset="", block_name="", data_tier_name="", origin_site_name="",
                   logical_file_name="",run_num=-1, min_cdate='0', max_cdate='0',
                   min_ldate='0', max_ldate='0', cdate='0',  ldate='0', open_for_writing=-1, detail=False):

        """
        API to list a block in DBS. At least one of the parameters block_name, dataset, data_tier_name or
        logical_file_name are required. If data_tier_name is provided, min_cdate and max_cdate have to be specified and
        the difference in time have to be less than 31 days.

        :param block_name: name of the block
        :type block_name: str
        :param dataset: dataset
        :type dataset: str
        :param data_tier_name: data tier
        :type data_tier_name: str
        :param logical_file_name: Logical File Name
        :type logical_file_name: str
        :param origin_site_name: Origin Site Name (Optional)
        :type origin_site_name: str
        :param open_for_writing: Open for Writting (Optional)
        :type open_for_writing: int (0 or 1)
        :param run_num: run_num numbers (Optional). Possible format are: run_num, 'run_min-run_max' or ['run_min-run_max', run1, run2, ...].
        :type run_num: int, list of runs or list of run ranges
        :param min_cdate: Lower limit for the creation date (unixtime) (Optional)
        :type min_cdate: int, str
        :param max_cdate: Upper limit for the creation date (unixtime) (Optional)
        :type max_cdate: int, str
        :param min_ldate: Lower limit for the last modification date (unixtime) (Optional)
        :type min_ldate: int, str
        :param max_ldate: Upper limit for the last modification date (unixtime) (Optional)
        :type max_ldate: int, str
        :param cdate: creation date (unixtime) (Optional)
        :type cdate: int, str
        :param ldate: last modification date (unixtime) (Optional)
        :type ldate: int, str
        :param detail: Get detailed information of a block (Optional)
        :type detail: bool
        :returns: List of dictionaries containing following keys (block_name). If option detail is used the dictionaries contain the following keys (block_id, create_by, creation_date, open_for_writing, last_modified_by, dataset, block_name, file_count, origin_site_name, last_modification_date, dataset_id and block_size)
        :rtype: list of dicts

        """
        # run_num=1 caused full table scan and CERN DBS reported some of the queries ran more than 50 hours
        # We will disbale all the run_num=1 calls in DBS. Run_num=1 will be OK while logical_file_name is given.
        # YG Jan. 15 2019
        #
        if (run_num != -1 and logical_file_name ==''):
            for r in parseRunRange(run_num):
                if isinstance(r, basestring) or isinstance(r, int) or isinstance(r, long):
                    if r == 1 or r == '1':
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
                elif isinstance(r, run_tuple):
                    if r[0] == r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "DBS run range must be apart at least by 1.",
                          self.logger.exception)
                    elif r[0] <= 1 <= r[1]:
                        dbsExceptionHandler("dbsException-invalid-input2", "Run_num=1 is not a valid input.",
                                self.logger.exception)

        dataset = dataset.replace("*", "%")
        block_name = block_name.replace("*", "%")
        logical_file_name = logical_file_name.replace("*", "%")
        origin_site_name = origin_site_name.replace("*", "%")
        #
	if isinstance(min_cdate, basestring) and ('*' in min_cdate or '%' in min_cdate):
            min_cdate = 0
        else:
            try:
                min_cdate = int(min_cdate)
            except:
                dbsExceptionHandler("dbsException-invalid-input", "invalid input for min_cdate")
        #
        if isinstance(max_cdate, basestring) and ('*' in max_cdate or '%' in max_cdate):
            max_cdate = 0
        else:
            try:
                max_cdate = int(max_cdate)
            except:
                dbsExceptionHandler("dbsException-invalid-input", "invalid input for max_cdate")
        #
        if isinstance(min_ldate, basestring) and ('*' in min_ldate or '%' in min_ldate):
            min_ldate = 0
        else:
            try:
                min_ldate = int(min_ldate)
            except:
                dbsExceptionHandler("dbsException-invalid-input", "invalid input for max_cdate")
        #
	if isinstance(max_ldate, basestring) and ('*' in max_ldate or '%' in max_ldate):
            max_ldate = 0
        else:
            try:
                max_ldate = int(max_ldate)
            except:
                dbsExceptionHandler("dbsException-invalid-input", "invalid input for max_ldate")
        #
        if isinstance(cdate, basestring) and ('*' in cdate or '%' in cdate):
            cdate = 0
        else:
            try:
                cdate = int(cdate)
            except:
                dbsExceptionHandler("dbsException-invalid-input", "invalid input for cdate")
        #
        if isinstance(cdate, basestring) and ('*' in ldate or '%' in ldate):
            ldate = 0
        else:
            try:
                ldate = int(ldate)
            except:
                dbsExceptionHandler("dbsException-invalid-input", "invalid input for ldate")
        #
        detail = detail in (True, 1, "True", "1", 'true')
        try:
            b= self.dbsBlock.listBlocks(dataset, block_name, data_tier_name, origin_site_name, logical_file_name,
                                  run_num, min_cdate, max_cdate, min_ldate, max_ldate, cdate, ldate, open_for_writing, detail)
	    #for item in b:
		#yield item
	    return b
	except HTTPError:
	    raise
	except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listBlocks. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: This method returns a list of all blocks in DBS.


Instruction:
Make a summary of the following Python 3 code
def listBlockOrigin(self, origin_site_name="",  dataset="", block_name=""):
        try:
            return self.dbsBlock.listBlocksOrigin(origin_site_name, dataset, block_name)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listBlocks. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'],
                                self.logger.exception, sError)

Response: API to list blocks in origin_site_name.


Instruction:
Can you generate a brief explanation for the following Python 3 code
def listBlockChildren(self, block_name=""):
        block_name = block_name.replace("*", "%")
        try:
            return self.dbsBlock.listBlockChildren(block_name)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listBlockChildren. %s\n. Exception trace: \n %s" % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to list block children.


Instruction:
Can you generate a brief explanation for the following Python 3 code
def listBlockSummaries(self, block_name="", dataset="", detail=False):
        if bool(dataset)+bool(block_name)!=1:
            dbsExceptionHandler("dbsException-invalid-input2",
                                dbsExceptionCode["dbsException-invalid-input2"],
                                self.logger.exception,
                                "Dataset or block_names must be specified at a time.")

        if block_name and isinstance(block_name, basestring):
            try:
                block_name = [str(block_name)]
            except:
                dbsExceptionHandler("dbsException-invalid-input", "Invalid block_name for listBlockSummaries. ")

        for this_block_name in block_name:
            if re.search("[*, %]", this_block_name):
                dbsExceptionHandler("dbsException-invalid-input2",
                                    dbsExceptionCode["dbsException-invalid-input2"],
                                    self.logger.exception,
                                    "No wildcards are allowed in block_name list")

        if re.search("[*, %]", dataset):
            dbsExceptionHandler("dbsException-invalid-input2",
                                dbsExceptionCode["dbsException-invalid-input2"],
                                self.logger.exception,
                                "No wildcards are allowed in dataset")
        data = []
        try:
            with self.dbi.connection() as conn:
                data = self.dbsBlockSummaryListDAO.execute(conn, block_name, dataset, detail)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listBlockSummaries. %s\n. Exception trace: \n %s" % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error',
                                dbsExceptionCode['dbsException-server-error'],
                                self.logger.exception,
                                sError)
        for item in data:
                    yield item

Response: API that returns total size file count and event counts of a dataset or a list of blocks.


Instruction:
Can you tell what is the following Python 3 function doing
def listFiles(self, dataset = "", block_name = "", logical_file_name = "",
        release_version="", pset_hash="", app_name="", output_module_label="",
        run_num=-1, origin_site_name="", lumi_list="", detail=False, validFileOnly=0, sumOverLumi=0):
        """
        API to list files in DBS. Either non-wildcarded logical_file_name, non-wildcarded dataset or non-wildcarded block_name is required.
        The combination of a non-wildcarded dataset or block_name with an wildcarded logical_file_name is supported.

        * For lumi_list the following two json formats are supported:
            - [a1, a2, a3,]
            - [[a,b], [c, d],]
	* lumi_list can be either a list of lumi section numbers as [a1, a2, a3,] or a list of lumi section range as [[a,b], [c, d],]. Thay cannot be mixed.
        * If lumi_list is provided run only run_num=single-run-number is allowed
	* When lfn list is present, no run or lumi list is allowed.

        *There are five dataset access types: VALID, INVALID, PRODUCTION, DEPRECATED and DELETED.
        * One file status: IS_FILE_VALID: 1 or 0.
        * When a dataset is INVALID/ DEPRECATED/ DELETED, DBS will consider all the files under it is invalid not matter what value is_file_valid has.
          In general, when the dataset is in one of INVALID/ DEPRECATED/ DELETED, is_file_valid should all marked as 0, but some old DBS2 data was not.
        * When Dataset is VALID/PRODUCTION, by default is_file_valid is all 1. But if individual file is invalid, then the file's is_file_valid is set to 0.
        * DBS use this logical in its APIs that have validFileOnly variable.

        *There are five dataset access types: VALID, INVALID, PRODUCTION, DEPRECATED and DELETED.
        * One file status: IS_FILE_VALID: 1 or 0.
        * When a dataset is INVALID/ DEPRECATED/ DELETED, DBS will consider all the files under it is invalid not matter what value is_file_valid has.
          In general, when the dataset is in one of INVALID/ DEPRECATED/ DELETED, is_file_valid should all marked as 0, but some old DBS2 data was not.
        * When Dataset is VALID/PRODUCTION, by default is_file_valid is all 1. But if individual file is invalid, then the file's is_file_valid is set to 0.
        * DBS use this logical in its APIs that have validFileOnly variable.

        :param logical_file_name: logical_file_name of the file
        :type logical_file_name: str
        :param dataset: dataset
        :type dataset: str
        :param block_name: block name
        :type block_name: str
        :param release_version: release version
        :type release_version: str
        :param pset_hash: parameter set hash
        :type pset_hash: str
        :param app_name: Name of the application
        :type app_name: str
        :param output_module_label: name of the used output module
        :type output_module_label: str
        :param run_num: run , run ranges, and run list. Possible format are: run_num, 'run_min-run_max' or ['run_min-run_max', run1, run2, ...].
        :type run_num: int, list, string
        :param origin_site_name: site where the file was created
        :type origin_site_name: str
        :param lumi_list: List containing luminosity sections
        :type lumi_list: list
        :param detail: Get detailed information about a file
        :type detail: bool
        :param validFileOnly: default=0 return all the files. when =1, only return files with is_file_valid=1 or dataset_access_type=PRODUCTION or VALID
        :type validFileOnly: int
        :param sumOverLumi: default=0 event_count is the event_count/file.  When sumOverLumi=1 and run_num is specified, the event_count is sum of the event_count/lumi for that run; When sumOverLumi = 1, no other input can be a list, for example no run_num list, lumi list or lfn list.
        :type sumOverLumi: int
        :returns: List of dictionaries containing the following keys (logical_file_name). If detail parameter is true, the dictionaries contain the following keys (check_sum, branch_hash_id, adler32, block_id, event_count, file_type, create_by, logical_file_name, creation_date, last_modified_by, dataset, block_name, file_id, file_size, last_modification_date, dataset_id, file_type_id, auto_cross_section, md5, is_file_valid)
        :rtype: list of dicts

        """
        logical_file_name = logical_file_name.replace("*", "%")
        release_version = release_version.replace("*", "%")
        pset_hash = pset_hash.replace("*", "%")
        app_name = app_name.replace("*", "%")
        block_name = block_name.replace("*", "%")
        origin_site_name = origin_site_name.replace("*", "%")
        dataset = dataset.replace("*", "%")
        #
        # run_num=1 caused full table scan and CERN DBS reported some of the queries ran more than 50 hours
        # We will disbale all the run_num=1 calls in DBS. Run_num=1 will be OK when logical_file_name is given.
        # YG Jan. 15 2019
        #
        if (run_num != -1 and logical_file_name ==''):
            for r in parseRunRange(run_num):
                if isinstance(r, basestring) or isinstance(r, int) or isinstance(r, long):
                    if r == 1 or r == '1':
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
                elif isinstance(r, run_tuple):
                    if r[0] == r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "DBS run range must be apart at least by 1.",
                          self.logger.exception)
                    elif r[0] <= 1 <= r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
        if lumi_list:
            if run_num ==-1 or not run_num :
                dbsExceptionHandler("dbsException-invalid-input", "When lumi_list is given, require a single run_num.", self.logger.exception)
            elif sumOverLumi == 1:
                 dbsExceptionHandler("dbsException-invalid-input", "lumi_list and sumOverLumi=1 cannot be set at the same time becaue nesting of WITH clause within WITH clause not supported yet by Oracle. ", self.logger.exception)
            else:
                try:
                    lumi_list = self.dbsUtils2.decodeLumiIntervals(lumi_list)
                except Exception as de:
                    dbsExceptionHandler("dbsException-invalid-input", "Invalid lumi_list input: "+ str(de), self.logger.exception)
        else:
            if not isinstance(run_num, list):
                if run_num ==1 or run_num == '1':
                    dbsExceptionHandler("dbsException-invalid-input", "files API does not supprt run_num=1 when no lumi.", self.logger.exception)
            else:
                if 1 in run_num or '1' in run_num :
                 dbsExceptionHandler("dbsException-invalid-input", "files API does not supprt run_num=1 when no lumi.", self.logger.exception)
        if int(sumOverLumi) == 1 and (isinstance(run_num, list) or isinstance(logical_file_name, list)):
            dbsExceptionHandler("dbsException-invalid-input", "When sumOverLumi=1, no lfn list or run_num list allowed  becaue nesting of WITH clause within WITH clause not supported yet by Oracle. ", self.logger.exception)
        detail = detail in (True, 1, "True", "1", 'true')
        output_module_label = output_module_label.replace("*", "%")
        try:
            result =  self.dbsFile.listFiles(dataset, block_name, logical_file_name, release_version, pset_hash, app_name,
                                        output_module_label, run_num, origin_site_name, lumi_list, detail,
                                        validFileOnly, sumOverLumi)
    	    for item in result:
		yield item
	except HTTPError as he:
	    raise he
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listFiles. %s \n Exception trace: \n %s" % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', ex.message,
                    self.logger.exception, sError)

Response: This is a helper method to list files in DBS.


Instruction:
Can you tell what is the following Python 3 function doing
def listFileSummaries(self, block_name='', dataset='', run_num=-1, validFileOnly=0, sumOverLumi=0):
        # run_num=1 caused full table scan and CERN DBS reported some of the queries ran more than 50 hours
        # We will disbale all the run_num=1 calls in DBS.
        # YG Jan. 16 2019
        #
        if (run_num != -1)  :
            for r in parseRunRange(run_num):
                if isinstance(r, basestring) or isinstance(r, int) or isinstance(r, long):
                    if r == 1 or r == '1':
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
                elif isinstance(r, run_tuple):
                    if r[0] == r[1]:
                        dbsExceptionHandler('dbsException-invalid-input', "DBS run range must be apart at least by 1.",
                          self.logger.exception)
                    elif r[0] <= 1 <= r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
        try:
            r = self.dbsFile.listFileSummary(block_name, dataset, run_num, validFileOnly=validFileOnly, sumOverLumi=sumOverLumi)
	    for item in r:
		yield item
	except HTTPError as he:
	    raise he
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
	except HTTPerror as he:
	    raise he
        except Exception as ex:
            sError = "DBSReaderModel/listFileSummaries. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', ex.message, self.logger.exception, sError)

Response: This function returns a list of dicts containing the number of files event counts and number of lumis in a given block or dataset.


Instruction:
Make a summary of the following Python 3 code
def listDatasetParents(self, dataset=''):
        try:
            return self.dbsDataset.listDatasetParents(dataset)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listDatasetParents. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to list Dataset Parents in DBS.


Instruction:
Explain what the following Python 3 code does
def listFileParents(self, logical_file_name='', block_id=0, block_name=''):
        try:
            r = self.dbsFile.listFileParents(logical_file_name, block_id, block_name)
	    for item in r:
		yield item
        except HTTPError as he:
	    raise he
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listFileParents. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', ex.message,  self.logger.exception, sError)

Response: API to list file parents of a file


Instruction:
Given the following Python 3 function, write the documentation
def listFileParentsByLumi(self):
        try :
            body = request.body.read()
            if body:
                data = cjson.decode(body)
                data = validateJSONInputNoCopy('file_parent_lumi', data, read=True)
            else:
                data = {}

            #Because CMSWEB has a 300 seconds responding time. We have to limit the array siz to make sure that
            #the API can be finished in 300 second.
            max_array_size = 1000
            if ('logical_file_name' in data.keys() and isinstance(data['logical_file_name'], list) and len(data['logical_file_name'])>max_array_size):
                dbsExceptionHandler("dbsException-invalid-input",
                                        "The Max list length supported in listFilePArentsByLumi is %s." %max_array_size, self.logger.exception)

            lfn = []
            if "block_name" not in data.keys():
                 dbsExceptionHandler('dbsException-invalid-input', "block_name is required for fileparentsbylumi")
            else:
                if "logical_file_name" in data.keys():
                    lfn = data["logical_file_name"]
            result = self.dbsFile.listFileParentsByLumi(block_name=data["block_name"], logical_file_name=lfn)
            for r in result:
                yield r
        except cjson.DecodeError as De:
            dbsExceptionHandler('dbsException-invalid-input2', "Invalid input", self.logger.exception, str(De))
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except HTTPError as he:
            raise he
        except Exception as ex:
            sError = "DBSReaderModel/listFileParentsByLumi. %s \n Exception trace: \n %s" \
            % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', ex.message, self.logger.exception, sError)

Response: This method returns a list of file parents for a given block with or w/o a list of LFN.


Instruction:
Explain what the following Python 3 code does
def listFileChildren(self, logical_file_name='', block_name='', block_id=0):
        if isinstance(logical_file_name, list):
            for f in logical_file_name:
                if '*' in f or '%' in f:
                    dbsExceptionHandler("dbsException-invalid-input2", dbsExceptionCode["dbsException-invalid-input2"], self.logger.exception, "No \
                                         wildcard allow in LFN list" )

        try:
            return self.dbsFile.listFileChildren(logical_file_name, block_name, block_id)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listFileChildren. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to list file children. One of the parameters in mandatory.


Instruction:
Explain what the following Python 3 code does
def listFileLumis(self, logical_file_name="", block_name="", run_num=-1, validFileOnly=0):
        # run_num=1 caused full table scan and CERN DBS reported some of the queries ran more than 50 hours
        # We will disbale all the run_num=1 calls in DBS. Run_num=1 will be OK when logical_file_name is given.
        # YG Jan. 16 2019
        if (run_num != -1  and logical_file_name ==''):
            for r in parseRunRange(run_num):
                if isinstance(r, basestring) or isinstance(r, int) or isinstance(r, long):
                    if r == 1 or r == '1':
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
                elif isinstance(r, run_tuple):
                    if r[0] == r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "DBS run range must be apart at least by 1.",self.logger.exception)
                    elif r[0] <= 1 <= r[1]:
                        dbsExceptionHandler("dbsException-invalid-input", "Run_num=1 is not a valid input.",
                                self.logger.exception)
        try:
            return self.dbsFile.listFileLumis(logical_file_name, block_name, run_num, validFileOnly )
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listFileLumis. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to list Lumi for files.


Instruction:
Can you tell what is the following Python 3 function doing
def listDataTypes(self, datatype="", dataset=""):
        try:
            return  self.dbsDataType.listDataType(dataType=datatype, dataset=dataset)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listDataTypes. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to list data types known to DBS.


Instruction:
Here you have a function in Python 3, explain what it does
def listDatasetAccessTypes(self, dataset_access_type=''):
        if dataset_access_type:
            dataset_access_type = dataset_access_type.replace("*", "%")
        try:
            return self.dbsDatasetAccessType.listDatasetAccessTypes(dataset_access_type)
        except dbsException as de:
            dbsExceptionHandler(de.eCode, de.message, self.logger.exception, de.serverError)
        except Exception as ex:
            sError = "DBSReaderModel/listDatasetAccessTypes. %s\n. Exception trace: \n %s" \
                    % (ex, traceback.format_exc())
            dbsExceptionHandler('dbsException-server-error', dbsExceptionCode['dbsException-server-error'], self.logger.exception, sError)

Response: API to list dataset access types.


Instruction:
How would you explain what the following Python 3 function does
def list():
    entries = lambder.list_events()
    for e in entries:
        click.echo(str(e))

Response: List all events in a resource group


Instruction:
Here you have a function in Python 3, explain what it does
def add(name, function_name, cron):
    lambder.add_event(name=name, function_name=function_name, cron=cron)

Response: Add an event to the current container.


Instruction:
Write a Python 3 function for
loading events from a json file

Response:
def load(file):
    """ Load events from a json file """
    with open(file, 'r') as f:
        contents = f.read()
    lambder.load_events(contents)


Instruction:
Make a summary of the following Python 3 code
def functions(context):
    # find lambder.json in CWD
    config_file = "./lambder.json"
    if os.path.isfile(config_file):
        context.obj = FunctionConfig(config_file)
    pass

Response: Manage AWS Lambda functions


Instruction:
Here you have a function in Python 3, explain what it does
def new(
    name,
    bucket,
    timeout,
    memory,
    description,
    subnet_ids,
    security_group_ids
):
    """ Create a new lambda project """
    config = {}
    if timeout:
        config['timeout'] = timeout
    if memory:
        config['memory'] = memory
    if description:
        config['description'] = description
    if subnet_ids:
        config['subnet_ids'] = subnet_ids
    if security_group_ids:
        config['security_group_ids'] = security_group_ids

    lambder.create_project(name, bucket, config)

Response: Create a new lambda project


Instruction:
Given the following Python 3 function, write the documentation
def deploy(
    config,
    name,
    bucket,
    timeout,
    memory,
    description,
    subnet_ids,
    security_group_ids
):
    """ Deploy/Update a function from a project directory """
    # options should override config if it is there
    myname = name or config.name
    mybucket = bucket or config.bucket
    mytimeout = timeout or config.timeout
    mymemory = memory or config.memory
    mydescription = description or config.description
    mysubnet_ids = subnet_ids or config.subnet_ids
    mysecurity_group_ids = security_group_ids or config.security_group_ids

    vpc_config = {}
    if mysubnet_ids and mysecurity_group_ids:
        vpc_config = {
            'SubnetIds': mysubnet_ids.split(','),
            'SecurityGroupIds': mysecurity_group_ids.split(',')
        }

    click.echo('Deploying {} to {}'.format(myname, mybucket))
    lambder.deploy_function(
        myname,
        mybucket,
        mytimeout,
        mymemory,
        mydescription,
        vpc_config
    )

Response: Deploy a function from a project directory


Instruction:
Can you implement a function in Python 3 that
deletes lambda function role and zipfile

Response:
def rm(config, name, bucket):
    """ Delete lambda function, role, and zipfile """
    # options should override config if it is there
    myname = name or config.name
    mybucket = bucket or config.bucket

    click.echo('Deleting {} from {}'.format(myname, mybucket))
    lambder.delete_function(myname, mybucket)


Instruction:
Given the following Python 3 function, write the documentation
def invoke(config, name, input):
    # options should override config if it is there
    myname = name or config.name

    click.echo('Invoking ' + myname)
    output = lambder.invoke_function(myname, input)
    click.echo(output)

Response: Invoke a function in AWS


Instruction:
Can you generate a brief explanation for the following Python 3 code
def putBlock(self, blockcontent, migration=False):
        #YG
        try:
            #1 insert configuration
            self.logger.debug("insert configuration")
            configList = self.insertOutputModuleConfig(
                            blockcontent['dataset_conf_list'], migration)
            #2 insert dataset
            self.logger.debug("insert dataset")
            datasetId = self.insertDataset(blockcontent, configList, migration)
            #3 insert block & files
            self.logger.debug("insert block & files.")
            self.insertBlockFile(blockcontent, datasetId, migration)
        except KeyError as ex:
            dbsExceptionHandler("dbsException-invalid-input2", "DBSBlockInsert/putBlock: \
                KeyError exception: %s. " %ex.args[0], self.logger.exception,
	        "DBSBlockInsert/putBlock: KeyError exception: %s. " %ex.args[0]	)
        except Exception as ex:
            raise

Response: Insert the data in sereral steps and commit when each step finishes or rollback when there is a problem.