forked from rtcTo/rtc2git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.py
333 lines (274 loc) · 12.5 KB
/
configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import configparser
import os
import shlex
import shutil
import shell
import shouter
config = None
configfile = None
user = None
password = None
stored = None
def read(configname=None):
if not configname:
global configfile
configname = configfile
parsedconfig = configparser.ConfigParser()
if len(parsedconfig.read(configname)) < 1:
raise IOError('unable to read %s' % configname)
generalsection = parsedconfig['General']
migrationsectionname = 'Migration'
migrationsection = parsedconfig[migrationsectionname]
miscsectionname = 'Miscellaneous'
global user
if not user and not stored:
user = generalsection['User']
global password
if not password and not stored:
password = generalsection['Password']
repositoryurl = generalsection['Repo']
scmcommand = generalsection.get('ScmCommand', "lscm")
shell.logcommands = parsedconfig.get(miscsectionname, 'LogShellCommands', fallback="False") == "True"
shell.setencoding(generalsection.get('encoding'))
rtcversion = generalsection.get('RTCVersion', "5");
workspace = shlex.quote(generalsection['WorkspaceName'])
gitreponame = generalsection['GIT-Reponame']
useexistingworkspace = generalsection.get('useExistingWorkspace', "False")
useprovidedhistory = migrationsection.get('UseProvidedHistory', "False")
useautomaticconflictresolution = migrationsection.get('UseAutomaticConflictResolution', "False")
maxchangesetstoaccepttogether = migrationsection.get('MaxChangeSetsToAcceptTogether', "10")
workdirectory = generalsection.get('Directory', os.getcwd())
streamname = shlex.quote(migrationsection['StreamToMigrate'].strip())
previousstreamname = migrationsection.get('PreviousStream', '').strip()
baselines = getinitialcomponentbaselines(migrationsection.get('InitialBaseLines'))
ignorefileextensionsproperty = parsedconfig.get(miscsectionname, 'IgnoreFileExtensions', fallback='')
ignorefileextensions = parsesplittedproperty(ignorefileextensionsproperty)
ignoredirectoriessproperty = parsedconfig.get(miscsectionname, 'IgnoreDirectories', fallback='')
ignoredirectories = parsesplittedproperty(ignoredirectoriessproperty)
includecomponentroots = parsedconfig.get(miscsectionname, 'IncludeComponentRoots', fallback="False")
commitmessageprefix = migrationsection.get('CommitMessageWorkItemPrefix', "")
gitattributesproperty = parsedconfig.get(migrationsectionname, 'Gitattributes', fallback='')
gitattributes = parsesplittedproperty(gitattributesproperty)
configbuilder = Builder().setuser(user).setpassword(password).setstored(stored).setrepourl(repositoryurl)
configbuilder.setscmcommand(scmcommand).setrtcversion(rtcversion)
configbuilder.setworkspace(workspace).setgitreponame(gitreponame).setrootfolder(os.getcwd())
configbuilder.setuseexistingworkspace(useexistingworkspace).setuseprovidedhistory(useprovidedhistory)
configbuilder.setuseautomaticconflictresolution(useautomaticconflictresolution)
configbuilder.setmaxchangesetstoaccepttogether(maxchangesetstoaccepttogether)
configbuilder.setworkdirectory(workdirectory).setstreamname(streamname).setinitialcomponentbaselines(baselines)
configbuilder.setpreviousstreamname(previousstreamname)
configbuilder.setignorefileextensions(ignorefileextensions)
configbuilder.setignoredirectories(ignoredirectories)
configbuilder.setincludecomponentroots(includecomponentroots).setcommitmessageprefix(commitmessageprefix)
configbuilder.setgitattributes(gitattributes)
global config
config = configbuilder.build()
return config
def get():
if not config:
read()
return config
def setconfigfile(newconfigfile):
global configfile
configfile = newconfigfile
def setUser(newuser):
global user
user = newuser
def setPassword(newpassword):
global password
password = newpassword
def setStored(newstored):
global stored
stored = newstored
def getinitialcomponentbaselines(definedbaselines):
initialcomponentbaselines = []
if definedbaselines:
componentbaselines = definedbaselines.split(",")
for entry in componentbaselines:
componentbaseline = entry.split("=")
component = componentbaseline[0].strip()
baseline = componentbaseline[1].strip()
initialcomponentbaselines.append(ComponentBaseLineEntry(component, baseline, component, baseline))
return initialcomponentbaselines
def parsesplittedproperty(property, separator=';'):
"""
:param property
:return: a list single properties, possibly empty
"""
properties = []
if property and len(property) > 0:
for splittedproperty in property.split(separator):
properties.append(splittedproperty.strip())
return properties
class Builder:
def __init__(self):
self.user = ""
self.password = ""
self.stored = False
self.repourl = ""
self.scmcommand = "lscm"
self.rtcversion = ""
self.workspace = ""
self.useexistingworkspace = ""
self.useprovidedhistory = ""
self.useautomaticconflictresolution = ""
self.maxchangesetstoaccepttogether = ""
self.workdirectory = os.path.dirname(os.path.realpath(__file__))
self.rootFolder = self.workdirectory
self.logFolder = self.rootFolder + os.sep + "Logs"
self.hasCreatedLogFolder = os.path.exists(self.logFolder)
self.initialcomponentbaselines = ""
self.streamname = ""
self.gitreponame = ""
self.clonedgitreponame = ""
self.previousstreamname = ""
self.ignorefileextensions = ""
self.ignoredirectories = ""
self.includecomponentroots = ""
self.commitmessageprefix = ""
self.gitattributes = ""
def setuser(self, user):
self.user = user
return self
def setpassword(self, password):
self.password = password
return self
def setstored(self, stored):
self.stored = stored
return self
def setrepourl(self, repourl):
self.repourl = repourl
return self
def setscmcommand(self, scmcommand):
self.scmcommand = scmcommand
return self
def setrtcversion(self, scmversion):
self.rtcversion = int(scmversion)
return self
def setworkspace(self, workspace):
self.workspace = workspace
return self
def setworkdirectory(self, workdirectory):
self.workdirectory = workdirectory
return self
def setrootfolder(self, rootfolder):
self.rootFolder = rootfolder
return self
def setlogfolder(self, logfolder):
self.logFolder = logfolder
return self
def setinitialcomponentbaselines(self, initialcomponentbaselines):
self.initialcomponentbaselines = initialcomponentbaselines
return self
def setstreamname(self, streamname):
self.streamname = streamname
return self
def setgitreponame(self, reponame):
self.gitreponame = reponame
self.clonedgitreponame = reponame[:-4] # cut .git
return self
def setuseexistingworkspace(self, useexistingworkspace):
self.useexistingworkspace = self.isenabled(useexistingworkspace)
return self
def setuseprovidedhistory(self, useprovidedhistory):
self.useprovidedhistory = self.isenabled(useprovidedhistory)
return self
def setuseautomaticconflictresolution(self, useautomaticconflictresolution):
self.useautomaticconflictresolution = self.isenabled(useautomaticconflictresolution)
return self
def setmaxchangesetstoaccepttogether(self, maxchangesetstoaccepttogether):
self.maxchangesetstoaccepttogether = int(maxchangesetstoaccepttogether)
return self
def setpreviousstreamname(self, previousstreamname):
self.previousstreamname = previousstreamname
return self
def setignorefileextensions(self, ignorefileextensions):
self.ignorefileextensions = ignorefileextensions
return self
def setignoredirectories(self, ignoreirectories):
self.ignoredirectories = ignoreirectories
return self
def setincludecomponentroots(self, includecomponentroots):
self.includecomponentroots = self.isenabled(includecomponentroots)
return self
def setcommitmessageprefix(self, commitmessageprefix):
self.commitmessageprefix = commitmessageprefix
return self
def setgitattributes(self, gitattributes):
self.gitattributes = gitattributes
return self
@staticmethod
def isenabled(stringwithbooleanexpression):
return stringwithbooleanexpression == "True"
def build(self):
return ConfigObject(self.user, self.password, self.stored, self.repourl, self.scmcommand, self.rtcversion,
self.workspace,
self.useexistingworkspace, self.workdirectory, self.initialcomponentbaselines,
self.streamname, self.gitreponame, self.useprovidedhistory,
self.useautomaticconflictresolution, self.maxchangesetstoaccepttogether, self.clonedgitreponame, self.rootFolder,
self.previousstreamname, self.ignorefileextensions, self.ignoredirectories, self.includecomponentroots,
self.commitmessageprefix, self.gitattributes)
class ConfigObject:
def __init__(self, user, password, stored, repourl, scmcommand, rtcversion, workspace, useexistingworkspace,
workdirectory,
initialcomponentbaselines, streamname, gitreponame, useprovidedhistory,
useautomaticconflictresolution, maxchangesetstoaccepttogether, clonedgitreponame, rootfolder, previousstreamname,
ignorefileextensions, ignoredirectories, includecomponentroots, commitmessageprefix, gitattributes):
self.user = user
self.password = password
self.stored = stored
self.repo = repourl
self.scmcommand = scmcommand
self.rtcversion = rtcversion
self.workspace = workspace
self.useexistingworkspace = useexistingworkspace
self.useprovidedhistory = useprovidedhistory
self.useautomaticconflictresolution = useautomaticconflictresolution
self.maxchangesetstoaccepttogether = maxchangesetstoaccepttogether
self.workDirectory = workdirectory
self.initialcomponentbaselines = initialcomponentbaselines
self.streamname = streamname
self.gitRepoName = gitreponame
self.clonedGitRepoName = clonedgitreponame
self.rootFolder = rootfolder
self.logFolder = rootfolder + os.sep + "Logs"
self.hasCreatedLogFolder = os.path.exists(self.logFolder)
self.streamuuid = ""
self.previousstreamname = previousstreamname
self.previousstreamuuid = ""
self.ignorefileextensions = ignorefileextensions
self.ignoredirectories = ignoredirectories
self.includecomponentroots = includecomponentroots
self.commitmessageprefix = commitmessageprefix
self.gitattributes = gitattributes
def getlogpath(self, filename):
if not self.hasCreatedLogFolder:
os.makedirs(self.logFolder)
self.hasCreatedLogFolder = True
return self.logFolder + os.sep + filename
def deletelogfolder(self):
if self.hasCreatedLogFolder:
shutil.rmtree(self.logFolder)
self.hasCreatedLogFolder = False
def gethistorypath(self, filename):
historypath = self.rootFolder + os.sep + "History"
return historypath + os.sep + filename
def collectstreamuuid(self, streamname):
if not streamname:
return
shouter.shout("Get UUID of configured stream " + streamname)
showuuidcommand = "%s --show-alias n --show-uuid y show attributes -r %s -w %s" % (
self.scmcommand, self.repo, streamname)
output = shell.getoutput(showuuidcommand)
splittedfirstline = output[0].split(" ")
streamuuid = splittedfirstline[0].strip()[1:-1]
return streamuuid
def collectstreamuuids(self):
self.streamuuid = self.collectstreamuuid(self.streamname)
self.previousstreamuuid = self.collectstreamuuid(self.previousstreamname)
class ComponentBaseLineEntry:
def __init__(self, component, baseline, componentname, baselinename):
self.component = component
self.baseline = baseline
self.componentname = componentname
self.baselinename = baselinename