Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListAllGuardsDialog.py

changeset 1254
c077fa008aae
parent 1131
7781e396c903
child 1260
9488a3aceb0e
equal deleted inserted replaced
1253:4a994190cf8b 1254:c077fa008aae
7 Module implementing a dialog to show all guards for all patches. 7 Module implementing a dialog to show all guards for all patches.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QProcess, QTimer 12 from PyQt4.QtCore import QProcess
13 from PyQt4.QtGui import QDialog, QTreeWidgetItem 13 from PyQt4.QtGui import QDialog, QTreeWidgetItem
14 14
15 from .Ui_HgQueuesListAllGuardsDialog import Ui_HgQueuesListAllGuardsDialog 15 from .Ui_HgQueuesListAllGuardsDialog import Ui_HgQueuesListAllGuardsDialog
16 16
17 import Preferences 17 import Preferences
29 @param parent reference to the parent widget (QWidget) 29 @param parent reference to the parent widget (QWidget)
30 """ 30 """
31 super().__init__(parent) 31 super().__init__(parent)
32 self.setupUi(self) 32 self.setupUi(self)
33 33
34 self.process = QProcess()
35 self.vcs = vcs 34 self.vcs = vcs
36 35 self.__hgClient = vcs.getClient()
37 def closeEvent(self, e):
38 """
39 Private slot implementing a close event handler.
40
41 @param e close event (QCloseEvent)
42 """
43 if self.process is not None and \
44 self.process.state() != QProcess.NotRunning:
45 self.process.terminate()
46 QTimer.singleShot(2000, self.process.kill)
47 self.process.waitForFinished(3000)
48
49 e.accept()
50 36
51 def start(self, path): 37 def start(self, path):
52 """ 38 """
53 Public slot to start the list command. 39 Public slot to start the list command.
54 40
61 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 47 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
62 repodir = os.path.dirname(repodir) 48 repodir = os.path.dirname(repodir)
63 if repodir == os.sep: 49 if repodir == os.sep:
64 return 50 return
65 51
66 ioEncoding = Preferences.getSystem("IOEncoding")
67 process = QProcess()
68 args = [] 52 args = []
69 args.append("qguard") 53 args.append("qguard")
70 args.append("--list") 54 args.append("--list")
71 55
72 process.setWorkingDirectory(repodir) 56 output = ""
73 process.start('hg', args) 57 if self.__hgClient:
74 procStarted = process.waitForStarted() 58 output = self.__hgClient.runcommand(args)[0]
75 if procStarted: 59 else:
76 finished = process.waitForFinished(30000) 60 ioEncoding = Preferences.getSystem("IOEncoding")
77 if finished and process.exitCode() == 0: 61 process = QProcess()
78 output = \ 62 process.setWorkingDirectory(repodir)
79 str(process.readAllStandardOutput(), ioEncoding, 'replace') 63 process.start('hg', args)
80 if output: 64 procStarted = process.waitForStarted()
81 guardsDict = {} 65 if procStarted:
82 for line in output.splitlines(): 66 finished = process.waitForFinished(30000)
83 if line: 67 if finished and process.exitCode() == 0:
84 patchName, guards = line.strip().split(":", 1) 68 output = \
85 guardsDict[patchName] = guards.strip().split() 69 str(process.readAllStandardOutput(), ioEncoding, 'replace')
86 for patchName in sorted(guardsDict.keys()): 70
87 patchItm = QTreeWidgetItem(self.guardsTree, [patchName]) 71 if output:
88 patchItm.setExpanded(True) 72 guardsDict = {}
89 for guard in guardsDict[patchName]: 73 for line in output.splitlines():
90 if guard.startswith("+"): 74 if line:
91 icon = UI.PixmapCache.getIcon("plus.png") 75 patchName, guards = line.strip().split(":", 1)
92 guard = guard[1:] 76 guardsDict[patchName] = guards.strip().split()
93 elif guard.startswith("-"): 77 for patchName in sorted(guardsDict.keys()):
94 icon = UI.PixmapCache.getIcon("minus.png") 78 patchItm = QTreeWidgetItem(self.guardsTree, [patchName])
95 guard = guard[1:] 79 patchItm.setExpanded(True)
96 else: 80 for guard in guardsDict[patchName]:
97 icon = None 81 if guard.startswith("+"):
98 guard = self.trUtf8("Unguarded") 82 icon = UI.PixmapCache.getIcon("plus.png")
99 itm = QTreeWidgetItem(patchItm, [guard]) 83 guard = guard[1:]
100 if icon: 84 elif guard.startswith("-"):
101 itm.setIcon(0, icon) 85 icon = UI.PixmapCache.getIcon("minus.png")
102 else: 86 guard = guard[1:]
103 QTreeWidgetItem(self.guardsTree, [self.trUtf8("no patches found")]) 87 else:
88 icon = None
89 guard = self.trUtf8("Unguarded")
90 itm = QTreeWidgetItem(patchItm, [guard])
91 if icon:
92 itm.setIcon(0, icon)
93 else:
94 QTreeWidgetItem(self.guardsTree, [self.trUtf8("no patches found")])

eric ide

mercurial