Plugins/VcsPlugins/vcsMercurial/PurgeExtension/purge.py

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

eric ide

mercurial