Skip to content

Commit 8d41086

Browse files
committed
Merge branch 'develop'
2 parents 8ff45ed + 8743f78 commit 8d41086

13 files changed

+575
-157
lines changed

config.ini.sample

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
[General]
2-
Repo=https://rtc.mySite.com
2+
Repo=https://rtc.mySite.com/ccm
33
User=USR
44
Password=secret
55
GIT-Reponame = myGitRepo.git
66
WorkspaceName=ToBeCreatedWorkspaceName
77
# If this value is set to True, the workspace referred with workspacename will just be loaded instead of newly created
88
useExistingWorkspace = False
9-
# Folder to be created
9+
# Folder to be created - where migration will take place
1010
Directory = \temp\myWorkingDirectory
11+
# Scm command to use (lscm or scm)
12+
ScmCommand = lscm
13+
# Optional - Set encoding of files (For example encoding = UTF-8)
14+
# See https://github.com/WtfJoke/rtc2git/wiki/Encoding for further instructions
15+
encoding =
1116

1217
[Migration]
13-
# Streams to be migrated, referenced by Name or UUID, separated by ",".
14-
# This can be either multiple streams or just one stream
15-
StreamsToMigrate = Stream_Version1, Stream_Version2, HeadDevelopmentStream
18+
# Stream to be migrated, referenced by Name or UUID
19+
StreamToMigrate = MyDevelopmentStream
1620

17-
# Earliest/Oldest Stream, where the migration should start
18-
# Referenced by Name or UUID
19-
OldestStream = Stream_Version1
20-
21-
# Optional, can be defined additionally to set the workspace to a earlier specific baseline
22-
# (baseline which were created earlier than the baselines of the oldest stream)
21+
# Optional, can be defined additionally to set the workspace to a specific baseline
2322
# Use following format: ComponentName = BaseLineName, AnotherComponentName=BaseLineName
23+
# If its not set, it will determine the oldest baseline (takes some time, depending of how much components you have in your stream)
2424
InitialBaseLines =
2525

2626
# False - Rely on order of changeset provided by the rtc cli compare command (due wrong order, more likely to cause merge-conflicts
2727
# True - (Component)History needs to be provided in a separate file by the user
2828
# For more information read https://github.com/WtfJoke/rtc2git/wiki/Getting-your-History-Files
2929
UseProvidedHistory = False
3030

31+
# Determines whether to prompt the user to accept change sets together to resolve accept errors.
32+
# False - The user is prompted
33+
# True - The user is not prompted
34+
UseAutomaticConflictResolution = False
3135

3236
[Miscellaneous]
3337
# Set to true if you want to see which commands are sent to command line

configuration.py

Lines changed: 141 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import configparser
3+
import shutil
34

45
from rtcFunctions import ComponentBaseLineEntry
56
import 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

50147
class 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]

gitFunctions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ def pushbranch(branchname):
9090

9191
@staticmethod
9292
def checkout(branchname):
93+
shell.execute("git stash") # in case there are changes, stash them before checkout new branch
9394
shell.execute("git checkout " + branchname)

migration.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ def initialize(config):
1414
directory = config.workDirectory
1515
if os.path.exists(directory):
1616
sys.exit("Configured directory already exists, please make sure to use a non-existing directory")
17-
os.mkdir(directory)
17+
os.makedirs(directory)
1818
os.chdir(directory)
19+
config.deletelogfolder()
1920
git = Initializer(config)
2021
git.initalize()
2122
RTCInitializer.initialize(config)
@@ -25,7 +26,7 @@ def initialize(config):
2526
def resume(config):
2627
os.chdir(config.workDirectory)
2728
os.chdir(config.clonedGitRepoName)
28-
RTCInitializer.loginandcollectstreams(config)
29+
RTCInitializer.loginandcollectstreamuuid(config)
2930
WorkspaceHandler(config).load()
3031

3132

@@ -34,34 +35,31 @@ def migrate():
3435
rtc = ImportHandler(config)
3536
rtcworkspace = WorkspaceHandler(config)
3637
git = Commiter
37-
3838
initialize(config)
39-
streamuuids = config.streamuuids
40-
for streamuuid in streamuuids:
41-
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
42-
streamname = config.streamnames[streamuuids.index(streamuuid)]
43-
rtcworkspace.setnewflowtargets(streamuuid)
44-
git.branch(streamname)
39+
streamuuid = config.streamuuid
40+
streamname = config.streamname
41+
branchname = streamname + "_branchpoint"
4542

46-
history = rtc.readhistory(componentbaselineentries, streamname)
47-
changeentries = rtc.getchangeentriesofstreamcomponents(componentbaselineentries)
43+
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
44+
rtcworkspace.setnewflowtargets(streamuuid)
45+
git.branch(branchname)
4846

49-
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history))
50-
shouter.shout("All changes of components of stream '%s' accepted" % streamname)
51-
git.pushbranch(streamname)
47+
history = rtc.readhistory(componentbaselineentries, streamname)
48+
changeentries = rtc.getchangeentriesofstreamcomponents(componentbaselineentries)
5249

53-
rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid)
54-
rtcworkspace.load()
50+
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history))
51+
shouter.shout("All changes until creation of stream '%s' accepted" % streamname)
52+
git.pushbranch(branchname)
53+
git.branch(streamname)
5554

56-
changeentries = rtc.getchangeentriesofstream(streamuuid)
57-
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history))
58-
git.pushbranch(streamname)
59-
shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname)
55+
rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid)
56+
rtcworkspace.load()
6057

61-
morestreamstomigrate = streamuuids.index(streamuuid) + 1 is not len(streamuuids)
62-
if morestreamstomigrate:
63-
git.checkout("master")
64-
rtcworkspace.recreateoldestworkspace()
58+
changeentries = rtc.getchangeentriesofstream(streamuuid)
59+
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history))
60+
git.pushbranch(streamname)
61+
shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname)
6562

6663

67-
migrate()
64+
if __name__ == "__main__":
65+
migrate()

0 commit comments

Comments
 (0)