11import os
22import configparser
3+ import shutil
34
45from rtcFunctions import ComponentBaseLineEntry
56import shell
@@ -10,92 +11,180 @@ def read():
1011 config = configparser .ConfigParser ()
1112 config .read ("config.ini" )
1213 generalsection = config ['General' ]
14+ migrationsection = config ['Migration' ]
15+
1316 user = generalsection ['User' ]
1417 password = generalsection ['Password' ]
18+ repositoryurl = generalsection ['Repo' ]
19+ scmcommand = generalsection ['ScmCommand' ]
20+ shell .logcommands = config ['Miscellaneous' ]['LogShellCommands' ] == "True"
21+ shell .setencoding (generalsection ['encoding' ])
22+
1523 workspace = generalsection ['WorkspaceName' ]
24+ gitreponame = generalsection ['GIT-Reponame' ]
25+
1626 useexistingworkspace = generalsection ['useExistingWorkspace' ]
17- repositoryurl = generalsection ['Repo' ]
18- workdirectory = generalsection ['Directory' ]
27+ useprovidedhistory = migrationsection ['UseProvidedHistory' ]
28+ useautomaticconflictresolution = migrationsection ['UseAutomaticConflictResolution' ]
29+
30+ workdirectory = getworkdirectory (generalsection ['Directory' ])
31+ streamname = migrationsection ['StreamToMigrate' ].strip ()
32+ baselines = getinitialcomponentbaselines (migrationsection ['InitialBaseLines' ])
33+
34+ configbuilder = Builder ().setuser (user ).setpassword (password ).setrepourl (repositoryurl ).setscmcommand (scmcommand )
35+ configbuilder .setworkspace (workspace ).setgitreponame (gitreponame ).setrootfolder (os .getcwd ())
36+ configbuilder .setuseexistingworkspace (useexistingworkspace ).setuseprovidedhistory (useprovidedhistory )
37+ configbuilder .setuseautomaticconflictresolution (useautomaticconflictresolution )
38+ configbuilder .setworkdirectory (workdirectory ).setstreamname (streamname ).setinitialcomponentbaselines (baselines )
39+ return configbuilder .build ()
40+
41+
42+ def getworkdirectory (workdirectory ):
1943 if not workdirectory :
2044 workdirectory = "."
21- migrationsection = config [ 'Migration' ]
22- oldeststream = migrationsection [ 'OldestStream' ]
23- streamsfromconfig = migrationsection [ 'StreamsToMigrate' ]
24- streamnames = getstreamnames ( streamsfromconfig )
45+ return workdirectory
46+
47+
48+ def getinitialcomponentbaselines ( definedbaselines ):
2549 initialcomponentbaselines = []
26- definedbaselines = migrationsection ['InitialBaseLines' ]
2750 if definedbaselines :
2851 componentbaselines = definedbaselines .split ("," )
2952 for entry in componentbaselines :
3053 componentbaseline = entry .split ("=" )
3154 component = componentbaseline [0 ].strip ()
3255 baseline = componentbaseline [1 ].strip ()
3356 initialcomponentbaselines .append (ComponentBaseLineEntry (component , baseline , component , baseline ))
34- gitreponame = generalsection ['GIT-Reponame' ]
35- useprovidedhistory = migrationsection ['UseProvidedHistory' ]
36- shell .logcommands = config ['Miscellaneous' ]['LogShellCommands' ] == "True"
37- return ConfigObject (user , password , repositoryurl , workspace , useexistingworkspace , workdirectory ,
38- initialcomponentbaselines , streamnames ,
39- gitreponame , oldeststream , useprovidedhistory )
57+ return initialcomponentbaselines
58+
59+
60+ class Builder :
61+ def __init__ (self ):
62+ self .user = ""
63+ self .password = ""
64+ self .repourl = ""
65+ self .scmcommand = "lscm"
66+ self .workspace = ""
67+ self .useexistingworkspace = ""
68+ self .useprovidedhistory = ""
69+ self .useautomaticconflictresolution = ""
70+ self .workdirectory = os .path .dirname (os .path .realpath (__file__ ))
71+ self .rootFolder = self .workdirectory
72+ self .logFolder = self .rootFolder + os .sep + "Logs"
73+ self .hasCreatedLogFolder = os .path .exists (self .logFolder )
74+ self .initialcomponentbaselines = ""
75+ self .streamname = ""
76+ self .gitreponame = ""
77+ self .clonedgitreponame = ""
4078
79+ def setuser (self , user ):
80+ self .user = user
81+ return self
82+
83+ def setpassword (self , password ):
84+ self .password = password
85+ return self
4186
42- def getstreamnames (streamsfromconfig ):
43- streamnames = []
44- for streamname in streamsfromconfig .split ("," ):
45- streamname = streamname .strip ()
46- streamnames .append (streamname )
47- return streamnames
87+ def setrepourl (self , repourl ):
88+ self .repourl = repourl
89+ return self
90+
91+ def setscmcommand (self , scmcommand ):
92+ self .scmcommand = scmcommand
93+ return self
94+
95+ def setworkspace (self , workspace ):
96+ self .workspace = workspace
97+ return self
98+
99+ def setworkdirectory (self , workdirectory ):
100+ self .workdirectory = workdirectory
101+ return self
102+
103+ def setrootfolder (self , rootfolder ):
104+ self .rootFolder = rootfolder
105+ return self
106+
107+ def setlogfolder (self , logfolder ):
108+ self .logFolder = logfolder
109+ return self
110+
111+ def setinitialcomponentbaselines (self , initialcomponentbaselines ):
112+ self .initialcomponentbaselines = initialcomponentbaselines
113+ return self
114+
115+ def setstreamname (self , streamname ):
116+ self .streamname = streamname
117+ return self
118+
119+ def setgitreponame (self , reponame ):
120+ self .gitreponame = reponame
121+ self .clonedgitreponame = reponame [:- 4 ] # cut .git
122+ return self
123+
124+ def setuseexistingworkspace (self , useexistingworkspace ):
125+ self .useexistingworkspace = self .isenabled (useexistingworkspace )
126+ return self
127+
128+ def setuseprovidedhistory (self , useprovidedhistory ):
129+ self .useprovidedhistory = self .isenabled (useprovidedhistory )
130+ return self
131+
132+ def setuseautomaticconflictresolution (self , useautomaticconflictresolution ):
133+ self .useautomaticconflictresolution = self .isenabled (useautomaticconflictresolution )
134+ return self
135+
136+ @staticmethod
137+ def isenabled (stringwithbooleanexpression ):
138+ return stringwithbooleanexpression == "True"
139+
140+ def build (self ):
141+ return ConfigObject (self .user , self .password , self .repourl , self .scmcommand , self .workspace ,
142+ self .useexistingworkspace , self .workdirectory , self .initialcomponentbaselines ,
143+ self .streamname , self .gitreponame , self .useprovidedhistory ,
144+ self .useautomaticconflictresolution , self .clonedgitreponame , self .rootFolder )
48145
49146
50147class ConfigObject :
51- def __init__ (self , user , password , repo , workspace , useexistingworkspace , workdirectory , initialcomponentbaselines ,
52- streamnames ,
53- gitreponame , oldeststream , useprovidedhistory ):
148+ def __init__ (self , user , password , repourl , scmcommand , workspace , useexistingworkspace , workdirectory ,
149+ initialcomponentbaselines , streamname , gitreponame , useprovidedhistory ,
150+ useautomaticconflictresolution , clonedgitreponame , rootfolder ):
54151 self .user = user
55152 self .password = password
56- self .repo = repo
153+ self .repo = repourl
154+ self .scmcommand = scmcommand
57155 self .workspace = workspace
58- self .useexistingworkspace = useexistingworkspace == "True"
59- self .useprovidedhistory = useprovidedhistory == "True"
156+ self .useexistingworkspace = useexistingworkspace
157+ self .useprovidedhistory = useprovidedhistory
158+ self .useautomaticconflictresolution = useautomaticconflictresolution
60159 self .workDirectory = workdirectory
61160 self .initialcomponentbaselines = initialcomponentbaselines
62- self .streamnames = streamnames
63- self .earlieststreamname = oldeststream
161+ self .streamname = streamname
64162 self .gitRepoName = gitreponame
65- self .clonedGitRepoName = gitreponame [: - 4 ] # cut .git
66- self .rootFolder = os . getcwd ()
67- self .logFolder = os . getcwd () + os .sep + "Logs"
163+ self .clonedGitRepoName = clonedgitreponame
164+ self .rootFolder = rootfolder
165+ self .logFolder = rootfolder + os .sep + "Logs"
68166 self .hasCreatedLogFolder = os .path .exists (self .logFolder )
69- self .streamuuids = []
167+ self .streamuuid = ""
70168
71169 def getlogpath (self , filename ):
72170 if not self .hasCreatedLogFolder :
73171 os .makedirs (self .logFolder )
74172 self .hasCreatedLogFolder = True
75173 return self .logFolder + os .sep + filename
76174
175+ def deletelogfolder (self ):
176+ if self .hasCreatedLogFolder :
177+ shutil .rmtree (self .logFolder )
178+ self .hasCreatedLogFolder = False
179+
77180 def gethistorypath (self , filename ):
78181 historypath = self .rootFolder + os .sep + "History"
79182 return historypath + os .sep + filename
80183
81- def collectstreamuuids (self ):
82- shouter .shout ("Get UUID's of configured streamnames" )
83- for streamname in self .streamnames :
84- streamname = streamname .strip ()
85- showuuidcommand = "lscm --show-alias n --show-uuid y show attributes -r %s -w %s" % (self .repo , streamname )
86- output = shell .getoutput (showuuidcommand )
87- splittedfirstline = output [0 ].split (" " )
88- streamuuid = splittedfirstline [0 ].strip ()[1 :- 1 ]
89- self .streamuuids .append (streamuuid )
90-
91-
92-
93-
94-
95-
96-
97-
98-
99-
100-
101-
184+ def collectstreamuuid (self ):
185+ shouter .shout ("Get UUID of configured stream" )
186+ showuuidcommand = "%s --show-alias n --show-uuid y show attributes -r %s -w %s" % (
187+ self .scmcommand , self .repo , self .streamname )
188+ output = shell .getoutput (showuuidcommand )
189+ splittedfirstline = output [0 ].split (" " )
190+ self .streamuuid = splittedfirstline [0 ].strip ()[1 :- 1 ]
0 commit comments