Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ config.ini
Compare_*.txt
StreamComponents_*.txt
accept*.txt
History_B*.txt
History_B*.txt
__pycache__
*.swp
*.pyc
4 changes: 0 additions & 4 deletions History/History_SampleComponent.txt

This file was deleted.

8 changes: 1 addition & 7 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def read():
componentbaseline = entry.split("=")
component = componentbaseline[0].strip()
baseline = componentbaseline[1].strip()
initialcomponentbaselines.append(ComponentBaseLineEntry(component, baseline, component, baseline,
oldeststream))
initialcomponentbaselines.append(ComponentBaseLineEntry(component, baseline, component, baseline))
gitreponame = generalsection['GIT-Reponame']
return ConfigObject(user, password, repositoryurl, workspace, useexistingworkspace, workdirectory,
initialcomponentbaselines, streamnames,
Expand Down Expand Up @@ -61,7 +60,6 @@ def __init__(self, user, password, repo, workspace, useexistingworkspace, workdi
self.earlieststreamname = oldeststream
self.gitRepoName = gitreponame
self.clonedGitRepoName = gitreponame[:-4] # cut .git
self.rootFolder = os.getcwd()
self.logFolder = os.getcwd() + os.sep + "Logs"
self.hasCreatedLogFolder = os.path.exists(self.logFolder)
self.streamuuids = []
Expand All @@ -72,10 +70,6 @@ def getlogpath(self, filename):
self.hasCreatedLogFolder = True
return self.logFolder + os.sep + filename

def gethistorypath(self, filename):
historypath = self.rootFolder + os.sep + "History"
return historypath + os.sep + filename

def collectstreamuuids(self):
shouter.shout("Get UUID's of configured streamnames")
for streamname in self.streamnames:
Expand Down
10 changes: 3 additions & 7 deletions migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,16 @@ def migrate():
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
streamname = config.streamnames[streamuuids.index(streamuuid)]
rtcworkspace.setnewflowtargets(streamuuid)
git.branch(streamname)

history = rtc.readhistory(componentbaselineentries)
changeentries = rtc.getchangeentriesofstreamcomponents(componentbaselineentries)

rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(history, changeentries))
git.branch(streamname)
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstreamcomponents(componentbaselineentries))
shouter.shout("All changes of components of stream '%s' accepted" % streamname)
git.pushbranch(streamname)

rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid)
rtcworkspace.load()

changeentries = rtc.getchangeentriesofstream(streamuuid)
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(history, changeentries))
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstream(streamuuid))
git.pushbranch(streamname)
shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname)

Expand Down
145 changes: 45 additions & 100 deletions rtcFunctions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import os

import sorter
import shell
Expand Down Expand Up @@ -32,7 +31,9 @@ def __init__(self, config):

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))
command = "lscm create workspace -r %s -s %s %s" % (self.config.repo, stream, self.workspace)
shouter.shout(command)
shell.execute(command)
if componentbaselineentries:
self.setcomponentstobaseline(componentbaselineentries, stream)
else:
Expand All @@ -41,8 +42,10 @@ def createandload(self, stream, componentbaselineentries=[], create=True):
self.load()

def load(self):
shouter.shout("Start (re)loading current workspace")
shell.execute("lscm load -r %s %s --force" % (self.repo, self.workspace))
command = "lscm load -r %s %s --force" % (self.repo, self.workspace)
shouter.shout("Start (re)loading current workspace: " + command)
shell.execute(command)
input("Press Enter to continue...")
shouter.shout("Load of workspace finished")

def setcomponentstobaseline(self, componentbaselineentries, streamuuid):
Expand All @@ -51,19 +54,24 @@ def setcomponentstobaseline(self, componentbaselineentries, streamuuid):

replacecommand = "lscm set component -r %s -b %s %s stream %s %s --overwrite-uncommitted" % \
(self.repo, entry.baseline, self.workspace, streamuuid, entry.component)
shouter.shout(replacecommand)
shell.execute(replacecommand)

def setnewflowtargets(self, streamuuid):
shouter.shout("Set new Flowtargets")
if not self.hasflowtarget(streamuuid):
shell.execute("lscm add flowtarget -r %s %s %s"
% (self.repo, self.workspace, streamuuid))
shell.execute("lscm set flowtarget -r %s %s --default --current %s"
% (self.repo, self.workspace, streamuuid))
command = "lscm add flowtarget -r %s %s %s" % (self.repo, self.workspace, streamuuid)
shouter.shout(command)
shell.execute(command)

