Package moap :: Package command :: Module bug
[hide private]
[frames] | no frames]

Source Code for Module moap.command.bug

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  import sys 
  5   
  6  from moap.util import util, mail 
  7  from moap.bug import bug 
  8  from moap.doap import doap 
  9   
10 -class Show(util.LogCommand):
11 usage = "[bug id]" 12 summary = "show a bug" 13
14 - def do(self, args):
15 if not args: 16 sys.stderr.write('Please give a bug id to show.\n') 17 return 3 18 19 bugId = args[0] 20 self.debug('Looking up bug %r' % bugId) 21 tracker = self.parentCommand.tracker 22 try: 23 b = tracker.getBug(bugId) 24 except bug.NotFoundError, e: 25 sys.stderr.write('Bug %s not found in bug tracker.\n' % e.id) 26 return 3 27 28 print "%s: %s" % (b.id, b.summary)
29
30 -class Query(util.LogCommand):
31 summary = "query for bugs" 32 description = """Query the bug database for bugs. 33 34 You can specify an output format string with --format. 35 Allowed variables are: 36 id, summary 37 38 Example for trac (using moap's .doap file): 39 $ moap doap bug query -f "%(id)s" owner=thomas 40 41 Example for bugzilla: 42 $ moap bug -U http://bugzilla.gnome.org/ query "product=GStreamer&component=gst-plugins-base&target_milestone=0.10.2" 43 """ 44
45 - def addOptions(self):
46 self.parser.add_option('-q', '--query', 47 action="store", dest="query", 48 help="query string") 49 self.parser.add_option('-f', '--format', 50 action="store", dest="format", 51 help="format string", default="%(id)s: %(summary)s")
52
53 - def handleOptions(self, options):
54 self.options = options
55
56 - def do(self, args):
57 if not args: 58 sys.stderr.write('Please give a bug search query.\n') 59 return 3 60 61 query = args[0] 62 63 self.debug('Looking up bugs') 64 tracker = self.parentCommand.tracker 65 self.debug('Looking up bug using query %r' % query) 66 bugs = tracker.query(query) 67 if not bugs: 68 sys.stderr.write('Zaroo bugs found.\n') 69 return 3 70 71 72 # scrub the bug dict 73 for b in bugs: 74 d = {} 75 for key in ['id', 'summary']: 76 if hasattr(b, key): 77 d[key] = getattr(b, key) 78 print self.options.format % d
79
80 -class Bug(util.LogCommand):
81 usage = "[bug-options] %command" 82 summary = "interact with bug tracker" 83 description = """ 84 This command will interact with the bug tracker at the URL passed with 85 -U/--URL, or looked up from a .doap file in the current directory. 86 87 Currently supported bug trackers: 88 trac, bugzilla 89 """ 90 subCommandClasses = [Show, Query] 91
92 - def addOptions(self):
93 self.parser.add_option('-U', '--URL', 94 action="store", dest="URL", 95 help="URL of bug tracker")
96
97 - def handleOptions(self, options):
98 # prefer the URL passed 99 # if not passed, try a doap file 100 self.URL = options.URL 101 if not self.URL: 102 from moap.doap import doap 103 from moap.command import doap as cdoap 104 d = None 105 if isinstance(self.parentCommand, cdoap.Doap): 106 self.debug('Doap is my parent, looking up its doap file') 107 d = self.parentCommand.doap 108 else: 109 self.debug('Looking for a .doap file in the current dir') 110 try: 111 d = doap.findDoapFile(None) 112 except doap.DoapException, e: 113 sys.stderr.write(e.args[0]) 114 115 if not d: 116 return 3 117 118 project = d.getProject() 119 self.URL = project.bug_database 120 else: 121 self.debug('Using specified bug tracker URL %s' % self.URL) 122 123 self.debug('Looking up bug tracker at %s' % self.URL) 124 tracker = bug.detect(self.URL) 125 if not tracker: 126 sys.stderr.write('No known bug tracker found at %s\n' % self.URL) 127 return 3 128 129 self.debug('Found bug tracker %r' % tracker) 130 self.tracker = tracker
131