Skip to content

Commit 457aa8b

Browse files
committed
Merge branch 'develop'
2 parents 744f0d2 + ba47f4f commit 457aa8b

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

config.ini.sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ User=USR
44
Password=secret
55
GIT-Reponame = myGitRepo.git
66
WorkspaceName=ToBeCreatedWorkspaceName
7-
## Will be created or emptied on initialization
7+
# If this value is set to True, the workspace referred with workspacename will just be loaded instead of newly created
8+
useExistingWorkspace = False
9+
# Folder to be created
810
Directory = \temp\myWorkingDirectory
911

1012
[Migration]

configuration.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import shouter
77

88

9-
def readconfig():
9+
def read():
1010
config = configparser.ConfigParser()
1111
config.read("config.ini")
1212
generalsection = config['General']
1313
user = generalsection['User']
1414
password = generalsection['Password']
1515
workspace = generalsection['WorkspaceName']
16+
useexistingworkspace = generalsection['useExistingWorkspace']
1617
repositoryurl = generalsection['Repo']
1718
workdirectory = generalsection['Directory']
1819
if not workdirectory:
@@ -31,7 +32,8 @@ def readconfig():
3132
baseline = componentbaseline[1].strip()
3233
initialcomponentbaselines.append(ComponentBaseLineEntry(component, baseline, component, baseline))
3334
gitreponame = generalsection['GIT-Reponame']
34-
return ConfigObject(user, password, repositoryurl, workspace, workdirectory, initialcomponentbaselines, streamnames,
35+
return ConfigObject(user, password, repositoryurl, workspace, useexistingworkspace, workdirectory,
36+
initialcomponentbaselines, streamnames,
3537
gitreponame, oldeststream)
3638

3739

@@ -44,12 +46,14 @@ def getstreamnames(streamsfromconfig):
4446

4547

4648
class ConfigObject:
47-
def __init__(self, user, password, repo, workspace, workdirectory, initialcomponentbaselines, streamnames,
49+
def __init__(self, user, password, repo, workspace, useexistingworkspace, workdirectory, initialcomponentbaselines,
50+
streamnames,
4851
gitreponame, oldeststream):
4952
self.user = user
5053
self.password = password
5154
self.repo = repo
5255
self.workspace = workspace
56+
self.useexistingworkspace = useexistingworkspace is "True"
5357
self.workDirectory = workdirectory
5458
self.initialcomponentbaselines = initialcomponentbaselines
5559
self.streamnames = streamnames

gitFunctions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def addandcommit(changeentry):
5252
shouter.shout("30 Commits happend, push current branch to avoid out of memory")
5353
Commiter.pushbranch("")
5454
Commiter.commitcounter = 0
55+
shouter.shout("Commited change in local git repository")
5556

5657

5758
@staticmethod
@@ -74,7 +75,7 @@ def replaceauthor(author, email):
7475
def branch(branchname):
7576
branchexist = shell.execute("git show-ref --verify --quiet refs/heads/" + branchname)
7677
if branchexist is 0:
77-
shell.execute("git checkout " + branchname)
78+
Commiter.checkout("git checkout " + branchname)
7879
else:
7980
shell.execute("git checkout -b " + branchname)
8081

@@ -83,3 +84,7 @@ def pushbranch(branchname):
8384
if branchname:
8485
shouter.shout("Final push of branch " + branchname)
8586
shell.execute("git push origin " + branchname)
87+
88+
@staticmethod
89+
def checkout(branchname):
90+
shell.execute("git checkout " + branchname)

migration.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
import shutil
2+
import sys
33

44
from rtcFunctions import ImportHandler
55
from rtcFunctions import WorkspaceHandler
@@ -13,7 +13,7 @@
1313
def initialize(config):
1414
directory = config.workDirectory
1515
if os.path.exists(directory):
16-
shutil.rmtree(directory)
16+
sys.exit("Configured directory already exists, please make sure to use a non-existing directory")
1717
os.mkdir(directory)
1818
os.chdir(directory)
1919
git = Initializer(config)
@@ -26,32 +26,38 @@ def resume(config):
2626
os.chdir(config.workDirectory)
2727
os.chdir(config.clonedGitRepoName)
2828
RTCInitializer.loginandcollectstreams(config)
29+
WorkspaceHandler(config).load()
2930

3031

31-
def startmigration():
32-
config = configuration.readconfig()
32+
def migrate():
33+
config = configuration.read()
3334
rtc = ImportHandler(config)
3435
rtcworkspace = WorkspaceHandler(config)
3536
git = Commiter
3637

3738
initialize(config)
3839
streamuuids = config.streamuuids
3940
for streamuuid in streamuuids:
41+
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
4042
streamname = config.streamnames[streamuuids.index(streamuuid)]
43+
rtcworkspace.setnewflowtargets(streamuuid)
44+
4145
git.branch(streamname)
42-
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
4346
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstreamcomponents(componentbaselineentries))
4447
shouter.shout("All changes of components of stream '%s' accepted" % streamname)
4548
git.pushbranch(streamname)
4649

4750
rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid)
4851
rtcworkspace.load()
52+
4953
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstream(streamuuid))
5054
git.pushbranch(streamname)
5155
shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname)
5256

