Skip to content

Commit

Permalink
merge 'migratestreambystream', resolves #6 closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
WtfJoke committed Feb 23, 2015
2 parents c2958bc + 5778021 commit 2495903
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
14 changes: 10 additions & 4 deletions config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
30 changes: 17 additions & 13 deletions configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import configparser

from rtcFunctions import ComponentBaseLineEntry
import shell
import shouter

Expand All @@ -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):
Expand All @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
37 changes: 23 additions & 14 deletions rtcFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -17,26 +17,32 @@ 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)
for entry in componentbaselineentries:
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):
Expand All @@ -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:
Expand Down

0 comments on commit 2495903

Please sign in to comment.