23 class GitSubmodulesStatusDialog(QDialog, Ui_GitSubmodulesStatusDialog): |
27 class GitSubmodulesStatusDialog(QDialog, Ui_GitSubmodulesStatusDialog): |
24 """ |
28 """ |
25 Class implementing a dialog to show the status of the submodules of the |
29 Class implementing a dialog to show the status of the submodules of the |
26 project. |
30 project. |
27 """ |
31 """ |
|
32 |
28 def __init__(self, vcs, parent=None): |
33 def __init__(self, vcs, parent=None): |
29 """ |
34 """ |
30 Constructor |
35 Constructor |
31 |
36 |
32 @param vcs reference to the vcs object |
37 @param vcs reference to the vcs object |
33 @type Git |
38 @type Git |
34 @param parent reference to the parent widget |
39 @param parent reference to the parent widget |
35 @type QWidget |
40 @type QWidget |
36 """ |
41 """ |
37 super().__init__(parent) |
42 super().__init__(parent) |
38 self.setupUi(self) |
43 self.setupUi(self) |
39 |
44 |
40 self.__statusCodes = { |
45 self.__statusCodes = { |
41 " ": self.tr("up-to-date"), |
46 " ": self.tr("up-to-date"), |
42 "-": self.tr("not initialized"), |
47 "-": self.tr("not initialized"), |
43 "+": self.tr("different to index"), |
48 "+": self.tr("different to index"), |
44 "U": self.tr("merge conflicts") |
49 "U": self.tr("merge conflicts"), |
45 } |
50 } |
46 |
51 |
47 self.__vcs = vcs |
52 self.__vcs = vcs |
48 self.__repodir = None |
53 self.__repodir = None |
49 |
54 |
50 self.refreshButton = self.buttonBox.addButton( |
55 self.refreshButton = self.buttonBox.addButton( |
51 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) |
56 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole |
52 self.refreshButton.setToolTip( |
57 ) |
53 self.tr("Press to refresh the status display")) |
58 self.refreshButton.setToolTip(self.tr("Press to refresh the status display")) |
54 |
59 |
55 def start(self, projectDir): |
60 def start(self, projectDir): |
56 """ |
61 """ |
57 Public method to populate the status list. |
62 Public method to populate the status list. |
58 |
63 |
59 @param projectDir name of the project directory |
64 @param projectDir name of the project directory |
60 @type str |
65 @type str |
61 """ |
66 """ |
62 # find the root of the repo |
67 # find the root of the repo |
63 self.__repodir = projectDir |
68 self.__repodir = projectDir |
64 while not os.path.isdir(os.path.join(self.__repodir, |
69 while not os.path.isdir(os.path.join(self.__repodir, self.__vcs.adminDir)): |
65 self.__vcs.adminDir)): |
|
66 self.__repodir = os.path.dirname(self.__repodir) |
70 self.__repodir = os.path.dirname(self.__repodir) |
67 if os.path.splitdrive(self.__repodir)[1] == os.sep: |
71 if os.path.splitdrive(self.__repodir)[1] == os.sep: |
68 return |
72 return |
69 |
73 |
70 self.errorGroup.hide() |
74 self.errorGroup.hide() |
71 self.errors.clear() |
75 self.errors.clear() |
72 self.statusList.clear() |
76 self.statusList.clear() |
73 self.buttonBox.setEnabled(False) |
77 self.buttonBox.setEnabled(False) |
74 |
78 |
75 args = self.__vcs.initCommand("submodule") |
79 args = self.__vcs.initCommand("submodule") |
76 args.append("status") |
80 args.append("status") |
77 if self.recursiveCheckBox.isChecked(): |
81 if self.recursiveCheckBox.isChecked(): |
78 args.append("--recursive") |
82 args.append("--recursive") |
79 if self.indexCheckBox.isChecked(): |
83 if self.indexCheckBox.isChecked(): |
80 args.append("--cached") |
84 args.append("--cached") |
81 |
85 |
82 process = QProcess() |
86 process = QProcess() |
83 process.setWorkingDirectory(self.__repodir) |
87 process.setWorkingDirectory(self.__repodir) |
84 process.start('git', args) |
88 process.start("git", args) |
85 procStarted = process.waitForStarted(5000) |
89 procStarted = process.waitForStarted(5000) |
86 if procStarted: |
90 if procStarted: |
87 finished = process.waitForFinished(30000) |
91 finished = process.waitForFinished(30000) |
88 if finished and process.exitCode() == 0: |
92 if finished and process.exitCode() == 0: |
89 ioEncoding = Preferences.getSystem("IOEncoding") |
93 ioEncoding = Preferences.getSystem("IOEncoding") |
90 output = str(process.readAllStandardOutput(), |
94 output = str(process.readAllStandardOutput(), ioEncoding, "replace") |
91 ioEncoding, 'replace') |
95 error = str(process.readAllStandardError(), ioEncoding, "replace") |
92 error = str(process.readAllStandardError(), |
|
93 ioEncoding, 'replace') |
|
94 if error: |
96 if error: |
95 self.errors.setText(error) |
97 self.errors.setText(error) |
96 self.errorGroup.show() |
98 self.errorGroup.show() |
97 self.__processOutput(output) |
99 self.__processOutput(output) |
98 else: |
100 else: |
99 if not finished: |
101 if not finished: |
100 self.errors.setText(self.tr( |
102 self.errors.setText( |
101 "The process {0} did not finish within 30 seconds.") |
103 self.tr( |
102 .format("git")) |
104 "The process {0} did not finish within 30 seconds." |
|
105 ).format("git") |
|
106 ) |
103 else: |
107 else: |
104 self.errors.setText(self.tr( |
108 self.errors.setText( |
105 "The process {0} finished with an error.\n" |
109 self.tr( |
106 "Error: {1}") |
110 "The process {0} finished with an error.\n" "Error: {1}" |
107 .format("git", process.errorString())) |
111 ).format("git", process.errorString()) |
|
112 ) |
108 self.errorGroup.show() |
113 self.errorGroup.show() |
109 else: |
114 else: |
110 self.errors.setText(self.tr( |
115 self.errors.setText( |
111 "The process {0} could not be started. " |
116 self.tr( |
112 "Ensure, that it is in the search path.").format("git")) |
117 "The process {0} could not be started. " |
|
118 "Ensure, that it is in the search path." |
|
119 ).format("git") |
|
120 ) |
113 self.errorGroup.show() |
121 self.errorGroup.show() |
114 |
122 |
115 self.buttonBox.setEnabled(True) |
123 self.buttonBox.setEnabled(True) |
116 self.buttonBox.setFocus() |
124 self.buttonBox.setFocus() |
117 |
125 |
118 def __processOutput(self, output): |
126 def __processOutput(self, output): |
119 """ |
127 """ |
120 Private method to process the output and populate the list. |
128 Private method to process the output and populate the list. |
121 |
129 |
122 @param output output of the submodule status command |
130 @param output output of the submodule status command |
123 @type str |
131 @type str |
124 """ |
132 """ |
125 for line in output.splitlines(): |
133 for line in output.splitlines(): |
126 try: |
134 try: |
129 status = self.tr("unknown") |
137 status = self.tr("unknown") |
130 lineParts = line[1:].split(None, 2) |
138 lineParts = line[1:].split(None, 2) |
131 if len(lineParts) == 3 and lineParts[2][0] == "(": |
139 if len(lineParts) == 3 and lineParts[2][0] == "(": |
132 # get rid of leading and trailing brackets |
140 # get rid of leading and trailing brackets |
133 lineParts[2] = lineParts[2][1:-1] |
141 lineParts[2] = lineParts[2][1:-1] |
134 QTreeWidgetItem(self.statusList, [ |
142 QTreeWidgetItem( |
135 lineParts[1], # submodule name |
143 self.statusList, |
136 status, # submodule status |
144 [ |
137 lineParts[0], # commit ID |
145 lineParts[1], # submodule name |
138 lineParts[2], # additional info |
146 status, # submodule status |
139 ]) |
147 lineParts[0], # commit ID |
140 |
148 lineParts[2], # additional info |
141 self.statusList.header().resizeSections( |
149 ], |
142 QHeaderView.ResizeMode.ResizeToContents) |
150 ) |
143 |
151 |
|
152 self.statusList.header().resizeSections(QHeaderView.ResizeMode.ResizeToContents) |
|
153 |
144 self.statusList.setSortingEnabled(True) |
154 self.statusList.setSortingEnabled(True) |
145 self.statusList.sortItems(0, Qt.SortOrder.AscendingOrder) |
155 self.statusList.sortItems(0, Qt.SortOrder.AscendingOrder) |
146 self.statusList.setSortingEnabled(False) |
156 self.statusList.setSortingEnabled(False) |
147 |
157 |
148 @pyqtSlot(QAbstractButton) |
158 @pyqtSlot(QAbstractButton) |
149 def on_buttonBox_clicked(self, button): |
159 def on_buttonBox_clicked(self, button): |
150 """ |
160 """ |
151 Private slot called by a button of the button box clicked. |
161 Private slot called by a button of the button box clicked. |
152 |
162 |
153 @param button button that was clicked (QAbstractButton) |
163 @param button button that was clicked (QAbstractButton) |
154 """ |
164 """ |
155 if button == self.buttonBox.button( |
165 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
156 QDialogButtonBox.StandardButton.Close |
|
157 ): |
|
158 self.close() |
166 self.close() |
159 elif button == self.refreshButton: |
167 elif button == self.refreshButton: |
160 self.on_refreshButton_clicked() |
168 self.on_refreshButton_clicked() |
161 |
169 |
162 @pyqtSlot() |
170 @pyqtSlot() |
163 def on_refreshButton_clicked(self): |
171 def on_refreshButton_clicked(self): |
164 """ |
172 """ |
165 Private slot to refresh the status display. |
173 Private slot to refresh the status display. |
166 """ |
174 """ |
167 self.start(self.__repodir) |
175 self.start(self.__repodir) |
168 |
176 |
169 @pyqtSlot(bool) |
177 @pyqtSlot(bool) |
170 def on_indexCheckBox_toggled(self, checked): |
178 def on_indexCheckBox_toggled(self, checked): |
171 """ |
179 """ |
172 Private slot handling a change of the index check box. |
180 Private slot handling a change of the index check box. |
173 |
181 |
174 @param checked check state of the check box |
182 @param checked check state of the check box |
175 @type bool |
183 @type bool |
176 """ |
184 """ |
177 self.on_refreshButton_clicked() |
185 self.on_refreshButton_clicked() |
178 |
186 |
179 @pyqtSlot(bool) |
187 @pyqtSlot(bool) |
180 def on_recursiveCheckBox_toggled(self, checked): |
188 def on_recursiveCheckBox_toggled(self, checked): |
181 """ |
189 """ |
182 Private slot handling a change of the recursive check box. |
190 Private slot handling a change of the recursive check box. |
183 |
191 |
184 @param checked check state of the check box |
192 @param checked check state of the check box |
185 @type bool |
193 @type bool |
186 """ |
194 """ |
187 self.on_refreshButton_clicked() |
195 self.on_refreshButton_clicked() |