Plugins/VcsPlugins/vcsPySvn/SvnUtilities.py

changeset 1880
dbd4d7698310
parent 1509
c0b5e693b0eb
child 1889
6de0f43f6678
--- a/Plugins/VcsPlugins/vcsPySvn/SvnUtilities.py	Mon May 28 15:59:36 2012 +0200
+++ b/Plugins/VcsPlugins/vcsPySvn/SvnUtilities.py	Tue May 29 20:59:40 2012 +0200
@@ -13,6 +13,8 @@
 
 import Utilities
 
+from .Config import DefaultConfig, DefaultIgnores
+
 
 def formatTime(seconds):
     """
@@ -38,7 +40,7 @@
 
 def getServersPath():
     """
-    Public method to get the filename of the servers file.
+    Module function to get the filename of the servers file.
     
     @return filename of the servers file (string)
     """
@@ -52,7 +54,7 @@
 
 def getConfigPath():
     """
-    Public method to get the filename of the config file.
+    Module function to get the filename of the config file.
     
     @return filename of the config file (string)
     """
@@ -62,3 +64,71 @@
     else:
         homedir = Utilities.getHomeDir()
         return os.path.join(homedir, ".subversion", "config")
+
+
+def createDefaultConfig():
+    """
+    Module function to create a default config file suitable for eric.
+    """
+    config = getConfigPath()
+    try:
+        os.makedirs(os.path.dirname(config))
+    except OSError:
+        pass
+    try:
+        f = open(config, "w")
+        f.write(DefaultConfig)
+        f.close()
+    except IOError:
+        pass
+
+
+def amendConfig():
+    """
+    Module function to amend the config file.
+    """
+    config = getConfigPath()
+    try:
+        f = open(config, "r")
+        configList = f.read().splitlines()
+        f.close()
+    except IOError:
+        return
+    
+    newConfig = []
+    ignoresFound = False
+    amendList = []
+    for line in configList:
+        if line.find("global-ignores") in [0, 2]:
+            ignoresFound = True
+            if line.startswith("# "):
+                line = line[2:]
+            newConfig.append(line)
+            for amend in DefaultIgnores:
+                if amend not in line:
+                    amendList.append(amend)
+        elif ignoresFound:
+            if line.startswith("##"):
+                ignoresFound = False
+                if amendList:
+                    newConfig.append("  " + " ".join(amendList))
+                newConfig.append(line)
+                continue
+            elif line.startswith("# "):
+                line = line[2:]
+            newConfig.append(line)
+            oldAmends = amendList[:]
+            amendList = []
+            for amend in oldAmends:
+                if amend not in line:
+                    amendList.append(amend)
+        else:
+            newConfig.append(line)
+    
+    if newConfig != configList:
+        try:
+            f = open(config, "w")
+            f.write(os.linesep.join(newConfig))
+            f.close()
+        except IOError:
+            pass

eric ide

mercurial