Package flumotion :: Package common :: Module bugreporter
[hide private]

Source Code for Module flumotion.common.bugreporter

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  """system information collector and bug reporter""" 
 19   
 20  import urllib 
 21  import webbrowser 
 22   
 23  from flumotion.common.common import pathToModuleName 
 24  from flumotion.common.debug import getVersions 
 25  from flumotion.configure import configure 
 26   
 27  _BUG_COMPONENT = 'flumotion' 
 28  _BUG_KEYWORDS = 'generated' 
 29  _BUG_TEMPLATE = """ 
 30  Please describe what you were doing when the crash happened. 
 31   
 32  ADD YOUR TEXT HERE 
 33   
 34  Collected information from your system: 
 35   
 36   * Flumotion version: '''%(version)s''' 
 37   * Flumotion SVN revision: [source:flumotion/%(branch)s#%(rev)s r%(rev)s] 
 38  %(extra)s 
 39  Python Traceback: 
 40  {{{ 
 41  %(traceback)s 
 42  }}} 
 43  """ 
 44  _TRAC_URL = 'https://code.flumotion.com/trac' 
 45   
 46   
47 -class BugReporter(object):
48 """I am a class that collects information about the system 49 and reports the information to the Flumotion bug report system. 50 """ 51
52 - def __init__(self):
53 self._baseURL = _TRAC_URL 54 self._component = _BUG_COMPONENT 55 self._keywords = [_BUG_KEYWORDS] 56 self._versions = getVersions()
57
58 - def _collectFilenames(self, filenames):
59 retval = {} 60 for filename in filenames: 61 moduleName = pathToModuleName(filename) 62 if not moduleName in self._versions: 63 continue 64 retval[filename] = self._versions[moduleName] 65 return retval
66
67 - def _processFilenames(self, filenames):
68 filenames = self._collectFilenames(filenames) 69 70 extra = ' * Filename revisions:\n' 71 for filename in sorted(filenames.keys()): 72 rev = filenames[filename] 73 link = '[source:flumotion/%s/%s#%s r%s]' % ( 74 configure.branchName, filename, rev, rev) 75 extra += " - %s: %s\n" % (filename, link) 76 return extra
77
78 - def _processTemplate(self, filenames, traceback):
79 description = _BUG_TEMPLATE % ( 80 dict(extra=self._processFilenames(filenames), 81 branch=configure.branchName, 82 rev=max(self._versions.values()), 83 traceback=traceback, 84 version=configure.version)) 85 return description
86 87 # Public API 88
89 - def submit(self, filenames, description, summary):
90 """Submits a bug report to trac by opening 91 a web browser 92 @param filenames: filenames visible in traceback 93 @type filenames: list of strings 94 @param description: description of the traceback 95 @type description: string 96 @param summary: summary of the bug report 97 @type summary: string 98 """ 99 description = self._processTemplate(filenames, description) 100 params = dict(summary=summary, 101 description=description) 102 if self._keywords: 103 params['keywords'] = ','.join(self._keywords) 104 if self._component: 105 params['component'] = self._component 106 107 data = urllib.urlencode(params) 108 reportURL = "%s/newticket?%s" % (self._baseURL, data, ) 109 webbrowser.open_new(reportURL)
110