Plugins/VcsPlugins/vcsMercurial/PurgeExtension/purge.py

Sat, 28 May 2011 15:41:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 28 May 2011 15:41:12 +0200
changeset 1071
ac0f74c0b870
child 1087
fb8cd56819a9
permissions
-rw-r--r--

Added support for the Mercurial purge extension.

1071
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the purge extension interface.
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt4.QtCore import QObject, QProcess
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt4.QtGui import QDialog
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from ..HgDialog import HgDialog
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from .HgPurgeListDialog import HgPurgeListDialog
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Preferences
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class Purge(QObject):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing the purge extension interface.
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 def __init__(self, vcs):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param vcs reference to the Mercurial vcs object
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 QObject.__init__(self, vcs)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.vcs = vcs
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.purgeListDialog = None
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def shutdown(self):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Public method used to shutdown the purge interface.
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 if self.purgeListDialog is not None:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.purgeListDialog.close()
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 def __getEntries(self, repodir, all):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 Public method to get a list of files/directories being purged.
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @param repodir directory name of the repository (string)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @param all flag indicating to delete all files including ignored ones (boolean)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @return name of the current patch (string)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 purgeEntries = []
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 ioEncoding = Preferences.getSystem("IOEncoding")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 process = QProcess()
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 args = []
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 args.append("purge")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 args.append("--print")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if all:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 args.append("--all")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 process.setWorkingDirectory(repodir)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 process.start('hg', args)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 procStarted = process.waitForStarted()
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if procStarted:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 finished = process.waitForFinished(30000)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if finished and process.exitCode() == 0:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 purgeEntries = str(
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 process.readAllStandardOutput(),
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ioEncoding, 'replace').strip().split()
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 return purgeEntries
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 def hgPurge(self, name, all=False):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 Public method to purge files and directories not tracked by Mercurial.
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 @param name file/directory name (string)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @param all flag indicating to delete all files including ignored ones (boolean)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 # find the root of the repo
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 repodir = self.vcs.splitPath(name)[0]
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 repodir = os.path.dirname(repodir)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if repodir == os.sep:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 return False
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 if all:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 title = self.trUtf8("Purge All Files")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 message = self.trUtf8("""Do really want to delete all files not tracked by"""
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """ Mercurial (including ignored ones)?""")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 else:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 title = self.trUtf8("Purge Files")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 message = self.trUtf8("""Do really want to delete files not tracked by"""
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """ Mercurial?""")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 entries = self.__getEntries(repodir, all)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 dlg = DeleteFilesConfirmationDialog(None, title, message, entries)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 if dlg.exec_() == QDialog.Accepted:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 args = []
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 args.append("purge")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 if all:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 args.append("--all")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 args.append("-v")
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 dia = HgDialog(title)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 res = dia.startProcess(args, repodir)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 if res:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 dia.exec_()
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 def hgPurgeList(self, name, all=False):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 Public method to list files and directories not tracked by Mercurial.
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @param name file/directory name (string)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @param all flag indicating to list all files including ignored ones (boolean)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 # find the root of the repo
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 repodir = self.vcs.splitPath(name)[0]
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 repodir = os.path.dirname(repodir)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if repodir == os.sep:
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 return False
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 entries = self.__getEntries(repodir, all)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.purgeListDialog = HgPurgeListDialog(entries)
ac0f74c0b870 Added support for the Mercurial purge extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.purgeListDialog.show()

eric ide

mercurial