def extractAttribute(self, key, line, error_attributes, warning_attributes): attrs = self.dico_attributes[key] if Tool._is_array(attrs): for attr in attrs: attr_value_found = self.matchAttribute(line, attr, error_attributes, warning_attributes) if attr_value_found: break else: attr_value_found = self.matchAttribute(line, attrs, error_attributes, warning_attributes) if attr_value_found: text = Tool.replaceNonASCII(attr_value_found,html=True) else: text = "" return text
def parseTable(self, start, end, list_tbl_tables=[]): try: doc_range = self.doc.Range(start,end) nb_tables = doc_range.Tables.Count tables_counter = 1 while tables_counter <= nb_tables: print "Process table:",tables_counter self.log("Process table:{:d}".format(tables_counter)) tbl = doc_range.Tables(tables_counter) nb_rows = len(tbl.Rows) + 1 #print "NB_ROWS",nb_rows nb_cols = len(tbl.Columns) + 1 tbl_tables = [] del(tbl_tables[:]) header = True for row in range(1, nb_rows): line = [] del(line[:]) for col in range(1, nb_cols): try: txt = Tool.replaceNonASCII(tbl.Cell(row, col).Range.Text) line.append(txt) except: #print "Warning, encounter joined cells." self.log("Warning, encounter joined cells.") pass # exception for joined cells if header: str_line = "|".join(line) self.log("Table found:{:s}".format(str_line)) header = False tbl_tables.append(line) #list_attributes["table"] = tbl_tables #print "inside tbl",tbl_tables # TODO: rendre applicable qunad plus d'un document est parsé if tables_counter in list_tbl_tables: # Already exists list_tbl_tables[tables_counter].extend(tbl_tables[:]) else: # New table list_tbl_tables[tables_counter] = tbl_tables[:] tables_counter += 1 else: pass #list_attributes["table"] = None except pythoncom.com_error as e: print "UN:",e #print "DEUX:",e.excepinfo[5] #print(win32api.FormatMessage(e.excepinfo[5])) #print "Treat:",start_delimiter,start,end #list_attributes["table"] = None return nb_tables
def getData(self,raw,key): import html2text id = raw[key,"id"] context = raw[key,"scope"] + " " + raw[key,"type"] + " " + raw[key,"review_id"] description = raw[key,"Description"] #print "DESC_1:",description description_wo_nonascii = Tool.replaceNonASCII(description) #print "DESC_2:",description_wo_nonascii description_plain_txt = html2text.html2text(description_wo_nonascii) #print "DESC_3:",description_plain_txt impact = raw[key,"context"] criticality = raw[key,"criticality"] assignee = raw[key,"lname"] expected = raw[key,"date_expected"][0:10] status = raw[key,"status"] response = raw[key,"comment"] response_plain_txt = html2text.html2text(Tool.replaceNonASCII(response)) tbl = [id,context,description_plain_txt,impact,criticality,assignee,expected,status,response_plain_txt] return tbl
def createCCB(self, list_projects, cr_domain, list_action_items, cr_with_parent, dico, list_cr_for_ccb, # User selection list from _getListCRForCCB status_list, # User selection availability flag _getListCRForCCB ccb_time=False, dico_former_cr_status_list={}, tableau_pr_unsorted=[], found_cr=False, ccb_time_obj="", **kwargs): """ This function creates the document based on the template - open template docx - get sections of the template - replace tag in document - create zip . copy unmodified section . copy modified section """ for key in kwargs: self.__dict__[key] = kwargs[key] if "system" not in self.__dict__: if "system" in dico: self.system = dico["system"] else: self.system = "Default" print "Missing system name" if self.ccb_cr_parent == "yes": cr_with_parent = True name,mail,tel,service,qams_user_id = self.get_user_infos(dico["login"]) if dico["author"] in ("","Nobody"): dico["author"] = Tool.replaceNonASCII(name) #self.old_cr_workflow = self.get_sys_item_old_workflow(dico["system"], # dico["item"]) #self.setDetectRelease(dico["detect"]) #self.setImplRelease(dico["implemented"]) #self.ccb_type = cr_domain cr_domain = self.getDomain() if self._is_array(cr_domain): list_cr_domain_str = ",".join(cr_domain) else: list_cr_domain_str = cr_domain self.setListCR(list_cr_for_ccb, status_list) # CR list created based on list self.tableau_pr #tableau_pr_unsorted,found_cr = self.getPR_CCB(cr_with_parent=cr_with_parent, # cr_type=dico["cr_type"]) # if time capsule is activated #print "dico_former_cr_status_list",dico_former_cr_status_list dico_time_capsule = {} #print "tableau_pr_unsorted",tableau_pr_unsorted if found_cr: for cr in tableau_pr_unsorted: #cr_id = cr[2] cr_id = cr[2].lstrip('0') #print "CR_ID__",cr_id current_cr_status = cr[3] if cr_id in dico_former_cr_status_list: # update status with former status in the past former_cr_status = dico_former_cr_status_list[cr_id] dico_time_capsule[cr_id] = {"current":current_cr_status, "former":former_cr_status} cr[3] = former_cr_status print "dico_time_capsule",dico_time_capsule print "CR",cr #print "dico_time_capsule",dico_time_capsule # Sort CR according to ID, status or severity column # by default CR are sorted by severity if found_cr: if self.ccb_cr_sort == "": tableau_pr_sorted = sorted(tableau_pr_unsorted,key=self._getSeverity) else: if self.ccb_cr_sort == "id": tableau_pr_sorted = sorted(tableau_pr_unsorted,key=lambda x: x[2]) elif self.ccb_cr_sort == "status": tableau_pr_sorted = sorted(tableau_pr_unsorted,key=lambda x: x[3]) elif self.ccb_cr_sort == "severity": tableau_pr_sorted = sorted(tableau_pr_unsorted,key=self._getSeverity) else: tableau_pr_sorted = tableau_pr_unsorted else: tableau_pr_sorted = tableau_pr_unsorted # Checklist list_candidate_cr=[] if found_cr: self.tableau_pr = tableau_pr_sorted # Dictionary containing checklist for each CR, not sorted. if self.isSwDomain(): cr_domain = "SCR" else: cr_domain = "CR" dico_cr_checklist = self.createChecklist(cr_domain, timeline=dico_time_capsule, list_candidate_cr=list_candidate_cr) else: dico_cr_checklist ={'domain':'SCR'} tableau_pr= [] list_cr_annex = [] if self.isSwDomain(): # Software domain tableau_pr.append(["Domain","CR Type","ID","Status","Synopsis","Severity"]) if found_cr: # Annex num_begin = ord("a") num_end = ord("z") num = num_begin prefix = "" print "list_candidate_cr",list_candidate_cr for cr_domain,cr_type,cr_id,cr_status,cr_synopsis,cr_severity in tableau_pr_sorted: # Patch # cr_id: 0001 etc. if cr_id in list_candidate_cr: line = "{:s}{:s}) Extract {:s} {:s}".format(prefix,chr(num),cr_domain,cr_id) print "LINE",line num += 1 if num > num_end: prefix += "a" num = num_begin list_cr_annex.append((line,'rb')) list_cr_annex.append(('','r')) tableau_pr.extend(tableau_pr_sorted) else: tableau_pr.append(["-","-","-","-","-","-"]) elif cr_with_parent: tableau_pr.append(["Domain","CR Type","ID","Status","Synopsis","Severity","Detected on","Implemented for","Parent CR","SW impact","HW impact","PLD impact"]) if not found_cr: tableau_pr.append(["-","-","-","-","-","-","-","-","-","-","-","-"]) else: tableau_pr.extend(tableau_pr_sorted) else: tableau_pr.append(["Domain","CR Type","ID","Status","Synopsis","Severity","Detected on","Implemented for","SW impact","HW impact","PLD impact"]) if not found_cr: tableau_pr.append(["-","-","-","-","-","-","-","-","-","-","-"]) else: tableau_pr.extend(tableau_pr_sorted) tableau_log = [["id","Log"],["--","--"]] # Action_items # Previous actions tbl_previous_actions = self.createTblPreviousActionsList(list_action_items,ccb_time) # Current actions tbl_current_actions = self.createTblActionsList(list_action_items,ccb_time) template_type = "CCB" item_description = self.getItemDescription(dico["item"]) ci_identification = self.get_ci_sys_item_identification(dico["system"], dico["item"]) if dico["component"] != "": title = "{:s} {:s} {:s} {:s}".format(self.system,dico["item"],dico["component"],template_type) subject = "{:s} {:s} {:s} {:s}".format(self.system,dico["item"],dico["component"],self.getTypeDocDescription(template_type)) elif dico["item"] != "": title = "{:s} {:s} {:s}".format(self.system,dico["item"],template_type) subject = "{:s} {:s} {:s}".format(self.system,dico["item"],self.getTypeDocDescription(template_type)) else: title = "{:s} {:s}".format(self.system,template_type) subject = "{:s} {:s}".format(self.system,self.getTypeDocDescription(template_type)) project_text = "The project is not defined" if dico["project"] != "": if len(list_projects) in (0,1) : project_text = "The project is {:s}".format(dico["project"]) else: text = "The projects are: " project_text = text + ", ".join(map(str, list_projects)) if dico["reference"] == "": if dico["component"] != "": tag_id = dico["component"] elif dico["item"] != "": tag_id = dico["item"] else: tag_id = dico["system"] reference = "CCB_Minutes_{:s}_001".format(tag_id) else: reference = dico["reference"] if self.isSwDomain(): # Software template_name = self._getTemplate("CCB") #if not cr_with_parent: colw_pr = [500, # Domain 500, # CR Type 500, # ID 500, # Synopsis 2500, 500] # 5000 = 100% if 0==1: colw_pr = [300, # Domain 300, # CR Type 300, # ID 500, # Status 2000, # Synopsis 400, # Severity 400, # Detected on 400, # Implemented for 400, # Parent CR 300] # 5000 = 100% else: # Hardware template_name = self._getTemplate("CCB_PLD","CCB_Minutes_HW_PLD_template.docx") if not cr_with_parent: colw_pr = [300, # Domain 300, # CR Type 300, # ID 500, # Status 2000, # Synopsis 400, # Severity 400, # Detected on 400, # Implemented for 300, # SW impact 300, # HW impact 300] # PLD impact 5000 = 100% else: colw_pr = [300, # Domain 300, # CR Type 300, # ID 500, # Status 2000, # Synopsis 400, # Severity 400, # Detected on 400, # Implemented for 400, # Parent CR 300, # SW impact 300, # HW impact 300] # PLD impact 5000 = 100% fmt_pr = { 'heading': True, 'colw': colw_pr, # 5000 = 100% 'cwunit': 'pct', 'tblw': 5000, 'twunit': 'pct', 'borders': {'all': {'color': 'auto','space': 0,'sz': 6,'val': 'single',}} } fmt_actions = { 'heading': True, 'colw': self.colw_actions, # 5000 = 100% 'cwunit': 'pct', 'tblw': 5000, 'twunit': 'pct', 'borders': {'all': {'color': 'auto','space': 0,'sz': 6,'val': 'single',}} } colw_log = [500,4500] # 5000 = 100% fmt_log = { 'heading': True, 'colw': colw_log, # 5000 = 100% 'cwunit': 'pct', 'tblw': 5000, 'twunit': 'pct', 'borders': {'all': {'color': 'auto','space': 0,'sz': 6,'val': 'single',}} } if dico["issue"] == "": issue = "1" else: issue = dico["issue"] if ccb_time_obj: #print "ccb_time_obj",ccb_time_obj #ccb_time = datetime.strftime("%d %b %Y",ccb_time_obj) #t = datetime(ccb_time_obj) ccb_time = ccb_time_obj else: ccb_time = time.strftime("%d %b %Y", time.localtime()) list_tags = { 'SUBJECT':{'type':'str','text':subject,'fmt':{}}, 'TITLE':{'type':'str','text':title,'fmt':{}}, 'CI_ID':{'type':'str','text':ci_identification,'fmt':{}}, 'REFERENCE':{'type':'str','text':reference,'fmt':{}}, 'ISSUE':{'type':'str','text':issue,'fmt':{}}, 'ITEM':{'type':'str','text':dico["item"],'fmt':{}}, 'ITEM_DESCRIPTION':{'type':'str','text':item_description,'fmt':{}}, 'DATE':{'type':'str','text':time.strftime("%d %b %Y", time.localtime()),'fmt':{}}, 'DATE_MEET':{'type':'str','text':ccb_time,'fmt':{}}, 'PROJECT':{'type':'str','text':project_text,'fmt':{}}, 'RELEASE':{'type':'str','text':dico["release"],'fmt':{}}, 'BASELINE':{'type':'str','text':dico["baseline"],'fmt':{}}, 'DOMAIN':{'type':'str','text':list_cr_domain_str,'fmt':{}}, 'WRITER':{'type':'str','text':dico["author"],'fmt':{}}, 'MAIL':{'type':'str','text':mail,'fmt':{}}, 'TEL':{'type':'str','text':tel,'fmt':{}}, 'SERVICE':{'type':'str','text':service,'fmt':{}}, 'COPIES':{'type':'str','text':"Nobody",'fmt':{}}, 'MISSING':{'type':'str','text':"Nobody",'fmt':{}}, 'TABLECHECKLIST':{'type':'mix','text':dico_cr_checklist,'fmt':self.fmt_chk}, 'TABLEPRS':{'type':'tab','text':tableau_pr,'fmt':fmt_pr}, 'PREVIOUS_ACTIONS':{'type':'tab','text':tbl_previous_actions,'fmt':fmt_actions}, 'CURRENT_ACTIONS':{'type':'tab','text':tbl_current_actions,'fmt':fmt_actions}, 'TABLELOGS':{'type':'tab','text':tableau_log,'fmt':fmt_log}, 'TABLEANNEX':{'type':'par','text':list_cr_annex,'fmt':{}} } #for pr in tableau_pr: # print "PR:",pr # print "LEN:",len(pr) #print "FMT:",fmt if dico["item"] != "": docx_filename = dico["system"] + "_" + dico["item"] + "_CR_" + template_type + "_Minutes_" + dico["reference"] + "_%f" % time.time() + ".docx" else: docx_filename = dico["system"] + "_CR_" + template_type + "_Minutes_" + dico["reference"] + "_%f" % time.time() + ".docx" self.ihm.docx_filename = docx_filename self.docx_filename,exception = self._createDico2Word(list_tags, template_name, docx_filename) return self.docx_filename,exception
def parse_body_attr(self, start_delimiter, # Requirement ID start, # Range.Start end, # Range.End list_attributes = {}): """ :param start_delimiter: :param start: :param end: :param list_attributes: :return: """ error_attributes = [] warning_attributes = [] #print "START_TAG",start_delimiter,start,end for style,key in self.dico_styles.iteritems(): if key in self.dico_types["SHLVCP"]: try: # New Style to be found # range must be reevaluated at each iteration range = self.doc.Range(start,end) index = 0 if key == "body": found = True else: found = self.find(range,style=style) while found and index < 50: index += 1 line = range.Text if key == "issue": # First attribute parsed_line = self.extractAttribute(key,line,error_attributes,warning_attributes) list_attributes["issue"] = parsed_line if Shlvcp.getVersion(list_attributes["issue"]) == self.doc_version: self.nb_reqs_modified += 1 first_attribute_start = range.Start list_attributes["body"] = self.doc.Range(start,first_attribute_start).Text list_procedures = self.getProcInBody(list_attributes["body"]) if list_procedures: list_attributes["proc"] = list_procedures objective = self.getObjectiveInBody(list_attributes["body"]) if objective: list_attributes["objective"] = re.sub(r"\r","",objective) break elif key == "verify": list_attributes["verify"] = self.getSplitAttribute(line,type="[A-Z]*_[\w-]*") if self.active_dbg: self.log("Requirement {:s}: Found attribute {:s}:{:s}".format(start_delimiter, style, list_attributes["verify"]), gui_display=True) break elif key == "additional": parsed_line = self.extractAttribute(key,line,error_attributes,warning_attributes) list_attributes["additional"] = parsed_line used_io = self.getUsedIOInBOdy(list_attributes["additional"]) if used_io: list_used_io = self.getSplitAttribute(line,type="[A-Z]*_[\w-]*") list_attributes["used_io"] = list_used_io if self.active_dbg: self.log("Requirement {:s}: Found attribute {:s}:{:s}".format(start_delimiter, style, list_attributes["used_io"]), gui_display=True) break elif key == "body": break else: # remove not related key for SHLVCP attrs = self.dico_attributes[key] if Tool._is_array(attrs): for attr in attrs: attr_value_found = self.matchAttribute(line, attr, error_attributes, warning_attributes) if attr_value_found: break else: attr_value_found = self.matchAttribute(line, attrs, error_attributes, warning_attributes) if range.End == end: # No more attribute with Style is to be found, leave break range = self.doc.Range(range.End,end) # Remove carriage return if attr_value_found: text = Tool.replaceNonASCII(attr_value_found,html=True) if self.active_dbg: self.log("Requirement {:s}: Found attribute {:s}:{:s}".format(start_delimiter, style, text), gui_display=True) if key not in list_attributes: list_attributes[key] = text else: list_attributes[key] += text found = self.find_execute() except pythoncom.com_error as exception: print exception print "KEY/Style",key,style
def load(self, full_filename, type = ("SHLVCP",)): pythoncom_loader = pkgutil.find_loader('pythoncom') found_pythoncom = pythoncom_loader is not None if found_pythoncom: start_area_req = 0 end_area_req = 0 try : print "FILE:",full_filename doc = self.word.Documents.Open(full_filename) doc.TrackFormatting = False doc.TrackMoves = False doc.TrackRevisions = False doc.ScreenUpdating = False # Active Show All self.word.ActiveWindow.ActivePane.View.ShowAll = True doc.TrackFormatting = False doc.TrackMoves = False doc.TrackRevisions = False doc.ScreenUpdating = False self.set_doc(doc) # TODO: Parse list of modifications # Looking for "Title 4" for SwRD tbl_req_tag = [] tbl_req_tag_wo_del = [] filename = Shlvcp.getFileName(full_filename) # get major version of the document doc_version = self.getDocVersion(filename) if doc_version: self.doc_version = doc_version self.log("Major version found: {:s}".format(self.doc_version),gui_display=True) start_area_req,end_area_req = self.getReqInfos(new_tab_req=self.tbl_req_vs_section, type=type, tbl_req_tag=tbl_req_tag, tbl_req_tag_wo_del=tbl_req_tag_wo_del, table_enabled=False, filename=filename) ReqPart = doc.Range(start_area_req,end_area_req) txt = Tool.replaceNonASCII(ReqPart.Text) self.tbl_file_llr[filename] = tbl_req_tag self.tbl_file_llr_wo_del[filename] = tbl_req_tag_wo_del self.tbl_file_nb_llr[filename] = self.nb_reqs_in_file self.tbl_file_nb_pages[filename] = self.get_nb_pages self.tbl_file_dir[filename] = "/".join(self.stack) except pythoncom.com_error as e: txt = "" print e print "Treat:",start_area_req,end_area_req try: doc.Close() del doc except pythoncom.com_error as e: print "Error in closing Word document:",e except UnboundLocalError as e: print e return True
def getReqInfos(self, new_tab_req=[], type=("SWRD",), tbl_req_tag=[], tbl_req_tag_wo_del=[], table_enabled=False, filename=""): #print "Call getReqInfos" # Looking for "Title 4" for SwRD tbl_req = [] tbl_section = [] tbl_output = [] start_area_req = self.parse_req(tbl_req,type="SHLVCP") # start is the beginning of requirements zone if table_enabled: self.nb_tables += self.parseTable(0,start_area_req,self.list_tbl_tables_begin) print "nb_tables",self.nb_tables # Find end f requirement end_area_req = self.parse_end_req(tbl_req, tbl_output) for req_id,start,end in tbl_output: print req_id,",",start,",",end #exit() index = 0 for start_delimiter,start,end in tbl_output: list_attributes = dict() #Caution, this a dictionary if table_enabled: tbl_tables = [] try: doc_range = self.doc.Range(start,end) nb_tables = doc_range.Tables.Count if nb_tables > 0: tbl = doc_range.Tables(1) nb_rows = len(tbl.Rows) + 1 nb_cols = len(tbl.Columns) + 1 for row in range(1, nb_rows): line = [] for col in range(1, nb_cols): try: line.append(Tool.replaceNonASCII(tbl.Cell(row, col).Range.Text)) except:pass # exception for joined cells tbl_tables.append(line) list_attributes["table"] = tbl_tables else: list_attributes["table"] = None except pythoncom.com_error as e: print "UN:",e print "Treat:",start_delimiter,start,end list_attributes["table"] = None self.parse_body_attr(start_delimiter, start, end, list_attributes) type,tag_req = self.extractReqType(start_delimiter) self.tbl_list_llr[start_delimiter] = list_attributes tbl_req_tag.append(start_delimiter) deleted = self.testStatusDeleted(start_delimiter,list_attributes) if not deleted: tbl_req_tag_wo_del.append(start_delimiter) # Forward if "verify" in list_attributes and "forward" in list_attributes: result = self.getDerived(type, list_attributes["verify"], list_attributes["forward"], filename, start_delimiter, key="forward") else: print "Missing verify or forward attribute" result = False if result: # Derived found self.nb_derived_req += 1 #if index > 50: # break index += 1 # Loop to link section with requirement for req_id,start_pos,end_pos in tbl_req: found_section = False prev_section_text = "" for section_text,section_start_pos,section_end_pos in tbl_section: if section_start_pos < start_pos: prev_section_text = section_text else: req_id_str = str(req_id) found_section = True if req_id_str not in new_tab_req: new_tab_req[req_id_str] = prev_section_text #new_tab_req.append([str(req_id),start_pos,end_pos,prev_section_text]) break #for req in new_tab_req: # print "tbl_req",req return (start_area_req,end_area_req)