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