Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py

changeset 3310
a2032ed66aec
child 3311
b4775920f5b8
equal deleted inserted replaced
3309:b5f782f7d43b 3310:a2032ed66aec
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the largefiles extension interface.
8 """
9
10 import os
11 import shutil
12
13 from PyQt4.QtGui import QDialog
14
15 from E5Gui.E5Application import e5App
16 from E5Gui import E5MessageBox
17
18 from ..HgExtension import HgExtension
19 from ..HgDialog import HgDialog
20
21 from . import getDefaults
22
23
24 class Largefiles(HgExtension):
25 """
26 Class implementing the largefiles extension interface.
27 """
28 def __init__(self, vcs):
29 """
30 Constructor
31
32 @param vcs reference to the Mercurial vcs object
33 """
34 super().__init__(vcs)
35
36 def hgLfconvert(self, direction, projectFile):
37 """
38 Public slot to convert the repository format of the current project.
39
40 @param direction direction of the conversion (string, one of
41 'largefiles' or 'normal')
42 @param projectFile file name of the current project file (string)
43 """
44 assert direction in ["largefiles", "normal"]
45
46 projectDir = os.path.dirname(projectFile)
47
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 False
54
55 from .LfConvertDataDialog import LfConvertDataDialog
56 dlg = LfConvertDataDialog(projectDir, direction)
57 if dlg.exec_() == QDialog.Accepted:
58 newName, minSize, patterns = dlg.getData()
59 newProjectFile = os.path.join(
60 newName, os.path.basename(projectFile))
61
62 # step 1: convert the current project to new project
63 args = self.vcs.initCommand("lfconvert")
64 if direction == 'normal':
65 args.append('--to-normal')
66 else:
67 args.append("--size")
68 args.append(str(minSize))
69 args.append(projectDir)
70 args.append(newName)
71 if direction == 'largefiles' and patterns:
72 args.extend(patterns)
73
74 dia = HgDialog(self.tr('Convert Project - Converting'), self.vcs)
75 res = dia.startProcess(args, repodir)
76 if res:
77 dia.exec_()
78 res = dia.normalExit() and os.path.isdir(
79 os.path.join(newName, self.vcs.adminDir))
80
81 # step 2: create working directory contents
82 if res:
83 args = self.vcs.initCommand("update")
84 if "-v" not in args and "--verbose" not in args:
85 args.append("-v")
86 dia = HgDialog(self.tr('Convert Project - Extracting'),
87 self.vcs, useClient=False)
88 res = dia.startProcess(args, newName)
89 if res:
90 dia.exec_()
91 res = dia.normalExit() and os.path.isfile(newProjectFile)
92
93 # step 3: close current project and open new one
94 if res:
95 e5App().getObject("Project").openProject(newProjectFile)
96
97 # step 3.1: copy old hgrc file
98 hgrc = os.path.join(repodir, self.vcs.adminDir, "hgrc")
99 if os.path.exists(hgrc):
100 ok = E5MessageBox.yesNo(
101 None,
102 self.tr("Convert Project"),
103 self.tr("""Shall the Mercurial repository"""
104 """ configuration file be copied over?"""))
105 if ok:
106 shutil.copy(
107 hgrc,
108 os.path.join(newName, self.vcs.adminDir, "hgrc"))
109 # TODO: write patterns to hgrc

eric ide

mercurial