Example #1
0
    def getPR(self,
              dico_pr,
              detect_in="",
              implemented_for="",
              cr_type="",
              cr_with_parent=False,
              list_cr=[],
              no_header=False,
              list_cr_type=[],
              list_cr_status=[],
              list_cr_doamin=[]):
        """
            Run a Change Request query
            Remove prefix to make generic status name
            The result is put in the table self.tableau_pr with the following columns:
            --------------------------------------------------------------------
            | ID | Synopsis | Type | Status | Detected on | Implemented in/for |
            --------------------------------------------------------------------
            or if parent CR is requested (cr_with_parent = TRUE)
            --------------------------------------------------------------------------------
            | ID | Synopsis | Type | Status | Detected on | Implemented in/for | Parent CR |
            --------------------------------------------------------------------------------
            %CR_type => SW_ENM, SW_BITE, SW_WHCC, SW_PLAN etc...
            Used by CreateCID function

        :param dico_pr: OUTPUT Ex: {"all":[['ID', 'Synopsis', 'Type', 'Status', 'Detected on', 'Implemented in/for', 'Parent CR'],
                                            ['1001', 'Inhibition of TRU over ripple protection', 'Evolution', 'Closed', 'N/A', 'SW_ENM/06', '910'], etc.
        :param detect_in: INPUT
        :param implemented_for: INPUT
        :param cr_type: INPUT
        :param cr_with_parent: INPUT
        """

        # Header
        empty_line = ["--","--","--","--","--","--","--"]
        header = ["ID","Synopsis","Type","Status","Detected on","Implemented in/for","Classif."]
        if cr_with_parent:
            header.append("Parent CR")
            empty_line.append("--")

        tableau_pr          = [] #[header]
        tableau_closed_pr   = [] #[header]
        tableau_opened_pr   = [] #[header]
        if self.ihm is not None:
            # Callback pourri
            old_cr_workflow = False
            condition,detect_attribut = self.new_createConditionStatus(detect_release=detect_in,
                                                                        impl_release=implemented_for,
                                                                        list_cr_type=list_cr_type,
                                                                        list_cr_status=list_cr_status,
                                                                        list_cr_doamin=list_cr_doamin)
        else:
            # Should not be here
            # Patch for input CRs treatment in get_ig_query for IS checking ...
            old_cr_workflow = False
            condition = '"(cvtype=\'problem\') '
            detection_word = "CR_detected_on"
            filter_cr = "CR_implemented_for"
            detect_attribut = "%{:s};%{:s}".format(detection_word,filter_cr)
            if  Tool.isAttributeValid(implemented_for):
                # implemented
                condition += self._createImpl(filter_cr, implemented_for,with_and=True)
            condition += '" '
        cr_domain = ""
        if list_cr != []:
            # overwrite condition previously computed
            query_list_cr = Tool._createImpl("problem_number",list_cr,with_and=False)
            condition = "-t problem \"{:s}\" ".format(query_list_cr)
            cr_domain = "<cell>%CR_domain</cell><cell>%CR_correction_description</cell>"
        if not no_header:
            tableau_pr.append(header)
            tableau_closed_pr.append(header)
            tableau_opened_pr.append(header)

        implementation_baseline_f = "%CR_implementation_baseline"
        # new with tags
        detect_attribut_tag = re.sub(r";","</cell><cell>",detect_attribut)
        classification = CCB.getClassif(old_cr_workflow)
        attributes = '-f "<cell>%problem_number</cell>' \
                     '<cell>%problem_synopsis</cell>' \
                     '<cell>%CR_request_type</cell>' \
                     '<cell>%crstatus</cell>' \
                     '<cell>{:s}</cell>' \
                     '{:s}' \
                     '<cell>%CR_customer_classification</cell>"'.format(detect_attribut_tag,cr_domain)
        # query sorted by CR status
        query = "query -sby crstatus {:s} {:s} ".format(condition,attributes)
        stdout,stderr = self.ccm_query(query,"Get CRs")
        if self.ihm is not None:
            self.ihm.log(query + " completed.")
        else:
            print "getPR query:",query
        # Set scrollbar at the bottom
        list_change_requests = []
        if stdout != "":
            output = stdout.splitlines()
            for line in output:
                line = re.sub(r"<void>",r"",line)
                cr_decod = self._parseCRCell(line)
                print "cr_decod",cr_decod
                cr_id = cr_decod[0]
                cr_synopsis = cr_decod[1]
                type = cr_decod[2]
                cr_domain = self.getCRPrefix(cr_decod[3])
                cr_decod[0] = cr_domain + " " + cr_decod[0]
                cr_decod[3] = self.discardCRPrefix(cr_decod[3])
                status = cr_decod[3]
                detected_on = cr_decod[4]
                implemented_for = cr_decod[5]
                #  Used to fill UI CR list box
                list_change_requests.append("{:s}) {:s}".format(cr_id.zfill(4),cr_synopsis))
                # For CLI
                #print line
                #tableau_pr.append([cr_id,cr_synopsis,type,status,detected_on,implemented_for])
                if cr_with_parent:
                    tbl_parent_cr_id = self._getParentCR(cr_id)
                    #print "tbl_parent_cr_id",tbl_parent_cr_id
                    if tbl_parent_cr_id:
                        #print "tbl_parent_cr_id",tbl_parent_cr_id
                        if Tool._is_array(tbl_parent_cr_id):
                            found_parent_cr_id_str = ", ".join(tbl_parent_cr_id)
                        else:
                            found_parent_cr_id_str = tbl_parent_cr_id
                        cr_decod.extend([found_parent_cr_id_str])
                    else:
                        cr_decod.extend([""])
                else:
                    pass
                    #cr_decod.extend([""])
                tableau_pr.append(cr_decod)
                if status in ("Closed","Fixed","Rejected","Cancelled"):
                    tableau_closed_pr.append(cr_decod)
                else:
                    tableau_opened_pr.append(cr_decod)

        if len(tableau_pr) == 1:
             tableau_pr.append(empty_line)
        if len(tableau_closed_pr) == 1:
             tableau_closed_pr.append(empty_line)
        if len(tableau_opened_pr) == 1:
             tableau_opened_pr.append(empty_line)
        dico_pr["all"]=tableau_pr
        dico_pr["open"]=tableau_opened_pr
        dico_pr["closed"]=tableau_closed_pr