|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select the heads to be closed. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import pyqtSlot, QProcess |
|
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
|
16 |
|
17 from .Ui_HgCloseHeadSelectionDialog import Ui_HgCloseHeadSelectionDialog |
|
18 |
|
19 |
|
20 class HgCloseHeadSelectionDialog(QDialog, Ui_HgCloseHeadSelectionDialog): |
|
21 """ |
|
22 Class implementing a dialog to select the heads to be closed. |
|
23 """ |
|
24 def __init__(self, vcs, ppath, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param vcs reference to the VCS object |
|
29 @type Hg |
|
30 @param ppath directory containing the repository |
|
31 @type str |
|
32 @param parent reference to the parent widget |
|
33 @type QWidget |
|
34 """ |
|
35 super(HgCloseHeadSelectionDialog, self).__init__(parent) |
|
36 self.setupUi(self) |
|
37 |
|
38 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
|
39 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
40 |
|
41 heads = self.__getHeads(vcs, ppath) |
|
42 for revision, branch in heads: |
|
43 QTreeWidgetItem(self.headsList, [revision, branch]) |
|
44 |
|
45 def __getHeads(self, vcs, ppath): |
|
46 """ |
|
47 Private method to get the open heads. |
|
48 |
|
49 @param vcs reference to the VCS object |
|
50 @type Hg |
|
51 @param ppath directory containing the repository |
|
52 @type str |
|
53 @return list of tuples containing the revision and the corresponding |
|
54 branch name |
|
55 @rtype list of tuples of (str, str) |
|
56 """ |
|
57 args = vcs.initCommand("heads") |
|
58 args.append('--template') |
|
59 args.append('{node|short}@@@{branches}\n') |
|
60 |
|
61 output = "" |
|
62 client = vcs.getClient() |
|
63 if client is None: |
|
64 # find the root of the repo |
|
65 repodir = self.splitPath(ppath)[0] |
|
66 while not os.path.isdir(os.path.join(repodir, self.adminDir)): |
|
67 repodir = os.path.dirname(repodir) |
|
68 if os.path.splitdrive(repodir)[1] == os.sep: |
|
69 return [] |
|
70 |
|
71 process = QProcess() |
|
72 process.setWorkingDirectory(repodir) |
|
73 process.start('hg', args) |
|
74 procStarted = process.waitForStarted(5000) |
|
75 if procStarted: |
|
76 finished = process.waitForFinished(30000) |
|
77 if finished and process.exitCode() == 0: |
|
78 output = str(process.readAllStandardOutput(), |
|
79 self.getEncoding(), 'replace') |
|
80 else: |
|
81 output, error = client.runcommand(args) |
|
82 |
|
83 heads = [] |
|
84 if output: |
|
85 for line in output.splitlines(): |
|
86 line = line.strip() |
|
87 if line: |
|
88 revision, branch = line.split("@@@") |
|
89 heads.append((revision, branch)) |
|
90 |
|
91 return heads |
|
92 |
|
93 @pyqtSlot() |
|
94 def on_headsList_itemSelectionChanged(self): |
|
95 """ |
|
96 Private slot handling changes of the selection. |
|
97 """ |
|
98 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
99 len(self.headsList.selectedItems()) > 0 |
|
100 ) |
|
101 |
|
102 def getData(self): |
|
103 """ |
|
104 Public method to retrieve the entered data. |
|
105 |
|
106 @return tuple containing a list of selected revisions and the commit |
|
107 message |
|
108 @rtype tuple of (list of str, str) |
|
109 """ |
|
110 revisions = [itm.text(0) for itm in self.headsList.selectedItems()] |
|
111 message = self.logEdit.toPlainText().strip() |
|
112 |
|
113 return revisions, message |