50,7 → 50,7 |
"""Prints out a usage summary and exits.""" |
print "\n", 78*"#" |
print """\n |
Usage: mantisctl.py [Options], version = mantisctl.py 0.3 |
Usage: mantisctl.py [Options], version = mantisctl.py 0.4 |
|
ACTION: |
-T, --test Test the script |
91,8 → 91,8 |
"""Parses options and arguments passed to the script |
and returns a tuple of a dictionary (opts) and a list (args).""" |
from optparse import OptionParser |
usage = "%prog [Options], version = %prog 0.3" |
op = OptionParser(usage=usage, version='%prog 0.3') |
usage = "%prog [Options], version = %prog 0.4" |
op = OptionParser(usage=usage, version='%prog 0.4') |
op.add_option("-T", "--test", action="store_true", dest="test", default=False, help="Test the script") |
op.add_option("-L", "--list", action="store_true", dest="list", default=False, help="List the Mantis options") |
op.add_option("-r", "--report", action="store_true", dest="report", default=False, help="Report a new bug") |
126,7 → 126,6 |
"""Checks if the URL for the Mantis BTS instance front page could be |
opened and if the title of main page corresponds to the configuration |
option 'title'.""" |
# Get the base url from options or configuration section |
url = self._getbaseurl() |
try: |
self.br.open(url) |
134,7 → 133,6 |
except: |
print "Cannot open a Mantis BTS instance main page." |
sys.exit(1) |
# basetitle is defined in the configuration section |
if re.search(basetitle, mainpagetitle): |
return True |
else: |
190,7 → 188,6 |
def login(self): |
"""Performs logging into a Mantis BTS instance as an authenticated |
reporter.""" |
# Check if we have the credentials to login into a Mantis BTS instance. |
self._checkcredentials() |
self.loginlink = self.br.links(text_regex=re.compile("Login")).next() |
self.br.follow_link(self.loginlink) |
293,6 → 290,9 |
else: |
self._printwarning("category", self.categories) |
# severity |
if not self.opts.severity: |
self._printwarning("severity", self.severities.keys()) |
sys.exit(1) |
if self.opts.severity and len(self.opts.severity) > 0: |
if self.opts.severity in self.severities.keys(): |
self.severity = str(self.severities[self.opts.severity]) |
328,24 → 328,20 |
|
def comparebugdata(self, soup, data): |
bugs = soup.findAll("table", id="buglist")[0].findAll("tr")[3:-1] |
for bug in bugs: |
bugdata = bug.findAll("td") |
# print bugdata |
# bugno = data[0].contents[0].attrs[2][1].strip().encode('utf-8') |
bugno = bugdata[3].contents[0].contents[0].strip().encode('utf-8')[-4:] |
# print "bug number: %s" % bugno |
try: |
severity = bugdata[8].contents[0].contents[0].strip().encode('utf-8') |
except: |
severity = None |
# print "severity: %s" % severity |
pnumber = bugdata[4].contents[0].strip().encode('utf-8') |
# print "product number: %s" % pnumber |
reporter = bugdata[9].contents[0].strip().encode('utf-8') |
# print "reporter: %s" % reporter |
# print data, [bugno, reporter, severity, pnumber] |
if [reporter, severity, pnumber] == data: |
return bugno |
bugdata = bugs[0].findAll("td") |
bugno = bugdata[3].contents[0].contents[0].strip().encode('utf-8')[-4:] |
print "bug number: %s" % bugno |
try: |
severity = bugdata[8].contents[0].strip().encode('utf-8') |
except: |
severity = None |
print "severity: %s" % severity |
pnumber = bugdata[4].contents[0].strip().encode('utf-8') |
print "product number: %s" % pnumber |
reporter = bugdata[9].contents[0].strip().encode('utf-8') |
print "reporter: %s" % reporter |
if [reporter, severity, pnumber] == data: |
return bugno |
return None |
|
def reportbug(self): |
352,7 → 348,6 |
"""Handles submission of a bug report.""" |
self.setreportdata() |
self.checkreportopts() |
# depends on self.checkreportopts as it sets all self.var(s) |
self.filloutreportform() |
if not self.opts.noconfirm: |
self.askconfirm() |
369,19 → 364,6 |
# except: |
# pass |
self.br.close() |
#[<td><input type="checkbox" name="bug_arr[]" value="7342" /></td>, |
# <td><a href="bug_update_page.php?bug_id=7342"><img border="0" width="16" height="16" src="http://bugs.scribus.net/images/update.png" alt="Update Issue" title="Update Issue" /></a></td>, |
# <td>normal</td>, |
# <td><a href="view.php?id=7342">0007342</a></td>, |
# <td>1.3.3.12</td>, |
# <td></td>, |
# <td class="center"> </td>, |
# <td class="center">Canvas</td>, |
# <td class="center"><span class="bold">major</span></td>, |
# <td class="center">malex</td>, |
# <td class="center"><span class="issue-status" title="open">assigned</span> (malex)</td>, |
# <td class="center"><span class="bold">08-08-30</span></td>, |
# <td class="left">Summary</td>] |
data = [self.username, self.opts.severity, self.pversion] |
bugno = self.comparebugdata(reportsoup, data) |
if bugno != None: |
426,11 → 408,8 |
"""Main controller of the script. It will be called if the script is |
run from a command line or can be run by an external script. No other |
interface is available.""" |
# Check if we can access the main page of a Mantis BTS instance. |
self.checkbts() |
# Login into a Mantis BTS instance. |
self.login() |
# Select and run an action. |
self.runchoice() |
|
if __name__=='__main__': |