Plugins/VcsPlugins/vcsPySvn/SvnUtilities.py

changeset 1880
dbd4d7698310
parent 1509
c0b5e693b0eb
child 1889
6de0f43f6678
equal deleted inserted replaced
1879:194a055fff04 1880:dbd4d7698310
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QDateTime, Qt 12 from PyQt4.QtCore import QDateTime, Qt
13 13
14 import Utilities 14 import Utilities
15
16 from .Config import DefaultConfig, DefaultIgnores
15 17
16 18
17 def formatTime(seconds): 19 def formatTime(seconds):
18 """ 20 """
19 Module function to return a formatted time string. 21 Module function to return a formatted time string.
36 return QDateTime.fromTime_t(int(seconds)).toTimeSpec(Qt.LocalTime).date() 38 return QDateTime.fromTime_t(int(seconds)).toTimeSpec(Qt.LocalTime).date()
37 39
38 40
39 def getServersPath(): 41 def getServersPath():
40 """ 42 """
41 Public method to get the filename of the servers file. 43 Module function to get the filename of the servers file.
42 44
43 @return filename of the servers file (string) 45 @return filename of the servers file (string)
44 """ 46 """
45 if Utilities.isWindowsPlatform(): 47 if Utilities.isWindowsPlatform():
46 appdata = os.environ["APPDATA"] 48 appdata = os.environ["APPDATA"]
50 return os.path.join(homedir, ".subversion", "servers") 52 return os.path.join(homedir, ".subversion", "servers")
51 53
52 54
53 def getConfigPath(): 55 def getConfigPath():
54 """ 56 """
55 Public method to get the filename of the config file. 57 Module function to get the filename of the config file.
56 58
57 @return filename of the config file (string) 59 @return filename of the config file (string)
58 """ 60 """
59 if Utilities.isWindowsPlatform(): 61 if Utilities.isWindowsPlatform():
60 appdata = os.environ["APPDATA"] 62 appdata = os.environ["APPDATA"]
61 return os.path.join(appdata, "Subversion", "config") 63 return os.path.join(appdata, "Subversion", "config")
62 else: 64 else:
63 homedir = Utilities.getHomeDir() 65 homedir = Utilities.getHomeDir()
64 return os.path.join(homedir, ".subversion", "config") 66 return os.path.join(homedir, ".subversion", "config")
67
68
69 def createDefaultConfig():
70 """
71 Module function to create a default config file suitable for eric.
72 """
73 config = getConfigPath()
74 try:
75 os.makedirs(os.path.dirname(config))
76 except OSError:
77 pass
78 try:
79 f = open(config, "w")
80 f.write(DefaultConfig)
81 f.close()
82 except IOError:
83 pass
84
85
86 def amendConfig():
87 """
88 Module function to amend the config file.
89 """
90 config = getConfigPath()
91 try:
92 f = open(config, "r")
93 configList = f.read().splitlines()
94 f.close()
95 except IOError:
96 return
97
98 newConfig = []
99 ignoresFound = False
100 amendList = []
101 for line in configList:
102 if line.find("global-ignores") in [0, 2]:
103 ignoresFound = True
104 if line.startswith("# "):
105 line = line[2:]
106 newConfig.append(line)
107 for amend in DefaultIgnores:
108 if amend not in line:
109 amendList.append(amend)
110 elif ignoresFound:
111 if line.startswith("##"):
112 ignoresFound = False
113 if amendList:
114 newConfig.append(" " + " ".join(amendList))
115 newConfig.append(line)
116 continue
117 elif line.startswith("# "):
118 line = line[2:]
119 newConfig.append(line)
120 oldAmends = amendList[:]
121 amendList = []
122 for amend in oldAmends:
123 if amend not in line:
124 amendList.append(amend)
125 else:
126 newConfig.append(line)
127
128 if newConfig != configList:
129 try:
130 f = open(config, "w")
131 f.write(os.linesep.join(newConfig))
132 f.close()
133 except IOError:
134 pass

eric ide

mercurial