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