eric6/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py

changeset 7971
ff2971513d6d
parent 7970
c4ee8a81584c
child 8143
2c730d5fd177
equal deleted inserted replaced
7970:c4ee8a81584c 7971:ff2971513d6d
11 11
12 from PyQt5.QtCore import QTimer 12 from PyQt5.QtCore import QTimer
13 from PyQt5.QtWidgets import QDialog 13 from PyQt5.QtWidgets import QDialog
14 14
15 from E5Gui.E5Application import e5App 15 from E5Gui.E5Application import e5App
16 from E5Gui import E5MessageBox
16 17
17 from ..HgExtension import HgExtension 18 from ..HgExtension import HgExtension
18 from ..HgDialog import HgDialog 19 from ..HgDialog import HgDialog
20 from ..HgClient import HgClient
19 21
20 22
21 class Largefiles(HgExtension): 23 class Largefiles(HgExtension):
22 """ 24 """
23 Class implementing the largefiles extension interface. 25 Class implementing the largefiles extension interface.
43 if direction not in ["largefiles", "normal"]: 45 if direction not in ["largefiles", "normal"]:
44 raise ValueError("Bad value for 'direction' parameter.") 46 raise ValueError("Bad value for 'direction' parameter.")
45 47
46 projectDir = os.path.dirname(projectFile) 48 projectDir = os.path.dirname(projectFile)
47 49
48 # find the root of the repo
49 repodir = projectDir
50 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
51 repodir = os.path.dirname(repodir)
52 if os.path.splitdrive(repodir)[1] == os.sep:
53 return
54
55 from .LfConvertDataDialog import LfConvertDataDialog 50 from .LfConvertDataDialog import LfConvertDataDialog
56 dlg = LfConvertDataDialog(projectDir, direction) 51 dlg = LfConvertDataDialog(projectDir, direction)
57 if dlg.exec() == QDialog.Accepted: 52 if dlg.exec() == QDialog.Accepted:
58 newName, minSize, patterns = dlg.getData() 53 newName, minSize, patterns = dlg.getData()
59 newProjectFile = os.path.join( 54 newProjectFile = os.path.join(
70 args.append(newName) 65 args.append(newName)
71 if direction == 'largefiles' and patterns: 66 if direction == 'largefiles' and patterns:
72 args.extend(patterns) 67 args.extend(patterns)
73 68
74 dia = HgDialog(self.tr('Convert Project - Converting'), self.vcs) 69 dia = HgDialog(self.tr('Convert Project - Converting'), self.vcs)
75 res = dia.startProcess(args, repodir) 70 res = dia.startProcess(args)
76 if res: 71 if res:
77 dia.exec() 72 dia.exec()
78 res = dia.normalExit() and os.path.isdir( 73 res = dia.normalExit() and os.path.isdir(
79 os.path.join(newName, self.vcs.adminDir)) 74 os.path.join(newName, self.vcs.adminDir))
80 75
81 # step 2: create working directory contents 76 # step 2: create working directory contents
82 if res: 77 if res:
78 # step 2.1: start a command server client for the new repo
79 client = HgClient(newName, "utf-8", self.vcs)
80 ok, err = client.startServer()
81 if not ok:
82 E5MessageBox.warning(
83 None,
84 self.tr("Mercurial Command Server"),
85 self.tr(
86 """<p>The Mercurial Command Server could not be"""
87 """ started.</p><p>Reason: {0}</p>""").format(err))
88 return
89
90 # step 2.2: create working directory contents
83 args = self.vcs.initCommand("update") 91 args = self.vcs.initCommand("update")
84 args.append("--verbose") 92 args.append("--verbose")
85 dia = HgDialog(self.tr('Convert Project - Extracting'), 93 dia = HgDialog(self.tr('Convert Project - Extracting'),
86 self.vcs, useClient=False) 94 self.vcs, client=client)
87 res = dia.startProcess(args, newName) 95 res = dia.startProcess(args)
88 if res: 96 if res:
89 dia.exec() 97 dia.exec()
90 res = dia.normalExit() and os.path.isfile(newProjectFile) 98 res = dia.normalExit() and os.path.isfile(newProjectFile)
99
100 # step 2.3: stop the command server client for the new repo
101 client.stopServer()
91 102
92 # step 3: close current project and open new one 103 # step 3: close current project and open new one
93 if res: 104 if res:
94 if direction == 'largefiles': 105 if direction == 'largefiles':
95 self.vcs.hgEditConfig(newName, largefilesData={ 106 self.vcs.hgEditConfig(
96 "minsize": minSize, "pattern": patterns}) 107 repoName=newName,
108 largefilesData={"minsize": minSize,
109 "pattern": patterns}
110 )
97 else: 111 else:
98 self.vcs.hgEditConfig(newName, withLargefiles=False) 112 self.vcs.hgEditConfig(
113 repoName=newName,
114 withLargefiles=False
115 )
99 QTimer.singleShot( 116 QTimer.singleShot(
100 0, lambda: e5App().getObject("Project").openProject( 117 0, lambda: e5App().getObject("Project").openProject(
101 newProjectFile)) 118 newProjectFile))
102 119
103 def hgAdd(self, names, mode): 120 def hgAdd(self, names, mode):
113 args.append("--large") 130 args.append("--large")
114 else: 131 else:
115 args.append("--normal") 132 args.append("--normal")
116 133
117 if isinstance(names, list): 134 if isinstance(names, list):
118 dname = self.vcs.splitPathList(names)[0]
119 else:
120 dname = self.vcs.splitPath(names)[0]
121
122 # find the root of the repo
123 repodir = dname
124 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
125 repodir = os.path.dirname(repodir)
126 if os.path.splitdrive(repodir)[1] == os.sep:
127 return
128
129 if isinstance(names, list):
130 self.vcs.addArguments(args, names) 135 self.vcs.addArguments(args, names)
131 else: 136 else:
132 args.append(names) 137 args.append(names)
133 138
134 dia = HgDialog( 139 dia = HgDialog(
135 self.tr('Adding files to the Mercurial repository'), 140 self.tr('Adding files to the Mercurial repository'),
136 self.vcs) 141 self.vcs)
137 res = dia.startProcess(args, repodir) 142 res = dia.startProcess(args)
138 if res: 143 if res:
139 dia.exec() 144 dia.exec()
140 145
141 def hgLfPull(self, revisions=None): 146 def hgLfPull(self, revisions=None):
142 """ 147 """
163 dia = HgDialog(self.tr("Pulling large files"), self.vcs) 168 dia = HgDialog(self.tr("Pulling large files"), self.vcs)
164 res = dia.startProcess(args) 169 res = dia.startProcess(args)
165 if res: 170 if res:
166 dia.exec() 171 dia.exec()
167 172
168 def hgLfVerify(self, projectDir, mode): 173 def hgLfVerify(self, mode):
169 """ 174 """
170 Public method to verify large files integrity. 175 Public method to verify large files integrity.
171 176
172 @param projectDir directory name of the project (string)
173 @param mode verify mode (string; one of 'large', 'lfa' or 'lfc') 177 @param mode verify mode (string; one of 'large', 'lfa' or 'lfc')
174 """ 178 """
175 # find the root of the repo
176 repodir = projectDir
177 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
178 repodir = os.path.dirname(repodir)
179 if os.path.splitdrive(repodir)[1] == os.sep:
180 return
181
182 args = self.vcs.initCommand("verify") 179 args = self.vcs.initCommand("verify")
183 if mode == "large": 180 if mode == "large":
184 args.append("--large") 181 args.append("--large")
185 elif mode == "lfa": 182 elif mode == "lfa":
186 args.append("--lfa") 183 args.append("--lfa")
190 return 187 return
191 188
192 dia = HgDialog( 189 dia = HgDialog(
193 self.tr('Verifying the integrity of large files'), 190 self.tr('Verifying the integrity of large files'),
194 self.vcs) 191 self.vcs)
195 res = dia.startProcess(args, repodir) 192 res = dia.startProcess(args)
196 if res: 193 if res:
197 dia.exec() 194 dia.exec()

eric ide

mercurial