eric6/Plugins/VcsPlugins/vcsSubversion/SvnUtilities.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) 2006 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing some common utility functions for the subversion package.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 import Utilities
15
16 from .Config import DefaultConfig, DefaultIgnores
17
18
19 def getServersPath():
20 """
21 Module function to get the filename of the servers file.
22
23 @return filename of the servers file (string)
24 """
25 if Utilities.isWindowsPlatform():
26 appdata = os.environ["APPDATA"]
27 return os.path.join(appdata, "Subversion", "servers")
28 else:
29 homedir = Utilities.getHomeDir()
30 return os.path.join(homedir, ".subversion", "servers")
31
32
33 def getConfigPath():
34 """
35 Module function to get the filename of the config file.
36
37 @return filename of the config file (string)
38 """
39 if Utilities.isWindowsPlatform():
40 appdata = os.environ["APPDATA"]
41 return os.path.join(appdata, "Subversion", "config")
42 else:
43 homedir = Utilities.getHomeDir()
44 return os.path.join(homedir, ".subversion", "config")
45
46
47 def createDefaultConfig():
48 """
49 Module function to create a default config file suitable for eric.
50 """
51 config = getConfigPath()
52 try:
53 os.makedirs(os.path.dirname(config))
54 except OSError:
55 pass
56 try:
57 f = open(config, "w")
58 f.write(DefaultConfig)
59 f.close()
60 except IOError:
61 pass
62
63
64 def amendConfig():
65 """
66 Module function to amend the config file.
67 """
68 config = getConfigPath()
69 try:
70 f = open(config, "r")
71 configList = f.read().splitlines()
72 f.close()
73 except IOError:
74 return
75
76 newConfig = []
77 ignoresFound = False
78 amendList = []
79 for line in configList:
80 if line.find("global-ignores") in [0, 2]:
81 ignoresFound = True
82 if line.startswith("# "):
83 line = line[2:]
84 newConfig.append(line)
85 for amend in DefaultIgnores:
86 if amend not in line:
87 amendList.append(amend)
88 elif ignoresFound:
89 if line.startswith("##"):
90 ignoresFound = False
91 if amendList:
92 newConfig.append(" " + " ".join(amendList))
93 newConfig.append(line)
94 continue
95 elif line.startswith("# "):
96 line = line[2:]
97 newConfig.append(line)
98 oldAmends = amendList[:]
99 amendList = []
100 for amend in oldAmends:
101 if amend not in line:
102 amendList.append(amend)
103 else:
104 newConfig.append(line)
105
106 if newConfig != configList:
107 try:
108 f = open(config, "w")
109 f.write("\n".join(newConfig))
110 f.close()
111 except IOError:
112 pass

eric ide

mercurial