PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/tortoisehg/hgtk/bugreport.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 95 lines | 77 code | 8 blank | 10 comment | 3 complexity | 961c72b4f86b84dff05e7009e7abd9a4 MD5 | raw file
 1# bugreport.py - Bug report dialog for TortoiseHg
 2#
 3# Copyright 2009 Steve Borho <steve@borho.org>
 4#
 5# This software may be used and distributed according to the terms of the
 6# GNU General Public License version 2, incorporated herein by reference.
 7
 8import os, sys
 9import gtk
10
11from mercurial import extensions
12from tortoisehg.util.i18n import _
13from tortoisehg.util import hglib, version
14from tortoisehg.hgtk import gdialog, gtklib
15
16class BugReport(gdialog.GWindow):
17    """GTK+ based dialog for displaying traceback info to the user in a
18    cut-paste friendly manner.  And include a number of useful bit of
19    information like version numbers, etc.
20    """
21
22    __error_text__ = None
23
24    def get_title(self):
25        return _('TortoiseHg Bug Report')
26
27    def get_icon(self):
28        return 'menudelete.ico'
29
30    def get_body(self):
31        textview = gtk.TextView()
32        textview.set_wrap_mode(gtk.WRAP_NONE)
33        textview.set_editable(False)
34        textview.modify_font(self.fonts['diff'])
35        scroller = gtk.ScrolledWindow()
36        scroller.set_shadow_type(gtk.SHADOW_IN)
37        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
38        scroller.add(textview)
39        scroller.set_border_width(5)
40        vbox = gtk.VBox()
41        vbox.pack_start(scroller, True, True, 2)
42        hbbox = gtk.HButtonBox()
43        hbbox.set_layout(gtk.BUTTONBOX_END)
44        vbox.pack_start(hbbox, False, False, 2)
45        save = gtk.Button(_('Save as..'))
46        save.connect('clicked', self.save_report_clicked)
47        hbbox.add(save)
48        close = gtk.Button(_('Close'))
49        close.connect('clicked', gtk.main_quit)
50        hbbox.add(close)
51        textview.get_buffer().set_text(self.get_error_text())
52        return vbox
53
54    def get_error_text(self):
55        if self.__error_text__ == None:
56            text = '{{{\n#!python\n' # Wrap in Bitbucket wiki preformat markers
57            text += _('** Please report this bug to'
58                      ' http://bitbucket.org/tortoisehg/stable/issues\n')
59            text += '** Mercurial version (%s).  TortoiseHg version (%s)\n' % (
60                    hglib.hgversion, version.version())
61            text += '** Command: %s\n' % (self.opts['cmd'])
62            text += '** CWD: %s\n' % os.getcwd()
63            extlist = [x[0] for x in extensions.extensions()]
64            text += '** Extensions loaded: %s\n' % ', '.join(extlist)
65            text += '** Python %s\n' % sys.version.replace('\n', '')
66            if os.name == 'nt':
67                text += '** sys.getwindowsversion(): %s\n' % str(sys.getwindowsversion())
68                arch = 'unknown (failed to import win32api)'
69                try:
70                    import win32api
71                    arch = 'unknown'
72                    archval = win32api.GetNativeSystemInfo()[0]
73                    if archval == 9:
74                        arch = 'x64'
75                    elif archval == 0:
76                        arch = 'x86'
77                except (ImportError, AttributeError):
78                    pass
79                text += '** Processor architecture: %s\n' % arch
80            text += self.opts['error']
81            text += '\n}}}'
82            self.__error_text__ = text
83        return self.__error_text__ 
84
85    def save_report_clicked(self, button):
86        result = gtklib.NativeSaveFileDialogWrapper(
87                        title=_('Save error report to')).run()
88
89        if result:
90            fd = file(result, 'w')
91            fd.write(self.get_error_text())
92            fd.close()
93
94def run(_ui, *pats, **opts):
95    return BugReport(_ui, None, None, None, opts)