[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

status-report-scripts pyGetReviewByFlags,1.4,1.5



Author: toshio

Update of /cvs/fedora/status-report-scripts
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv17800

Modified Files:
	pyGetReviewByFlags 
Log Message:
* Add a patch from Jason Tibbits that includes the last change time for bugs
  in the output.
* Use a temporary directory to hold the new updates so we don't destroy the
  working files while we're creating new ones.
* Pull the command line parser into its own function.
* Have flag loop work by reading data from a hash instead of having an if-then
  to process the information.
* Move printing of the footer to its own function.
* Change all tabs to 8 spaces.




Index: pyGetReviewByFlags
===================================================================
RCS file: /cvs/fedora/status-report-scripts/pyGetReviewByFlags,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- pyGetReviewByFlags	20 Apr 2007 15:30:27 -0000	1.4
+++ pyGetReviewByFlags	24 May 2007 18:17:53 -0000	1.5
@@ -6,23 +6,38 @@
 from optparse import OptionParser
 import xmlrpclib
 import datetime
+import tempfile
+import glob
 
 url = 'http://bugzilla.redhat.com/bugzilla/xmlrpc.cgi'
 
-usage = "usage: %prog [options] -d <dest_dir>"
-parser = OptionParser(usage)
-parser.add_option("-d", "--destination", dest="dirname",
-		  help="destination directory")
-parser.add_option("-f", "--frequency", dest="frequency",
-		  help="update frequency", default="60")
-(options, args) = parser.parse_args()
-tst = str(options.dirname)
-if str(options.dirname) == 'None':
-    parser.error("Please specify destination directory")
-if not os.path.isdir(options.dirname):
-    parser.error("Please specify an existing destination directory")
+flagData = {
+    # 'FLAG' : (baseFlagFilename, openMsg, closeMsg),
+    '+': ('ACCEPT.html', "Accepted, but still open, tickets",
+        "Accepted tickets"),
+    '-': ('REJECT.html', "Rejected, but still open, tickets",
+        "Rejected tickets"),
+    '?': ('REVIEW.html', "Tickets being reviewed",
+        "Tickets being reviewed, but closed (should not happen)")
+    }
+
+def parse_commandline():
+    usage = "usage: %prog [options] -d <dest_dir>"
+    parser = OptionParser(usage)
+    parser.add_option("-d", "--destination", dest="dirname",
+              help="destination directory")
+    parser.add_option("-f", "--frequency", dest="frequency",
+              help="update frequency", default="60")
+    (options, args) = parser.parse_args()
+    tst = str(options.dirname)
+    if str(options.dirname) == 'None':
+        parser.error("Please specify destination directory")
+    if not os.path.isdir(options.dirname):
+        parser.error("Please specify an existing destination directory")
 
-def printHeader(f):
+    return options
+
+def printHeader(f, frequency):
     print >> f, """
 <html>
   <head>
@@ -46,7 +61,14 @@
       It is updated every %s minutes</h1>
     <div id="content_here">
     <h1 style="background-color: #99f">Last Update: %s </h1>
-""" % (options.frequency, (datetime.datetime.today()))
+""" % (frequency, (datetime.datetime.today()))
+
+def printFooter(f):
+    print >> f, """
+        </div></div>
+      </body>
+    </html>
+    """
 
 def runQuery(server, flag, f, openMsg, closeMsg):
     querydata = {}
@@ -55,22 +77,27 @@
     querydata['component'] = ['Package Review']
     querydata['field0-0-0'] = 'flagtypes.name'
     if flag == " ":
-	querydata['bug_status'] = ["NEW", "ASSIGNED", "REOPENED", "NEEDINFO", "INVESTIGATE", "MODIFIED"]
-	querydata['type0-0-0'] = 'notregexp';
-	querydata['value0-0-0'] = 'fedora-review[-+?]'
+        querydata['bug_status'] = ["NEW", "ASSIGNED", "REOPENED", "NEEDINFO", "INVESTIGATE", "MODIFIED"]
+        querydata['type0-0-0'] = 'notregexp';
+        querydata['value0-0-0'] = 'fedora-review[-+?]'
     else:
-	querydata['bug_status'] = ["NEW", "VERIFIED", "ASSIGNED", "REOPENED", "CLOSED", "NEEDINFO_ENG", "NEEDINFO", "INVESTIGATE", "MODIFIED", "ON_DEV", "UNCONFIRMED", "QA_READY", "ON_QA", "FAILS_QA", "NEEDINFO_REPORTER", "RELEASE_PENDING", "POST"]
-	querydata['type0-0-0'] = 'equals'
-	querydata['value0-0-0'] = "fedora-review" + flag
+        querydata['bug_status'] = ["NEW", "VERIFIED", "ASSIGNED", "REOPENED", "CLOSED", "NEEDINFO_ENG", "NEEDINFO", "INVESTIGATE", "MODIFIED", "ON_DEV", "UNCONFIRMED", "QA_READY", "ON_QA", "FAILS_QA", "NEEDINFO_REPORTER", "RELEASE_PENDING", "POST"]
+        querydata['type0-0-0'] = 'equals'
+        querydata['value0-0-0'] = "fedora-review" + flag
     call = server.bugzilla.runQuery(querydata)
     bugs = call['bugs']
     closedCnt = 0
     notClosedCnt = 0
+    
+    for bug in bugs:
+        nosec = bug['changeddate'].rfind(':')
+        bug['changeddate'] = bug['changeddate'][0:nosec]
+    
     for e in bugs:
-	if e['bug_status'] == "CLOSED":
-	    closedCnt += 1
-	else:
-	    notClosedCnt += 1
+        if e['bug_status'] == "CLOSED":
+            closedCnt += 1
+        else:
+            notClosedCnt += 1
     print >> f, """
 <h1 style="background-color: #99f">%s<br/>
 There are %d tickets in this category</h1>
@@ -80,6 +107,7 @@
 <col class="bz_alias_column">
 <col class="bz_assigned_to_column">
 <col class="bz_bug_status_column">
+<col class="bz_bug_changeddate_column">
 <col class="bz_resolution_column">
 <col class="bz_short_short_desc_column">
 </colgroup>
@@ -89,21 +117,22 @@
 <td>Alias</td>
 <td>Assignee</td>
 <td>Status</td>
+<td>Last Change</td>
 <td>Resolution</td>
 <td>Summary</td>
 </thead>
 """ % (openMsg, notClosedCnt)
     cnt = 0
     for e in bugs:
-	if e['bug_status'] == "CLOSED":
-	    continue
-	cnt += 1
-	if (cnt % 2) == 1:
-	    print >> f, '<tr class="bz_even bz_'
-	else:
-	    print >> f, '<tr class="bz_odd bz_'
-	print >> f, e['bug_status'], ' onMouseOver="bug_over(this, 0);">', "\n"
-	print >> f, """
+        if e['bug_status'] == "CLOSED":
+            continue
+        cnt += 1
+        if (cnt % 2) == 1:
+            print >> f, '<tr class="bz_even bz_'
+        else:
+            print >> f, '<tr class="bz_odd bz_'
+        print >> f, e['bug_status'], ' onMouseOver="bug_over(this, 0);">', "\n"
+        print >> f, """
 <td>
 <a href="show_bug.cgi?id=%s">%s</a>
 </td><td><nobr>
@@ -116,11 +145,13 @@
 <span title="%s">%s</span>
 </nobr></td><td><nobr>
 <span title="%s">%s</span>
+</nobr></td><td><nobr>
+<span title="%s">%s</span>
 </nobr></td></tr>
-""" % (e['bug_id'], e['bug_id'], e['alias'], e['alias'], e['assigned_to'], e['assigned_to'], e['bug_status'], e['bug_status'], e['resolution'], e['resolution'], e['short_desc'], e['short_desc'])
+""" % (e['bug_id'], e['bug_id'], e['alias'], e['alias'], e['assigned_to'], e['assigned_to'], e['bug_status'], e['bug_status'], e['changeddate'], e['changeddate'], e['resolution'], e['resolution'], e['short_desc'], e['short_desc'])
     print >> f, "</table>\n"
     if flag == " ":
-	return
+        return
     print >> f, """
 <h1 style="background-color: #99f">%s<br/>
 There are %d tickets in this category</h1>
@@ -130,6 +161,7 @@
 <col class="bz_alias_column">
 <col class="bz_assigned_to_column">
 <col class="bz_bug_status_column">
+<col class="bz_changeddate_column">
 <col class="bz_resolution_column">
 <col class="bz_short_short_desc_column">
 </colgroup>
@@ -139,21 +171,22 @@
 <td>Alias</td>
 <td>Assignee</td>
 <td>Status</td>
+<td>Last Change</td>
 <td>Resolution</td>
 <td>Summary</td>
 </thead>
 """ % (closeMsg, closedCnt)
     cnt = 0
     for e in bugs:
-	if e['bug_status'] != "CLOSED":
-	    continue
-	cnt += 1
-	if (cnt % 2) == 1:
-	    print >> f, '<tr class="bz_even bz_'
-	else:
-	    print >> f, '<tr class="bz_odd bz_'
-	print >> f, e['bug_status'], ' onMouseOver="bug_over(this, 0);">', "\n"
-	print >> f, """
+        if e['bug_status'] != "CLOSED":
+            continue
+        cnt += 1
+        if (cnt % 2) == 1:
+            print >> f, '<tr class="bz_even bz_'
+        else:
+            print >> f, '<tr class="bz_odd bz_'
+        print >> f, e['bug_status'], ' onMouseOver="bug_over(this, 0);">', "\n"
+        print >> f, """
 <td>
 <a href="show_bug.cgi?id=%s">%s</a>
 </td><td><nobr>
@@ -166,50 +199,47 @@
 <span title="%s">%s</span>
 </nobr></td><td><nobr>
 <span title="%s">%s</span>
+</nobr></td><td><nobr>
+<span title="%s">%s</span>
 </nobr></td></tr>
-""" % (e['bug_id'], e['bug_id'], e['alias'], e['alias'], e['assigned_to'], e['assigned_to'], e['bug_status'], e['bug_status'], e['resolution'], e['resolution'], e['short_desc'], e['short_desc'])
+""" % (e['bug_id'], e['bug_id'], e['alias'], e['alias'], e['assigned_to'], e['assigned_to'], e['bug_status'], e['bug_status'], e['changeddate'], e['changeddate'], e['resolution'], e['resolution'], e['short_desc'], e['short_desc'])
     print >> f, "</table>\n"
 
-server = xmlrpclib.Server(url)
 
-fname = os.path.join(options.dirname, "NEW.html")
-try:
-    f = open(fname, "w")
-except IOError, (err, strerr):
-    print 'ERROR: %s: %s' % (strerr, fname)
-    sys.exit(1)
-printHeader(f)
-runQuery(server, ' ', f, "Open ticket(s) with an empty flag", "")
-print >> f, """
-    </div></div>
-  </body>
-</html>
-"""
-f.close()
-
-for flag in ['+', '-', '?']:
-    if flag == '+':
-	openMsg = "Accepted, but still open, tickets"
-	closeMsg = "Accepted tickets"
-	fname = os.path.join(options.dirname, "ACCEPT.html")
-    elif flag == '-':
-	openMsg = "Rejected, but still open, tickets"
-	closeMsg = "Rejected tickets"
-	fname = os.path.join(options.dirname, "REJECT.html")
-    else:
-	openMsg = "Tickets being reviewed"
-	closeMsg = "Tickets being reviewed, but closed (should not happen)"
-	fname = os.path.join(options.dirname, "REVIEW.html")
+if __name__ == '__main__':
+    server = xmlrpclib.Server(url)
+    options = parse_commandline()
+    tmpdir = tempfile.mkdtemp(dir=options.dirname)
+    fname = os.path.join(tmpdir, "NEW.html")
     try:
-	f = open(fname, "w")
+        f = open(fname, "w")
     except IOError, (err, strerr):
-	print 'ERROR: %s: %s' % (strerr, fname)
-	sys.exit(1)
-    printHeader(f)
-    runQuery(server, flag, f, openMsg, closeMsg)
+        print 'ERROR: %s: %s' % (strerr, fname)
+        sys.exit(1)
+    printHeader(f, options.frequency)
+    runQuery(server, ' ', f, "Open ticket(s) with an empty flag", "")
     print >> f, """
-    </div></div>
-  </body>
-</html>
-"""
-sys.exit(0)
+        </div></div>
+      </body>
+    </html>
+    """
+    f.close()
+
+    for flag in flagData.keys():
+        try:
+            f = open(os.path.join(tmpdir, flagData[flag][0]), "w")
+        except IOError, (err, strerr):
+            print 'ERROR: %s: %s' % (strerr, flagData[flag][0])
+            sys.exit(1)
+        printHeader(f, options.frequency)
+        runQuery(server, flag, f, flagData[flag][1], flagData[flag][2])
+        printFooter(f)
+        f.close()
+
+    # Move the created files to their final destination
+    for filename in glob.glob(os.path.join(tmpdir, '*')):
+        newFilename = os.path.basename(filename)
+        os.rename(filename, os.path.join(options.dirname, newFilename))
+    os.rmdir(tmpdir)
+
+    sys.exit(0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]