5357
morestreamstomigrate = streamuuids.index(streamuuid) + 1 is not len(streamuuids)
5458
if morestreamstomigrate:
59+
git.checkout("master")
5560
rtcworkspace.recreateoldestworkspace()
5661

57-
startmigration()
62+
63+
migrate()

rtcFunctions.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ class RTCInitializer:
99
@staticmethod
1010
def initialize(config):
1111
RTCInitializer.loginandcollectstreams(config)
12-
WorkspaceHandler(config).createandload(config.earlieststreamname, config.initialcomponentbaselines)
12+
workspace = WorkspaceHandler(config)
13+
if config.useexistingworkspace:
14+
shouter.shout("Use existing workspace to start migration")
15+
workspace.load()
16+
else:
17+
workspace.createandload(config.earlieststreamname, config.initialcomponentbaselines)
1318

1419
@staticmethod
1520
def loginandcollectstreams(config):
@@ -39,7 +44,6 @@ def load(self):
3944
shouter.shout("Load of workspace finished")
4045

4146
def setcomponentstobaseline(self, componentbaselineentries, streamuuid):
42-
self.setnewflowtargets(streamuuid)
4347
for entry in componentbaselineentries:
4448
shouter.shout("Set component '%s' to baseline '%s'" % (entry.componentname, entry.baselinename))
4549

@@ -48,19 +52,23 @@ def setcomponentstobaseline(self, componentbaselineentries, streamuuid):
4852
shell.execute(replacecommand)
4953

5054
def setnewflowtargets(self, streamuuid):
51-
shouter.shout("Replacing Flowtargets")
52-
self.removedefaultflowtarget()
53-
shell.execute("lscm add flowtarget -r %s %s %s"
54-
% (self.repo, self.workspace, streamuuid))
55+
shouter.shout("Set new Flowtargets")
56+
if not self.hasflowtarget(streamuuid):
57+
shell.execute("lscm add flowtarget -r %s %s %s"
58+
% (self.repo, self.workspace, streamuuid))
5559
shell.execute("lscm set flowtarget -r %s %s --default --current %s"
5660
% (self.repo, self.workspace, streamuuid))
5761

58-
def removedefaultflowtarget(self):
59-
flowtargetline = shell.getoutput("lscm --show-alias n list flowtargets -r %s %s"
60-
% (self.repo, self.workspace))[0]
61-
flowtargetnametoremove = flowtargetline.split("\"")[1]
62-
shell.execute("lscm remove flowtarget -r %s %s %s"
63-
% (self.repo, self.workspace, flowtargetnametoremove))
62+
def hasflowtarget(self, streamuuid):
63+
flowtargetlines = shell.getoutput("lscm --show-uuid y --show-alias n list flowtargets -r %s %s"
64+
% (self.repo, self.workspace))
65+
for flowtargetline in flowtargetlines:
66+
splittedinformationline = flowtargetline.split("\"")
67+
uuidpart = splittedinformationline[0].split(" ")
68+
flowtargetuuid = uuidpart[0].strip()[1:-1]
69+
if streamuuid in flowtargetuuid:
70+
return True
71+
return False
6472

6573
def recreateoldestworkspace(self):
6674
self.createandload(self.config.earlieststreamname, self.config.initialcomponentbaselines, False)
@@ -121,12 +129,12 @@ def acceptchangesintoworkspace(self, changeentries):
121129
acceptcommand = "lscm accept --changes " + revision + " --overwrite-uncommitted"
122130
acceptedsuccesfully = shell.execute(acceptcommand, self.config.getlogpath("accept.txt"), "a") is 0
123131
if not acceptedsuccesfully:
132+
shouter.shout("Last executed command: " + acceptcommand)
124133
sys.exit("Change wasnt succesfully accepted into workspace, please check the output and "
125134
"rerun programm with resume")
135+
shouter.shout("Accepted change %s/%s into working directory" % (amountofacceptedchanges, amountofchanges))
126136
git.addandcommit(changeEntry)
127137

128-
shouter.shout("Accepted change %s/%s" % (amountofacceptedchanges, amountofchanges))
129-
130138
def getchangeentriesofstreamcomponents(self, componentbaselineentries):
131139
shouter.shout("Start collecting changeentries")
132140
changeentries = []
@@ -168,6 +176,7 @@ def getchangeentriesbytypeandvalue(self, comparetype, value):
168176
shell.execute(comparecommand, outputfilename)
169177
return ImportHandler.getchangeentriesfromfile(outputfilename)
170178

179+
171180
class ChangeEntry:
172181
def __init__(self, revision, author, email, date, comment):
173182
self.revision = revision

0 commit comments

Comments
 (0)