command = "lscm set flowtarget -r %s %s --default --current %s" % (self.repo, self.workspace, streamuuid)
shouter.shout(command)
shell.execute(command)

def hasflowtarget(self, streamuuid):
flowtargetlines = shell.getoutput("lscm --show-uuid y --show-alias n list flowtargets -r %s %s"
% (self.repo, self.workspace))
command = "lscm --show-uuid y --show-alias n list flowtargets -r %s %s" % (self.repo, self.workspace)
shouter.shout(command)
flowtargetlines = shell.getoutput(command)
for flowtargetline in flowtargetlines:
splittedinformationline = flowtargetline.split("\"")
uuidpart = splittedinformationline[0].split(" ")
Expand All @@ -82,8 +90,9 @@ def __init__(self, config):

def getcomponentbaselineentriesfromstream(self, stream):
filename = self.config.getlogpath("StreamComponents_" + stream + ".txt")
shell.execute(
"lscm --show-alias n --show-uuid y list components -v -r " + self.config.repo + " " + stream, filename)
command = "lscm --show-alias n --show-uuid y list components -v -r " + self.config.repo + " " + stream
shouter.shout(command)
shell.execute(command, filename)
componentbaselinesentries = []
skippedfirstrow = False
islinewithcomponent = 2
Expand All @@ -109,7 +118,7 @@ def getcomponentbaselineentriesfromstream(self, stream):

if baseline and component:
componentbaselinesentries.append(
ComponentBaseLineEntry(component, baseline, componentname, baselinename, stream))
ComponentBaseLineEntry(component, baseline, componentname, baselinename))
baseline = ""
component = ""
componentname = ""
Expand All @@ -121,85 +130,38 @@ def acceptchangesintoworkspace(self, changeentries):
git = Commiter
amountofchanges = len(changeentries)
shouter.shoutwithdate("Start accepting %s changesets" % amountofchanges)
reloaded = 0
amountofacceptedchanges = 0
skipnextchangeset = False
for changeEntry in changeentries:
amountofacceptedchanges += 1
if skipnextchangeset:
skipnextchangeset = False
continue
revision = changeEntry.revision
acceptingmsg = "Accepting: " + changeEntry.comment + " (Date: " + changeEntry.date + ", Author: " \
+ changeEntry.author + ", Revision: " + revision + ")"
shouter.shout(acceptingmsg)
acceptcommand = "lscm accept --overwrite-uncommitted --changes " + revision
acceptedsuccesfully = shell.execute(acceptcommand, self.config.getlogpath("accept.txt"), "a") is 0
if not acceptedsuccesfully:
self.retryacceptincludingnextchangeset(changeEntry, changeentries, acceptcommand)
skipnextchangeset = True
acceptcommand = "lscm accept -v -r %s -t %s --overwrite-uncommitted --changes %s" % (self.config.repo, self.config.workspace, revision)
shouter.shout(acceptcommand)
rc = shell.execute(acceptcommand, self.config.getlogpath("accept.txt"), "a")
if rc is 0:
shouter.shout("Accepted change %s/%s into working directory" % (amountofacceptedchanges, amountofchanges))
if reloaded is 0:
command = "lscm load -r %s %s --force" % (self.config.repo, self.config.workspace)
shouter.shout("Reloading workspace after first accept: " + command)
shell.execute(command)
reloaded = 1
else:
shouter.shout("Last executed command exited with "+str(rc)+": " + acceptcommand)
input("Press Enter to continue (or quit and re-run the program with resume)")

shouter.shout("Accepted change %s/%s into working directory" % (amountofacceptedchanges, amountofchanges))
git.addandcommit(changeEntry)

def retryacceptincludingnextchangeset(self, changeentry, changeentries, acceptcommand):
shouter.shout("Change wasnt succesfully accepted into workspace, trying to discard last change")
self.discardchanges(changeentry.revision)
nextindex = changeentries.index(changeentry) + 1
successfull = False
if nextindex is not len(changeentries):
nextchangeentry = changeentries[nextindex]
if changeentry.author == nextchangeentry.author: # most likely merge changeset
shouter.shout("Trying to accept next changeset (might be a solved merge-conflict)")
acceptcommand += " " + nextchangeentry.revision
successfull = shell.execute(acceptcommand, self.config.getlogpath("accept.txt"), "a") is 0
if not successfull:
self.discardchanges(changeentry, nextchangeentry)

