Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListAllGuardsDialog.py

Mon, 08 Jul 2013 22:36:10 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 08 Jul 2013 22:36:10 +0200
branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2525
8b507a9a2d40
parent 2771
281c9b30dd91
child 3057
10516539f238
permissions
-rw-r--r--

Merge with default branch.

1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to show all guards for all patches.
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
10 from __future__ import unicode_literals # __IGNORE_WARNING__
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11 try:
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
12 str = unicode
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
13 except (NameError):
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
14 pass
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
15
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import os
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
1260
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
18 from PyQt4.QtCore import QProcess, QCoreApplication
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from PyQt4.QtGui import QDialog, QTreeWidgetItem
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from .Ui_HgQueuesListAllGuardsDialog import Ui_HgQueuesListAllGuardsDialog
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 import Preferences
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 import UI.PixmapCache
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class HgQueuesListAllGuardsDialog(QDialog, Ui_HgQueuesListAllGuardsDialog):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Class implementing a dialog to show all guards for all patches.
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 def __init__(self, vcs, parent=None):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Constructor
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param parent reference to the parent widget (QWidget)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
37 super(HgQueuesListAllGuardsDialog, self).__init__(parent)
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.setupUi(self)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.vcs = vcs
1254
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
41 self.__hgClient = vcs.getClient()
1260
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
42
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
43 self.show()
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
44 QCoreApplication.processEvents()
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def start(self, path):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Public slot to start the list command.
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @param path name of directory to be listed (string)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 dname, fname = self.vcs.splitPath(path)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 # find the root of the repo
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 repodir = dname
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 repodir = os.path.dirname(repodir)
1318
6fa303bd65d6 Fixed issues in various Mercurial files that could cause infinite loops on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
58 if os.path.splitdrive(repodir)[1] == os.sep:
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 return
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 args = []
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 args.append("qguard")
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 args.append("--list")
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
1254
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
65 output = ""
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
66 if self.__hgClient:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
67 output = self.__hgClient.runcommand(args)[0]
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
68 else:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
69 ioEncoding = Preferences.getSystem("IOEncoding")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
70 process = QProcess()
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
71 process.setWorkingDirectory(repodir)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
72 process.start('hg', args)
2771
281c9b30dd91 Changed all QProcess.waitForStarted() calls to use a 5s timeout (except the debugger interfaces, which have a 10s timeout).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
73 procStarted = process.waitForStarted(5000)
1254
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
74 if procStarted:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
75 finished = process.waitForFinished(30000)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
76 if finished and process.exitCode() == 0:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
77 output = \
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
78 str(process.readAllStandardOutput(), ioEncoding, 'replace')
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
79
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
80 if output:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
81 guardsDict = {}
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
82 for line in output.splitlines():
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
83 if line:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
84 patchName, guards = line.strip().split(":", 1)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
85 guardsDict[patchName] = guards.strip().split()
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
86 for patchName in sorted(guardsDict.keys()):
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
87 patchItm = QTreeWidgetItem(self.guardsTree, [patchName])
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
88 patchItm.setExpanded(True)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
89 for guard in guardsDict[patchName]:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
90 if guard.startswith("+"):
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
91 icon = UI.PixmapCache.getIcon("plus.png")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
92 guard = guard[1:]
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
93 elif guard.startswith("-"):
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
94 icon = UI.PixmapCache.getIcon("minus.png")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
95 guard = guard[1:]
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
96 else:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
97 icon = None
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
98 guard = self.trUtf8("Unguarded")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
99 itm = QTreeWidgetItem(patchItm, [guard])
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
100 if icon:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
101 itm.setIcon(0, icon)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
102 else:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
103 QTreeWidgetItem(self.guardsTree, [self.trUtf8("no patches found")])

eric ide

mercurial