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

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the largefiles extension interface.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 from PyQt5.QtCore import QTimer
15 from PyQt5.QtWidgets import QDialog
16
17 from E5Gui.E5Application import e5App
18
19 from ..HgExtension import HgExtension
20 from ..HgDialog import HgDialog
21
22
23 class Largefiles(HgExtension):
24 """
25 Class implementing the largefiles extension interface.
26 """
27 def __init__(self, vcs):
28 """
29 Constructor
30
31 @param vcs reference to the Mercurial vcs object
32 """
33 super(Largefiles, self).__init__(vcs)
34
35 def hgLfconvert(self, direction, projectFile):
36 """
37 Public slot to convert the repository format of the current project.
38
39 @param direction direction of the conversion (string, one of
40 'largefiles' or 'normal')
41 @param projectFile file name of the current project file (string)
42 """
43 assert direction in ["largefiles", "normal"]
44
45 projectDir = os.path.dirname(projectFile)
46
47 # find the root of the repo
48 repodir = projectDir
49 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
50 repodir = os.path.dirname(repodir)
51 if os.path.splitdrive(repodir)[1] == os.sep:
52 return
53
54 from .LfConvertDataDialog import LfConvertDataDialog
55 dlg = LfConvertDataDialog(projectDir, direction)
56 if dlg.exec_() == QDialog.Accepted:
57 newName, minSize, patterns = dlg.getData()
58 newProjectFile = os.path.join(
59 newName, os.path.basename(projectFile))
60
61 # step 1: convert the current project to new project
62 args = self.vcs.initCommand("lfconvert")
63 if direction == 'normal':
64 args.append('--to-normal')
65 else:
66 args.append("--size")
67 args.append(str(minSize))
68 args.append(projectDir)
69 args.append(newName)
70 if direction == 'largefiles' and patterns:
71 args.extend(patterns)
72
73 dia = HgDialog(self.tr('Convert Project - Converting'), self.vcs)
74 res = dia.startProcess(args, repodir)
75 if res:
76 dia.exec_()
77 res = dia.normalExit() and os.path.isdir(
78 os.path.join(newName, self.vcs.adminDir))
79
80 # step 2: create working directory contents
81 if res:
82 args = self.vcs.initCommand("update")
83 args.append("--verbose")
84 dia = HgDialog(self.tr('Convert Project - Extracting'),
85 self.vcs, useClient=False)
86 res = dia.startProcess(args, newName)
87 if res:
88 dia.exec_()
89 res = dia.normalExit() and os.path.isfile(newProjectFile)
90
91 # step 3: close current project and open new one
92 if res:
93 if direction == 'largefiles':
94 self.vcs.hgEditConfig(newName, largefilesData={
95 "minsize": minSize, "pattern": patterns})
96 else:
97 self.vcs.hgEditConfig(newName, withLargefiles=False)
98 QTimer.singleShot(
99 0, lambda: e5App().getObject("Project").openProject(
100 newProjectFile))
101
102 def hgAdd(self, names, mode):
103 """
104 Public method used to add a file to the Mercurial repository.
105
106 @param names file name(s) to be added (string or list of string)
107 @param mode add mode (string one of 'normal' or 'large')
108 """
109 args = self.vcs.initCommand("add")
110 args.append("-v")
111 if mode == "large":
112 args.append("--large")
113 else:
114 args.append("--normal")
115
116 if isinstance(names, list):
117 dname = self.vcs.splitPathList(names)[0]
118 else:
119 dname = self.vcs.splitPath(names)[0]
120
121 # find the root of the repo
122 repodir = dname
123 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
124 repodir = os.path.dirname(repodir)
125 if os.path.splitdrive(repodir)[1] == os.sep:
126 return
127
128 if isinstance(names, list):
129 self.vcs.addArguments(args, names)
130 else:
131 args.append(names)
132
133 dia = HgDialog(
134 self.tr('Adding files to the Mercurial repository'),
135 self.vcs)
136 res = dia.startProcess(args, repodir)
137 if res:
138 dia.exec_()
139
140 def hgLfPull(self, projectDir, revisions=None):
141 """
142 Public method to pull missing large files into the local repository.
143
144 @param projectDir directory name of the project (string)
145 @param revisions list of revisions to pull (list of string)
146 """
147 # find the root of the repo
148 repodir = projectDir
149 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
150 repodir = os.path.dirname(repodir)
151 if os.path.splitdrive(repodir)[1] == os.sep:
152 return
153
154 revs = []
155 if revisions:
156 revs = revisions
157 else:
158 from .LfRevisionsInputDialog import LfRevisionsInputDialog
159 dlg = LfRevisionsInputDialog()
160 if dlg.exec_() == QDialog.Accepted:
161 revs = dlg.getRevisions()
162
163 if revs:
164 args = self.vcs.initCommand("lfpull")
165 args.append("-v")
166 for rev in revs:
167 args.append("--rev")
168 args.append(rev)
169
170 dia = HgDialog(self.tr("Pulling large files"), self.vcs)
171 res = dia.startProcess(args, repodir)
172 if res:
173 dia.exec_()
174
175 def hgLfVerify(self, projectDir, mode):
176 """
177 Public method to verify large files integrity.
178
179 @param projectDir directory name of the project (string)
180 @param mode verify mode (string; one of 'large', 'lfa' or 'lfc')
181 """
182 # find the root of the repo
183 repodir = projectDir
184 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
185 repodir = os.path.dirname(repodir)
186 if os.path.splitdrive(repodir)[1] == os.sep:
187 return
188
189 args = self.vcs.initCommand("verify")
190 if mode == "large":
191 args.append("--large")
192 elif mode == "lfa":
193 args.append("--lfa")
194 elif mode == "lfc":
195 args.append("--lfc")
196 else:
197 return
198
199 dia = HgDialog(
200 self.tr('Verifying the integrity of large files'),
201 self.vcs)
202 res = dia.startProcess(args, repodir)
203 if res:
204 dia.exec_()

eric ide

mercurial