Kiln » TortoiseHg » TortoiseHg
Clone URL:  
bugreport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# bugreport.py - Report Python tracebacks to the user # # Copyright 2010 Steve Borho <steve@borho.org> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. import os import sys from PyQt4 import QtCore, QtGui from PyQt4.QtCore import SIGNAL, SLOT from mercurial import extensions from tortoisehg.util import hglib, version from tortoisehg.util.i18n import _ class BugReport(QtGui.QDialog): def __init__(self, opts, parent=None): super(BugReport, self).__init__(parent) self.text = self.gettext(opts) layout = QtGui.QVBoxLayout() te = QtGui.QTextEdit() te.setPlainText(self.text) te.setReadOnly(True) te.setWordWrapMode(QtGui.QTextOption.NoWrap) layout.addWidget(te) # dialog buttons BB = QtGui.QDialogButtonBox bb = QtGui.QDialogButtonBox(BB.Ok|BB.Save) self.connect(bb, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(bb.button(BB.Save), SIGNAL("clicked()"), self.save) bb.button(BB.Ok).setDefault(True) layout.addWidget(bb) self.setLayout(layout) self.setWindowTitle(_('TortoiseHg Bug Report')) def gettext(self, opts): text = '{{{\n#!python\n' # Wrap in Bitbucket wiki preformat markers text += _('** Please report this bug to' ' http://bitbucket.org/tortoisehg/stable/issues\n') text += '** Mercurial version (%s). TortoiseHg version (%s)\n' % ( hglib.hgversion, version.version()) text += '** Command: %s\n' % (opts.get('cmd', 'N/A')) text += '** CWD: %s\n' % os.getcwd() extlist = [x[0] for x in extensions.extensions()] text += '** Extensions loaded: %s\n' % ', '.join(extlist) if os.name == 'nt': text += self.getarch() text += opts.get('error', 'N/A') text += '\n}}}' return text def getarch(self): text += '** Windows version: %s\n' % str(sys.getwindowsversion()) arch = 'unknown (failed to import win32api)' try: import win32api arch = 'unknown' archval = win32api.GetNativeSystemInfo()[0] if archval == 9: arch = 'x64' elif archval == 0: arch = 'x86' except (ImportError, AttributeError): pass text += '** Processor architecture: %s\n' % arch return text def save(self): try: fd = QtGui.QFileDialog(self) fname = fd.getSaveFileName(self, _('Save error report to'), os.path.join(os.getcwd(), 'bugreport.txt'), _('Text files (*.txt)')) if fname: open(fname, 'wb').write(self.text) except (EnvironmentError), e: print e def run(ui, *pats, **opts): return BugReport(opts) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) form = BugReport({'cmd':'cmd', 'error':'error'}) form.show() app.exec_()