if not successfull:
shouter.shout("Last executed command: " + acceptcommand)
sys.exit("Change wasnt succesfully accepted into workspace, please check the output and "
"rerun programm with resume")

@staticmethod
def discardchanges(*changeentries):
idstodiscard = ""
for changeentry in changeentries:
idstodiscard += " " + changeentry.revision
shell.execute("lscm discard --overwrite-uncommitted " + idstodiscard)

def getchangeentriesofstreamcomponents(self, componentbaselineentries):
shouter.shout("Start comparing current workspace with baselines")
missingchangeentries = {}

shouter.shout("Start collecting changeentries")
changeentriesbycomponentbaselineentry = {}
for componentBaseLineEntry in componentbaselineentries:
changeentries = self.getchangeentriesofbaseline(componentBaseLineEntry.baseline)
for changeentry in changeentries:
missingchangeentries[changeentry.revision] = changeentry
return missingchangeentries

def readhistory(self, componentbaselineentries):
historyuuids = {}
shouter.shout("Start reading history files")
for componentBaseLineEntry in componentbaselineentries:
history = self.gethistory(componentBaseLineEntry.component, componentBaseLineEntry.componentname,
componentBaseLineEntry.stream)
historyuuids[componentBaseLineEntry.component] = history
return historyuuids

@staticmethod
def getchangeentriestoaccept(history, missingchangeentries):
historywithchangeentryobject = {}
for key in history.keys():
currentuuids = history.get(key)
changeentries = []
for uuid in currentuuids:
changeentry = missingchangeentries.get(uuid)
if changeentry:
changeentries.append(changeentry)
historywithchangeentryobject[key] = changeentries
changeentriestoaccept = sorter.tosortedlist(historywithchangeentryobject)
return changeentriestoaccept

changeentriesbycomponentbaselineentry[componentBaseLineEntry.componentname] = \
self.getchangeentriesofbaseline(componentBaseLineEntry.baseline)
changeentries = sorter.tosortedlist(changeentriesbycomponentbaselineentry)
return changeentries

@staticmethod
def getchangeentriesfromfile(outputfilename):
Expand All @@ -218,21 +180,8 @@ def getchangeentriesfromfile(outputfilename):
comment = splittedlines[3].strip()
date = splittedlines[4].strip()
changeentries.append(ChangeEntry(revision, author, email, date, comment))
return changeentries

@staticmethod
def getsimplehistoryfromfile(outputfilename):
revisions = []
if not os.path.isfile(outputfilename):
shouter.shout("History file not found: " + outputfilename)
shouter.shout("Skipping this part of history")
return revisions

with open(outputfilename, 'r') as file:
for line in file:
revisions.append(line.strip())
revisions.reverse() # to begin by the oldest
return revisions
return changeentries

def getchangeentriesofbaseline(self, baselinetocompare):
return self.getchangeentriesbytypeandvalue("baseline", baselinetocompare)
Expand All @@ -246,13 +195,10 @@ def getchangeentriesbytypeandvalue(self, comparetype, value):
outputfilename = self.config.getlogpath("Compare_" + comparetype + "_" + value + ".txt")
comparecommand = "lscm --show-alias n --show-uuid y compare ws %s %s %s -r %s -I sw -C @@{name}@@{email}@@ --flow-directions i -D @@\"%s\"@@" \
% (self.config.workspace, comparetype, value, self.config.repo, dateformat)
shouter.shout(comparecommand + " --> " + outputfilename)
shell.execute(comparecommand, outputfilename)
return ImportHandler.getchangeentriesfromfile(outputfilename)

def gethistory(self, componentuuid, componentname, streamuuid):
outputfilename = self.config.gethistorypath("History_" + componentname + ".txt")
return ImportHandler.getsimplehistoryfromfile(outputfilename)


class ChangeEntry:
def __init__(self, revision, author, email, date, comment):
Expand All @@ -268,9 +214,8 @@ def getgitauthor(self):


class ComponentBaseLineEntry:
def __init__(self, component, baseline, componentname, baselinename, streamuuid):
def __init__(self, component, baseline, componentname, baselinename):
self.component = component
self.baseline = baseline
self.componentname = componentname
self.baselinename = baselinename
self.stream = streamuuid