Plugins/VcsPlugins/vcsSubversion/SvnPropListDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show the output of the svn proplist command process.
8 """
9
10 import types
11
12 from PyQt4.QtCore import *
13 from PyQt4.QtGui import *
14
15 from Ui_SvnPropListDialog import Ui_SvnPropListDialog
16
17 class SvnPropListDialog(QWidget, Ui_SvnPropListDialog):
18 """
19 Class implementing a dialog to show the output of the svn proplist command process.
20 """
21 def __init__(self, vcs, parent = None):
22 """
23 Constructor
24
25 @param vcs reference to the vcs object
26 @param parent parent widget (QWidget)
27 """
28 QWidget.__init__(self, parent)
29 self.setupUi(self)
30
31 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
32 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
33
34 self.process = QProcess()
35 self.vcs = vcs
36
37 self.propsList.headerItem().setText(self.propsList.columnCount(), "")
38 self.propsList.header().setSortIndicator(0, Qt.AscendingOrder)
39
40 self.connect(self.process, SIGNAL('finished(int, QProcess::ExitStatus)'),
41 self.__procFinished)
42 self.connect(self.process, SIGNAL('readyReadStandardOutput()'),
43 self.__readStdout)
44 self.connect(self.process, SIGNAL('readyReadStandardError()'),
45 self.__readStderr)
46
47 self.rx_path = QRegExp(r"Properties on '([^']+)':\s*")
48 self.rx_prop = QRegExp(r" (.*) : (.*)[\r\n]")
49 self.lastPath = None
50 self.lastProp = None
51 self.propBuffer = ""
52
53 def __resort(self):
54 """
55 Private method to resort the tree.
56 """
57 self.propsList.sortItems(self.propsList.sortColumn(),
58 self.propsList.header().sortIndicatorOrder())
59
60 def __resizeColumns(self):
61 """
62 Private method to resize the list columns.
63 """
64 self.propsList.header().resizeSections(QHeaderView.ResizeToContents)
65 self.propsList.header().setStretchLastSection(True)
66
67 def __generateItem(self, path, propName, propValue):
68 """
69 Private method to generate a properties item in the properties list.
70
71 @param path file/directory name the property applies to (string or QString)
72 @param propName name of the property (string or QString)
73 @param propValue value of the property (string or QString)
74 """
75 QTreeWidgetItem(self.propsList, QStringList() << path << propName << propValue)
76
77 def closeEvent(self, e):
78 """
79 Private slot implementing a close event handler.
80
81 @param e close event (QCloseEvent)
82 """
83 if self.process is not None and \
84 self.process.state() != QProcess.NotRunning:
85 self.process.terminate()
86 QTimer.singleShot(2000, self.process, SLOT('kill()'))
87 self.process.waitForFinished(3000)
88
89 e.accept()
90
91 def start(self, fn, recursive = False):
92 """
93 Public slot to start the svn status command.
94
95 @param fn filename(s) (string or list of string)
96 @param recursive flag indicating a recursive list is requested
97 """
98 self.errorGroup.hide()
99
100 self.process.kill()
101
102 args = []
103 args.append('proplist')
104 self.vcs.addArguments(args, self.vcs.options['global'])
105 args.append('--verbose')
106 if recursive:
107 args.append('--recursive')
108 if type(fn) is types.ListType:
109 dname, fnames = self.vcs.splitPathList(fn)
110 self.vcs.addArguments(args, fnames)
111 else:
112 dname, fname = self.vcs.splitPath(fn)
113 args.append(fname)
114
115 self.process.setWorkingDirectory(dname)
116
117 self.process.start('svn', args)
118 procStarted = self.process.waitForStarted()
119 if not procStarted:
120 QMessageBox.critical(None,
121 self.trUtf8('Process Generation Error'),
122 self.trUtf8(
123 'The process {0} could not be started. '
124 'Ensure, that it is in the search path.'
125 ).format('svn'))
126
127 def __finish(self):
128 """
129 Private slot called when the process finished or the user pressed the button.
130 """
131 if self.process is not None and \
132 self.process.state() != QProcess.NotRunning:
133 self.process.terminate()
134 QTimer.singleShot(2000, self.process, SLOT('kill()'))
135 self.process.waitForFinished(3000)
136
137 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
138 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
139 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
140
141 self.process = None
142 if self.lastProp:
143 self.__generateItem(self.lastPath, self.lastProp, self.propBuffer)
144
145 self.__resort()
146 self.__resizeColumns()
147
148 def on_buttonBox_clicked(self, button):
149 """
150 Private slot called by a button of the button box clicked.
151
152 @param button button that was clicked (QAbstractButton)
153 """
154 if button == self.buttonBox.button(QDialogButtonBox.Close):
155 self.close()
156 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
157 self.__finish()
158
159 def __procFinished(self, exitCode, exitStatus):
160 """
161 Private slot connected to the finished signal.
162
163 @param exitCode exit code of the process (integer)
164 @param exitStatus exit status of the process (QProcess.ExitStatus)
165 """
166 if self.lastPath is None:
167 self.__generateItem('', 'None', '')
168
169 self.__finish()
170
171 def __readStdout(self):
172 """
173 Private slot to handle the readyReadStandardOutput signal.
174
175 It reads the output of the process, formats it and inserts it into
176 the contents pane.
177 """
178 self.process.setReadChannel(QProcess.StandardOutput)
179
180 while self.process.canReadLine():
181 s = unicode(self.process.readLine())
182 if self.rx_path.exactMatch(s):
183 if self.lastProp:
184 self.__generateItem(self.lastPath, self.lastProp, self.propBuffer)
185 self.lastPath = self.rx_path.cap(1)
186 self.lastProp = None
187 self.propBuffer = ""
188 elif self.rx_prop.exactMatch(s):
189 if self.lastProp:
190 self.__generateItem(self.lastPath, self.lastProp, self.propBuffer)
191 self.lastProp = self.rx_prop.cap(1)
192 self.propBuffer = self.rx_prop.cap(2)
193 else:
194 self.propBuffer += ' '
195 self.propBuffer += s
196
197 def __readStderr(self):
198 """
199 Private slot to handle the readyReadStandardError signal.
200
201 It reads the error output of the process and inserts it into the
202 error pane.
203 """
204 if self.process is not None:
205 self.errorGroup.show()
206 s = unicode(self.process.readAllStandardError())
207 self.errors.insertPlainText(s)
208 self.errors.ensureCursorVisible()

eric ide

mercurial