Continued implementing Mercurial lfconvert functionality.

Fri, 28 Feb 2014 18:24:24 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 28 Feb 2014 18:24:24 +0100
changeset 3311
b4775920f5b8
parent 3310
a2032ed66aec
child 3312
7535e5a5cbce

Continued implementing Mercurial lfconvert functionality.

Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.ui file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/hg.py file | annotate | diff | comparison | revisions
--- a/Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.py	Thu Feb 27 19:48:55 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.py	Fri Feb 28 18:24:24 2014 +0100
@@ -12,16 +12,22 @@
 
 import UI.PixmapCache
 
+from .LargefilesExtension import getDefaults as getLargefilesDefaults
+
 
 class HgRepoConfigDataDialog(QDialog, Ui_HgRepoConfigDataDialog):
     """
     Class implementing a dialog to enter data needed for the initial creation
     of a repository configuration file (hgrc).
     """
-    def __init__(self, parent=None):
+    def __init__(self, withLargefiles=False, largefilesData=None, parent=None):
         """
         Constructor
         
+        @param withLargefiles flag indicating to configure the largefiles
+            section (boolean)
+        @param largefilesData dictionary with data for the largefiles
+            section (dict)
         @param parent reference to the parent widget (QWidget)
         """
         super().__init__(parent)
@@ -32,6 +38,16 @@
         self.defaultPushShowPasswordButton.setIcon(
             UI.PixmapCache.getIcon("showPassword.png"))
         
+        self.__withLargefiles = withLargefiles
+        if withLargefiles:
+            if largefilesData is None:
+                largefilesData = getLargefilesDefaults()
+            self.lfFileSizeSpinBox.setValue(largefilesData["minsize"])
+            self.lfFilePatternsEdit.setText(
+                " ".join(largefilesData["pattern"]))
+        else:
+            self.largefilesGroup.setVisible(False)
+        
         self.resize(self.width(), self.minimumSizeHint().height())
     
     @pyqtSlot(bool)
@@ -92,3 +108,24 @@
             defaultPushUrl = defaultPushUrl.toString()
         
         return defaultUrl, defaultPushUrl
+    
+    def getLargefilesData(self):
+        """
+        Public method to get the data for the largefiles extension.
+        
+        @return tuple with the minimum file size (integer) and file patterns
+            (list of string). None as value denote to use the default value.
+        """
+        if self.__withLargefiles:
+            lfDefaults = getLargefilesDefaults()
+            if self.lfFileSizeSpinBox.value() == lfDefaults["minsize"]:
+                minsize = None
+            else:
+                minsize = self.lfFileSizeSpinBox.value()
+            patterns = self.lfFilePatternsEdit.text().split()
+            if set(patterns) == set(lfDefaults["pattern"]):
+                patterns = None
+            
+            return minsize, patterns
+        else:
+            return None, None
--- a/Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.ui	Thu Feb 27 19:48:55 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.ui	Fri Feb 28 18:24:24 2014 +0100
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>650</width>
-    <height>323</height>
+    <width>500</width>
+    <height>352</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -146,6 +146,68 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="largefilesGroup">
+     <property name="title">
+      <string>Large Files</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_3">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_8">
+        <property name="text">
+         <string>Minimum file size:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QSpinBox" name="lfFileSizeSpinBox">
+        <property name="toolTip">
+         <string>Enter the minimum file size in MB for files to be treated as Large Files</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        </property>
+        <property name="suffix">
+         <string> MB</string>
+        </property>
+        <property name="minimum">
+         <number>1</number>
+        </property>
+        <property name="value">
+         <number>10</number>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>215</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_9">
+        <property name="text">
+         <string>Patterns:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1" colspan="2">
+       <widget class="QLineEdit" name="lfFilePatternsEdit">
+        <property name="toolTip">
+         <string>Enter file patterns (space separated) for files to be treated as Large Files</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -173,6 +235,8 @@
   <tabstop>defaultPushUserEdit</tabstop>
   <tabstop>defaultPushPasswordEdit</tabstop>
   <tabstop>defaultPushShowPasswordButton</tabstop>
+  <tabstop>lfFileSizeSpinBox</tabstop>
+  <tabstop>lfFilePatternsEdit</tabstop>
   <tabstop>buttonBox</tabstop>
  </tabstops>
  <resources/>
