diff --git a/config.ini.sample b/config.ini.sample index 2b56a13..0e7d139 100644 --- a/config.ini.sample +++ b/config.ini.sample @@ -2,15 +2,21 @@ Repo=https://rtc.mySite.com User=USR Password=secret -Stream=HeadDevelopmentStream GIT-Reponame = myGitRepo.git WorkspaceName=ToBeCreatedWorkspaceName ## Will be created or emptied on initialization Directory = \temp\myWorkingDirectory [Migration] -# Streams referenced by Name or UUID, separated by ",". -# They should follow the order the way you like your branches, beginning from the oldest and ending with your most current stream -Streams=Stream_Version1, Stream_Version2, HeadDevelopmentStream +# Streams to be migrated, referenced by Name or UUID, separated by ",". +# This can be either multiple streams or just one stream +StreamsToMigrate = Stream_Version1, Stream_Version2, HeadDevelopmentStream +# Earliest/Oldest Stream, where the migration should start +# Referenced by Name or UUID +OldestStream = Stream_Version1 +# Optional, can be defined additionally to set the workspace to a earlier specific baseline +# (baseline which were created earlier than the baselines of the oldest stream) +# Use following format: ComponentName = BaseLineName, AnotherComponentName=BaseLineName +InitialBaseLines = diff --git a/configuration.py b/configuration.py index 65ff013..0b98782 100644 --- a/configuration.py +++ b/configuration.py @@ -1,6 +1,7 @@ import os import configparser +from rtcFunctions import ComponentBaseLineEntry import shell import shouter @@ -13,23 +14,25 @@ def readconfig(): password = generalsection['Password'] workspace = generalsection['WorkspaceName'] repositoryurl = generalsection['Repo'] - mainstream = generalsection['Stream'] workdirectory = generalsection['Directory'] if not workdirectory: workdirectory = "." migrationsection = config['Migration'] - streamsfromconfig = migrationsection['Streams'] + oldeststream = migrationsection['OldestStream'] + streamsfromconfig = migrationsection['StreamsToMigrate'] streamnames = getstreamnames(streamsfromconfig) initialcomponentbaselines = [] - definedbaselines = "" # migrationsection['InitialBaseLine'] - # if definedbaselines: - # componentbaselines = definedbaselines.split(",") - # for entry in componentbaselines: - # componentbaseline = entry.split("=") - # component = componentbaseline[0].strip() - # baseline = componentbaseline[1].strip() + definedbaselines = migrationsection['InitialBaseLines'] + 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)) gitreponame = generalsection['GIT-Reponame'] - return ConfigObject(user, password, repositoryurl, workspace, workdirectory, mainstream, streamnames, gitreponame) + return ConfigObject(user, password, repositoryurl, workspace, workdirectory, initialcomponentbaselines, streamnames, + gitreponame, oldeststream) def getstreamnames(streamsfromconfig): @@ -41,15 +44,16 @@ def getstreamnames(streamsfromconfig): class ConfigObject: - def __init__(self, user, password, repo, workspace, workdirectory, mainstream, streamnames, gitreponame): + def __init__(self, user, password, repo, workspace, workdirectory, initialcomponentbaselines, streamnames, + gitreponame, oldeststream): self.user = user self.password = password self.repo = repo self.workspace = workspace self.workDirectory = workdirectory - self.mainStream = mainstream + self.initialcomponentbaselines = initialcomponentbaselines self.streamnames = streamnames - self.earlieststreamname = streamnames[0] + self.earlieststreamname = oldeststream self.gitRepoName = gitreponame self.clonedGitRepoName = gitreponame[:-4] # cut .git self.logFolder = os.getcwd() diff --git a/migration.py b/migration.py index 405a3d5..65d8774 100644 --- a/migration.py +++ b/migration.py @@ -45,9 +45,13 @@ def startmigration(): git.pushbranch(streamname) rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid) - rtcworkspace.reload() + rtcworkspace.load() rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstream(streamuuid)) git.pushbranch(streamname) shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname) + morestreamstomigrate = streamuuids.index(streamuuid) + 1 is not len(streamuuids) + if morestreamstomigrate: + rtcworkspace.recreateoldestworkspace() + startmigration() diff --git a/rtcFunctions.py b/rtcFunctions.py index e165469..f4ce329 100644 --- a/rtcFunctions.py +++ b/rtcFunctions.py @@ -6,8 +6,8 @@ class RTCInitializer: @staticmethod def initialize(config): - RTCInitializer.loginandcollectstreams() - WorkspaceHandler(config).createandload(config.earlieststreamname) + RTCInitializer.loginandcollectstreams(config) + WorkspaceHandler(config).createandload(config.earlieststreamname, config.initialcomponentbaselines) @staticmethod def loginandcollectstreams(config): @@ -17,18 +17,24 @@ def loginandcollectstreams(config): class WorkspaceHandler: def __init__(self, config): - self.workspacename = config.workspace + self.config = config + self.workspace = config.workspace self.repo = config.repo - def createandload(self, stream): - shell.execute("lscm create workspace -r %s -s %s %s" % (self.repo, stream, self.workspacename)) - shouter.shout("Starting initial load of workspace") - shell.execute("lscm load -r %s %s" % (self.repo, self.workspacename)) - shouter.shout("Initial load of workspace finished") - - def reload(self): - shouter.shout("Start reloading/replacing current workspace") - shell.execute("lscm load -r %s %s --force" % (self.repo, self.workspacename)) + def createandload(self, stream, componentbaselineentries=[], create=True): + if create: + shell.execute("lscm create workspace -r %s -s %s %s" % (self.config.repo, stream, self.workspace)) + if componentbaselineentries: + self.setcomponentstobaseline(componentbaselineentries, stream) + else: + self.setcomponentstobaseline(ImportHandler(self.config).getcomponentbaselineentriesfromstream(stream), + stream) + self.load() + + def load(self): + shouter.shout("Start (re)loading current workspace") + shell.execute("lscm load -r %s %s --force" % (self.repo, self.workspace)) + shouter.shout("Load of workspace finished") def setcomponentstobaseline(self, componentbaselineentries, streamuuid): self.setnewflowtargets(streamuuid) @@ -36,7 +42,7 @@ def setcomponentstobaseline(self, componentbaselineentries, streamuuid): shouter.shout("Set component '%s' to baseline '%s'" % (entry.componentname, entry.baselinename)) replacecommand = "lscm set component -r %s -b %s %s stream %s %s --overwrite-uncommitted" % \ - (self.repo, entry.baseline, self.workspacename, streamuuid, entry.component) + (self.repo, entry.baseline, self.workspace, streamuuid, entry.component) shell.execute(replacecommand) def setnewflowtargets(self, streamuuid): @@ -52,7 +58,10 @@ def removedefaultflowtarget(self): % (self.repo, self.workspace))[0] flowtargetnametoremove = flowtargetline.split("\"")[1] shell.execute("lscm remove flowtarget -r %s %s %s" - % (self.repo, self.workspace.workspace, flowtargetnametoremove)) + % (self.repo, self.workspace, flowtargetnametoremove)) + + def recreateoldestworkspace(self): + self.createandload(self.config.earlieststreamname, self.config.initialcomponentbaselines, False) class ImportHandler: