def main(): wsOpts = WSOpts() parser = wsOpts.get_common_opts() (options, args) = parser.parse_args() wsOpts.setLogging(options.debug) if wsOpts.checkRequiredMissing(options, ('snapshot',)): parser.print_help() sys.exit(-1) configServiceClient = ConfigServiceClient(options) defectServiceClient = DefectServiceClient(options) snapshotIdDO = configServiceClient.get_snapshot(options.snapshot) if not snapshotIdDO: logging.error("No valid snapshot found") parser.print_help() sys.exit(-1) streamname = configServiceClient.get_stream_by_snapshot(options.snapshot) streamIdDOs = configServiceClient.get_stream(streamname) if not streamIdDOs: logging.error("No valid stream for this snapshot found") sys.exit(-1) if len(streamIdDOs) != 1: logging.error("Found more than one stream for this snapshot!!!") sys.exit(-1) streamIdDO = streamIdDOs[0] try: md = defectServiceClient.get_merged_defects_by_snapshot(snapshotIdDO,streamIdDO) except: logging.warning("No merged defects for snapshot found") sys.exit(-1) try: cids = [d.cid for d in md.mergedDefects] except: logging.error("Error getting cids for snapshot") sys.exit(-1) totalFetched = len(cids) if totalFetched < 1: print "No defects in snapshot", snapshotIdDO.id.snapshotId.id sys.exit(1) else: print "Fetched "+ str(totalFetched) + " cids in snapshot", options.snapshot
def main(): wsOpts = WSOpts() parser = wsOpts.get_common_opts() # use --test flag to avoid sending e-mail while debugging this script parser.add_option("--test", action="store_true", dest="testing", default="False", help="Testing flag: no mail just echo to stdout"); parser.add_option("--last", action="store_true", dest="last", help="Notify about last commit: project or stream MUST be specified"); (options, args) = parser.parse_args() wsOpts.setLogging(options.debug) if wsOpts.checkRequiredMissing(options, ('last','stream'),('last','project')): logging.error("Must specify --last with either --stream or --project") sys.exit(-1) configServiceClient = ConfigServiceClient(options) defectServiceClient = DefectServiceClient(options) streamIdDOs = configServiceClient.get_streams(options.project,options.stream) if not streamIdDOs: logging.error("No valid streams found") sys.exit(-1) cws = configServiceClient.get_components_with_subscribers(options.project,options.stream) if len(cws) == 0: logging.warning("No subscribers for specified streams/projects") sys.exit(-1) logging.debug([(c.componentId.name, c.subscribers) for c in cws]) comps = [c.componentId.name for c in cws] total = 0 mds = [] for streamIdDO in streamIdDOs: lastSnapshotIdDO = configServiceClient.get_last_snapshot(streamIdDO) nextToLastSnapshotIdDO = configServiceClient.get_next_to_last_snapshot(streamIdDO) logging.debug(lastSnapshotIdDO) logging.debug(nextToLastSnapshotIdDO) mergedDefectsDOs = defectServiceClient.get_merged_defects_by_snapshot(lastSnapshotIdDO, streamIdDO, nextToLastSnapshotIdDO) logging.debug(mergedDefectsDOs.totalNumberOfRecords) if mergedDefectsDOs.totalNumberOfRecords > 0: total += mergedDefectsDOs.totalNumberOfRecords mds.extend(mergedDefectsDOs.mergedDefects) if total == 0: print "No records new in latest snapshots" sys.exit(0) md = [m for m in mds if m.componentName in comps] if len(md) == 0: print "No records found for notification" sys.exit(0) # iterate over merged defects email_cid = {} for mergedDefectDO in md: # if the component the defect belongs to has subscribers cName = mergedDefectDO.componentName componentDO = configServiceClient.get_component(cName) try: subscribers = componentDO.subscribers except: # shouldn't be here as we filtered out the defects without subscribers logging.debug("no subscribers for "+cName) continue else: # store user and defects in a dictionary for user in subscribers: if user not in email_cid: email_cid[user] = {} if cName not in email_cid[user]: email_cid[user][cName] = [] if mergedDefectDO.cid not in email_cid[user]: email_cid[user][cName].append(mergedDefectDO.cid) if len(email_cid) == 0: print "Nothing to notify about" sys.exit(0) logging.debug("Will notify %d users about %d defects" % (len(email_cid), len(mds))) if options.project: subject = "New defects found in your subscribed components of Coverity project "+options.project elif options.stream: subject = "New defects in your subscribed components of Coverity stream "+options.stream else: logging.warning("Not yet implemented") project_id = None url = None if options.project: project_id = configServiceClient.get_project_id(options.project) elif options.stream: pDO = configServiceClient.get_projects(None, options.stream) if len(pDO) == 0: logging.error("Stream %s doesn't have a primary parent owner" % (options.stream)) project_id = configServiceClient.get_project_id(pDO[0].id.name) else: logging.warning("Not yet implemented") leadin = "<html>\n<br>The following new defects were found in your subscribed components in the latest snapshot:<br>\n" if project_id: projId=str(project_id) url = "http://"+options.host+":"+options.port+"/sourcebrowser.htm?projectId="+projId+"#mergedDefectId=" for u in email_cid.keys(): body = leadin for c in email_cid[u].keys(): body = body + "Component " + c + ":<br>\n" for cid in email_cid[u][c]: U = url+str(cid) body = body + " CID " + str(cid) + ": <a href " + U + ">" + U + "</a><br>\n" body = body + "</html>" if options.testing == True: logging.info("just testing") print u print subject print body else: logging.debug(u) logging.debug(subject) logging.debug(body) configServiceClient.send_notifications(u, subject, body)
def main(): wsOpts = WSOpts() parser = wsOpts.get_common_opts() (options, args) = parser.parse_args() wsOpts.setLogging(options.debug) if wsOpts.checkRequiredMissing(options, ('snapshot', )): parser.print_help() sys.exit(-1) configServiceClient = ConfigServiceClient(options) defectServiceClient = DefectServiceClient(options) snapshotIdDO = configServiceClient.get_snapshot(options.snapshot) snapshotInfoDO = configServiceClient.get_snapshot_info(options.snapshot) if not snapshotInfoDO: logging.warning("No valid snapshot found") parser.print_help() sys.exit(-1) streamname = configServiceClient.get_stream_by_snapshot(options.snapshot) streamIdDOs = configServiceClient.get_stream(streamname) if not streamIdDOs: logging.error("No valid stream for this snapshot found") parser.print_help() sys.exit(-1) if len(streamIdDOs) != 1: logging.error("Found more than one stream for this snapshot!!!") parser.print_help() sys.exit(-1) streamIdDO = streamIdDOs[0] lastSnapshotIdDO = configServiceClient.get_snapshot_by_date( datetime.datetime.now(), streamIdDO) logging.debug("Last snapshot in stream %s is " % (streamIdDO.name)) logging.debug(lastSnapshotIdDO.id.snapshotId.id) mergedDefectDOs = defectServiceClient.get_merged_defects_by_snapshot( snapshotIdDO, streamIdDO) logging.debug("Last snapshot in this stream is " + str(lastSnapshotIdDO.id.snapshotId.id)) totalFetched = mergedDefectDOs.totalNumberOfRecords if totalFetched < 1: logging.warning("No defects") sys.exit(1) else: logging.debug( str(totalFetched) + " merged defects fetched for snapshot " + str(snapshotIdDO.id) + " " + streamIdDO.name) pass currentMDDOs = defectServiceClient.get_merged_defects(streamIdDOs, 'all') if currentMDDOs.totalNumberOfRecords < 1: logging.warning("Something is wrong: no current defects") sys.exit(1) cids = [md.cid for md in currentMDDOs.mergedDefects] logging.debug(len(cids)) badcids = ([ md.cid for md in mergedDefectDOs.mergedDefects if md.cid not in cids ]) goodcids = ([ md.cid for md in mergedDefectDOs.mergedDefects if md.cid in cids ]) allcids = [md.cid for md in mergedDefectDOs.mergedDefects] logging.debug(len(allcids)) logging.debug(len(set(cids).difference(set(allcids)))) logging.debug(len(set(allcids).difference(set(cids)))) mds = ([md for md in mergedDefectDOs.mergedDefects if md.cid in cids]) logging.info(str(len(cids)) + " cids were committed - " + str(len(mds))) # things to add # get previous snapshot CIDs, compare # get next snapshot CIDs, compare # give breakdown of CIDs in that snapshot by current status print "Number of CIDs committed to stream %s in snapshot %s: %d " % ( streamname, options.snapshot, len(cids)) print " of which:" Fixed = [md.cid for md in mds if md.status == 'Fixed'] Dismissed = [md.cid for md in mds if md.status == 'Dismissed'] Triaged = [md.cid for md in mds if md.status == 'Triaged'] New = [md.cid for md in mds if md.status == 'New'] print len(Fixed), " were fixed" print len(Dismissed), " are dismissed" print len(Triaged), " were triaged but still outstanding" print len(New), " are still New and untriaged"
def main(): wsOpts = WSOpts() parser = wsOpts.get_common_opts() (options, args) = parser.parse_args() wsOpts.setLogging(options.debug) if wsOpts.checkRequiredMissing(options, ('snapshot',)): parser.print_help() sys.exit(-1) configServiceClient = ConfigServiceClient(options) defectServiceClient = DefectServiceClient(options); snapshotIdDO = configServiceClient.get_snapshot(options.snapshot) snapshotInfoDO = configServiceClient.get_snapshot_info(options.snapshot) if not snapshotInfoDO: logging.warning("No valid snapshot found") parser.print_help() sys.exit(-1) streamname = configServiceClient.get_stream_by_snapshot(options.snapshot) streamIdDOs = configServiceClient.get_stream(streamname) if not streamIdDOs: logging.error("No valid stream for this snapshot found") parser.print_help() sys.exit(-1) if len(streamIdDOs) != 1: logging.error("Found more than one stream for this snapshot!!!") parser.print_help() sys.exit(-1) streamIdDO = streamIdDOs[0] lastSnapshotIdDO = configServiceClient.get_snapshot_by_date(datetime.datetime.now(), streamIdDO) logging.debug("Last snapshot in stream %s is " % (streamIdDO.name)) logging.debug(lastSnapshotIdDO.id.snapshotId.id) mergedDefectDOs = defectServiceClient.get_merged_defects_by_snapshot(snapshotIdDO, streamIdDO) logging.debug("Last snapshot in this stream is " + str(lastSnapshotIdDO.id.snapshotId.id)) totalFetched = mergedDefectDOs.totalNumberOfRecords if totalFetched < 1: logging.warning("No defects") sys.exit(1) else: logging.debug(str(totalFetched) + " merged defects fetched for snapshot " + str(snapshotIdDO.id) + " " + streamIdDO.name) pass currentMDDOs = defectServiceClient.get_merged_defects(streamIdDOs, 'all') if currentMDDOs.totalNumberOfRecords < 1: logging.warning("Something is wrong: no current defects") sys.exit(1) cids = [md.cid for md in currentMDDOs.mergedDefects] logging.debug(len(cids)) badcids = ([md.cid for md in mergedDefectDOs.mergedDefects if md.cid not in cids]) goodcids = ([md.cid for md in mergedDefectDOs.mergedDefects if md.cid in cids]) allcids = [md.cid for md in mergedDefectDOs.mergedDefects] logging.debug(len(allcids)) logging.debug(len(set(cids).difference(set(allcids)))) logging.debug(len(set(allcids).difference(set(cids)))) mds = ([md for md in mergedDefectDOs.mergedDefects if md.cid in cids]) logging.info(str(len(cids)) + " cids were committed - " + str(len(mds))) # things to add # get previous snapshot CIDs, compare # get next snapshot CIDs, compare # give breakdown of CIDs in that snapshot by current status print "Number of CIDs committed to stream %s in snapshot %s: %d " % (streamname,options.snapshot,len(cids)) print " of which:" Fixed = [md.cid for md in mds if md.status=='Fixed'] Dismissed = [md.cid for md in mds if md.status=='Dismissed'] Triaged = [md.cid for md in mds if md.status=='Triaged'] New = [md.cid for md in mds if md.status=='New'] print len(Fixed), " were fixed" print len(Dismissed), " are dismissed" print len(Triaged), " were triaged but still outstanding" print len(New), " are still New and untriaged"
def main(): wsOpts = WSOpts() parser = wsOpts.get_common_opts() # use --test flag to avoid sending e-mail while debugging this script parser.add_option("--test", action="store_true", dest="testing", default="False", help="Testing flag: no mail just echo to stdout") parser.add_option( "--last", action="store_true", dest="last", help="Notify about last commit: project or stream MUST be specified") (options, args) = parser.parse_args() wsOpts.setLogging(options.debug) if wsOpts.checkRequiredMissing(options, ('last', 'stream'), ('last', 'project')): logging.error("Must specify --last with either --stream or --project") sys.exit(-1) configServiceClient = ConfigServiceClient(options) defectServiceClient = DefectServiceClient(options) streamIdDOs = configServiceClient.get_streams(options.project, options.stream) if not streamIdDOs: logging.error("No valid streams found") sys.exit(-1) cws = configServiceClient.get_components_with_subscribers( options.project, options.stream) if len(cws) == 0: logging.warning("No subscribers for specified streams/projects") sys.exit(-1) logging.debug([(c.componentId.name, c.subscribers) for c in cws]) comps = [c.componentId.name for c in cws] total = 0 mds = [] for streamIdDO in streamIdDOs: lastSnapshotIdDO = configServiceClient.get_last_snapshot(streamIdDO) nextToLastSnapshotIdDO = configServiceClient.get_next_to_last_snapshot( streamIdDO) logging.debug(lastSnapshotIdDO) logging.debug(nextToLastSnapshotIdDO) mergedDefectsDOs = defectServiceClient.get_merged_defects_by_snapshot( lastSnapshotIdDO, streamIdDO, nextToLastSnapshotIdDO) logging.debug(mergedDefectsDOs.totalNumberOfRecords) if mergedDefectsDOs.totalNumberOfRecords > 0: total += mergedDefectsDOs.totalNumberOfRecords mds.extend(mergedDefectsDOs.mergedDefects) if total == 0: print "No records new in latest snapshots" sys.exit(0) md = [m for m in mds if m.componentName in comps] if len(md) == 0: print "No records found for notification" sys.exit(0) # iterate over merged defects email_cid = {} for mergedDefectDO in md: # if the component the defect belongs to has subscribers cName = mergedDefectDO.componentName componentDO = configServiceClient.get_component(cName) try: subscribers = componentDO.subscribers except: # shouldn't be here as we filtered out the defects without subscribers logging.debug("no subscribers for " + cName) continue else: # store user and defects in a dictionary for user in subscribers: if user not in email_cid: email_cid[user] = {} if cName not in email_cid[user]: email_cid[user][cName] = [] if mergedDefectDO.cid not in email_cid[user]: email_cid[user][cName].append(mergedDefectDO.cid) if len(email_cid) == 0: print "Nothing to notify about" sys.exit(0) logging.debug("Will notify %d users about %d defects" % (len(email_cid), len(mds))) if options.project: subject = "New defects found in your subscribed components of Coverity project " + options.project elif options.stream: subject = "New defects in your subscribed components of Coverity stream " + options.stream else: logging.warning("Not yet implemented") project_id = None url = None if options.project: project_id = configServiceClient.get_project_id(options.project) elif options.stream: pDO = configServiceClient.get_projects(None, options.stream) if len(pDO) == 0: logging.error("Stream %s doesn't have a primary parent owner" % (options.stream)) project_id = configServiceClient.get_project_id(pDO[0].id.name) else: logging.warning("Not yet implemented") leadin = "<html>\n<br>The following new defects were found in your subscribed components in the latest snapshot:<br>\n" if project_id: projId = str(project_id) url = "http://" + options.host + ":" + options.port + "/sourcebrowser.htm?projectId=" + projId + "#mergedDefectId=" for u in email_cid.keys(): body = leadin for c in email_cid[u].keys(): body = body + "Component " + c + ":<br>\n" for cid in email_cid[u][c]: U = url + str(cid) body = body + " CID " + str( cid) + ": <a href=" + U + ">" + U + "</a><br>\n" body = body + "</html>" if options.testing == True: logging.info("just testing") print u print subject print body else: logging.debug(u) logging.debug(subject) logging.debug(body) configServiceClient.send_notifications(u, subject, body)