--- a/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py	Thu Feb 27 19:48:55 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py	Fri Feb 28 18:24:24 2014 +0100
@@ -8,18 +8,14 @@
 """
 
 import os
-import shutil
 
 from PyQt4.QtGui import QDialog
 
 from E5Gui.E5Application import e5App
-from E5Gui import E5MessageBox
 
 from ..HgExtension import HgExtension
 from ..HgDialog import HgDialog
 
-from . import getDefaults
-
 
 class Largefiles(HgExtension):
     """
@@ -81,8 +77,7 @@
             # step 2: create working directory contents
             if res:
                 args = self.vcs.initCommand("update")
-                if "-v" not in args and "--verbose" not in args:
-                    args.append("-v")
+                args.append("--verbose")
                 dia = HgDialog(self.tr('Convert Project - Extracting'),
                                self.vcs, useClient=False)
                 res = dia.startProcess(args, newName)
@@ -93,17 +88,8 @@
             # step 3: close current project and open new one
             if res:
                 e5App().getObject("Project").openProject(newProjectFile)
-                
-                # step 3.1: copy old hgrc file
-                hgrc = os.path.join(repodir, self.vcs.adminDir, "hgrc")
-                if os.path.exists(hgrc):
-                    ok = E5MessageBox.yesNo(
-                        None,
-                        self.tr("Convert Project"),
-                        self.tr("""Shall the Mercurial repository"""
-                                """ configuration file be copied over?"""))
-                    if ok:
-                        shutil.copy(
-                            hgrc,
-                            os.path.join(newName, self.vcs.adminDir, "hgrc"))
-                # TODO: write patterns to hgrc
+                if direction == 'largefiles':
+                    self.vcs.hgEditConfig(newName, largefilesData={
+                        "minsize": minSize, "pattern": patterns})
+                else:
+                    self.vcs.hgEditConfig(newName, withLargefiles=False)
--- a/Plugins/VcsPlugins/vcsMercurial/hg.py	Thu Feb 27 19:48:55 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/hg.py	Fri Feb 28 18:24:24 2014 +0100
@@ -2192,11 +2192,15 @@
         self.userEditor = MiniEditor(cfgFile, "Properties")
         self.userEditor.show()
     
-    def hgEditConfig(self, name):
+    def hgEditConfig(self, name, withLargefiles=True, largefilesData=None):
         """
         Public method used to edit the repository configuration file.
         
         @param name file/directory name (string)
+        @param withLargefiles flag indicating to configure the largefiles
+            section (boolean)
+        @param largefilesData dictionary with data for the largefiles
+            section of the data dialog (dict)
         """
         dname, fname = self.splitPath(name)
         
@@ -2210,11 +2214,16 @@
         cfgFile = os.path.join(repodir, self.adminDir, "hgrc")
         if not os.path.exists(cfgFile):
             # open dialog to enter the initial data
+            withLargefiles = (self.isExtensionActive("largefiles") and 
+                              withLargefiles)
             from .HgRepoConfigDataDialog import HgRepoConfigDataDialog
-            dlg = HgRepoConfigDataDialog()
+            dlg = HgRepoConfigDataDialog(withLargefiles=withLargefiles,
+                                         largefilesData=largefilesData)
             if dlg.exec_() == QDialog.Accepted:
                 createContents = True
                 defaultUrl, defaultPushUrl = dlg.getData()
+                if withLargefiles:
+                    lfMinSize, lfPattern = dlg.getLargefilesData()
             else:
                 createContents = False
             try:
@@ -2227,6 +2236,15 @@
                     if defaultPushUrl:
                         cfg.write("default-push = {0}\n".format(
                             defaultPushUrl))
+                    if withLargefiles and \
+                            (lfMinSize, lfPattern) != (None, None):
+                        cfg.write("\n[largefiles]\n")
+                        if lfMinSize is not None:
+                            cfg.write("minsize = {0}\n".format(lfMinSize))
+                        if lfPattern is not None:
+                            cfg.write("patterns =\n")
+                            cfg.write("  {0}\n".format(
+                                "\n  ".join(lfPattern)))
                 cfg.close()
                 self.__monitorRepoIniFile(repodir)
             except IOError:

eric ide

mercurial