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