Skip to content

Commit 744f0d2

Browse files
committed
Merge branch 'develop'
2 parents 9714fc8 + b08a4e6 commit 744f0d2

File tree

6 files changed

+153
-91
lines changed

6 files changed

+153
-91
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# rtc2git
2-
A tool made for migrating code from an existing RTC SCM repository into a Git repository
3-
It uses the CLI of RTC to gather the required informations
2+
A tool made for migrating code from an existing [RTC] (https://jazz.net/products/rational-team-concert/) SCM repository into a Git repository
3+
It uses the CLI of RTC to gather the required informations (You can find the CLI under the name "SCM Tools" [here] (https://jazz.net/downloads/rational-team-concert/releases/5.0.1?p=allDownloads))
44

55
## Prerequirements
66
<ul>
77
<li> RTC Version 5.0+ (Was tested using 5.0.1) </li>
8-
<li> Working RTC CLI aka "SCM Tools" --> (e.g Command "lscm help" should work in console) </li>
8+
<li> RTC CLI --> (e.g Command "lscm help" should work in console) </li>
99
<li> Python 3 </li>
1010
</ul>
1111

@@ -26,3 +26,6 @@ It uses the CLI of RTC to gather the required informations
2626
<li>The corresponding git command will be executed to do the same change in the git-repository</li>
2727
</ol>
2828

29+
30+
## Wiki
31+
For more details [visit our wiki] (https://github.com/WtfJoke/rtc2git/wiki)

config.ini.sample

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
Repo=https://rtc.mySite.com
33
User=USR
44
Password=secret
5-
Stream=HeadDevelopmentStream
65
GIT-Reponame = myGitRepo.git
76
WorkspaceName=ToBeCreatedWorkspaceName
87
## Will be created or emptied on initialization
98
Directory = \temp\myWorkingDirectory
109

1110
[Migration]
12-
# Streams referenced by Name or UUID, separated by ",".
13-
# They should follow the order the way you like your branches, beginning from the oldest and ending with your most current stream
14-
Streams=Stream_Version1, Stream_Version2, HeadDevelopmentStream
11+
# Streams to be migrated, referenced by Name or UUID, separated by ",".
12+
# This can be either multiple streams or just one stream
13+
StreamsToMigrate = Stream_Version1, Stream_Version2, HeadDevelopmentStream
1514

15+
# Earliest/Oldest Stream, where the migration should start
16+
# Referenced by Name or UUID
17+
OldestStream = Stream_Version1
1618

19+
# Optional, can be defined additionally to set the workspace to a earlier specific baseline
20+
# (baseline which were created earlier than the baselines of the oldest stream)
21+
# Use following format: ComponentName = BaseLineName, AnotherComponentName=BaseLineName
22+
InitialBaseLines =

configuration.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import configparser
33

4+
from rtcFunctions import ComponentBaseLineEntry
45
import shell
56
import shouter
67

@@ -13,23 +14,25 @@ def readconfig():
1314
password = generalsection['Password']
1415
workspace = generalsection['WorkspaceName']
1516
repositoryurl = generalsection['Repo']
16-
mainstream = generalsection['Stream']
1717
workdirectory = generalsection['Directory']
1818
if not workdirectory:
1919
workdirectory = "."
2020
migrationsection = config['Migration']
21-
streamsfromconfig = migrationsection['Streams']
21+
oldeststream = migrationsection['OldestStream']
22+
streamsfromconfig = migrationsection['StreamsToMigrate']
2223
streamnames = getstreamnames(streamsfromconfig)
2324
initialcomponentbaselines = []
24-
definedbaselines = "" # migrationsection['InitialBaseLine']
25-
# if definedbaselines:
26-
# componentbaselines = definedbaselines.split(",")
27-
# for entry in componentbaselines:
28-
# componentbaseline = entry.split("=")
29-
# component = componentbaseline[0].strip()
30-
# baseline = componentbaseline[1].strip()
25+
definedbaselines = migrationsection['InitialBaseLines']
26+
if definedbaselines:
27+
componentbaselines = definedbaselines.split(",")
28+
for entry in componentbaselines:
29+
componentbaseline = entry.split("=")
30+
component = componentbaseline[0].strip()
31+
baseline = componentbaseline[1].strip()
32+
initialcomponentbaselines.append(ComponentBaseLineEntry(component, baseline, component, baseline))
3133
gitreponame = generalsection['GIT-Reponame']
32-
return ConfigObject(user, password, repositoryurl, workspace, workdirectory, mainstream, streamnames, gitreponame)
34+
return ConfigObject(user, password, repositoryurl, workspace, workdirectory, initialcomponentbaselines, streamnames,
35+
gitreponame, oldeststream)
3336

3437

3538
def getstreamnames(streamsfromconfig):
@@ -41,22 +44,27 @@ def getstreamnames(streamsfromconfig):
4144

4245

4346
class ConfigObject:
44-
def __init__(self, user, password, repo, workspace, workdirectory, mainstream, streamnames, gitreponame):
47+
def __init__(self, user, password, repo, workspace, workdirectory, initialcomponentbaselines, streamnames,
48+
gitreponame, oldeststream):
4549
self.user = user
4650
self.password = password
4751
self.repo = repo
4852
self.workspace = workspace
4953
self.workDirectory = workdirectory
50-
self.mainStream = mainstream
54+
self.initialcomponentbaselines = initialcomponentbaselines
5155
self.streamnames = streamnames
52-
self.earlieststreamname = streamnames[0]
56+
self.earlieststreamname = oldeststream
5357
self.gitRepoName = gitreponame
5458
self.clonedGitRepoName = gitreponame[:-4] # cut .git
55-
self.logFolder = os.getcwd()
59+
self.logFolder = os.getcwd() + os.sep + "Logs"
60+
self.hasCreatedLogFolder = os.path.exists(self.logFolder)
5661
self.streamuuids = []
5762

5863
def getlogpath(self, filename):
59-
return "%s\%s" % (self.logFolder, filename)
64+
if not self.hasCreatedLogFolder:
65+
os.makedirs(self.logFolder)
66+
self.hasCreatedLogFolder = True
67+
return self.logFolder + os.sep + filename
6068

6169
def collectstreamuuids(self):
6270
shouter.shout("Get UUID's of configured streamnames")

gitFunctions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Commiter:
4343
@staticmethod
4444
def addandcommit(changeentry):
4545
comment = Commiter.replacegitcreatingfilesymbol(changeentry.comment)
46+
Commiter.replaceauthor(changeentry.author, changeentry.email)
4647
shell.execute("git add -A")
4748
shell.execute("git commit -m %s --date %s --author=%s"
4849
% (shell.quote(comment), shell.quote(changeentry.date), changeentry.getgitauthor()))
@@ -64,6 +65,11 @@ def replacewords(replacedwith, word, *replacingstrings):
6465
word = word.replace(replacingstring, replacedwith)
6566
return word
6667

68+
@staticmethod
69+
def replaceauthor(author, email):
70+
shell.execute("git config --replace-all user.name " + shell.quote(author))
71+
shell.execute("git config --replace-all user.email " + email)
72+
6773
@staticmethod
6874
def branch(branchname):
6975
branchexist = shell.execute("git show-ref --verify --quiet refs/heads/" + branchname)

migration.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,56 @@
22
import shutil
33

44
from rtcFunctions import ImportHandler
5+
from rtcFunctions import WorkspaceHandler
6+
from rtcFunctions import RTCInitializer
57
from gitFunctions import Initializer
68
from gitFunctions import Commiter
79
import configuration
810
import shouter
911

1012

11-
def initialize(directory):
13+
def initialize(config):
14+
directory = config.workDirectory
1215
if os.path.exists(directory):
1316
shutil.rmtree(directory)
1417
os.mkdir(directory)
1518
os.chdir(directory)
16-
gitInitializer.initalize()
17-
rtc.initialize()
18-
gitInitializer.initialcommitandpush()
19+
git = Initializer(config)
20+
git.initalize()
21+
RTCInitializer.initialize(config)
22+
git.initialcommitandpush()
1923

2024

21-
def resume(directory):
22-
os.chdir(directory)
23-
os.chdir(gitInitializer.clonedRepoName)
24-
rtc.loginandcollectstreams()
25+
def resume(config):
26+
os.chdir(config.workDirectory)
27+
os.chdir(config.clonedGitRepoName)
28+
RTCInitializer.loginandcollectstreams(config)
2529

2630

2731
def startmigration():
28-
initialize(config.workDirectory)
32+
config = configuration.readconfig()
33+
rtc = ImportHandler(config)
34+
rtcworkspace = WorkspaceHandler(config)
35+
git = Commiter
36+
37+
initialize(config)
2938
streamuuids = config.streamuuids
3039
for streamuuid in streamuuids:
3140
streamname = config.streamnames[streamuuids.index(streamuuid)]
3241
git.branch(streamname)
3342
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
34-
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstream(componentbaselineentries))
35-
shouter.shout("All changes of stream '%s' accepted" % streamname)
43+
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstreamcomponents(componentbaselineentries))
44+
shouter.shout("All changes of components of stream '%s' accepted" % streamname)
45+
git.pushbranch(streamname)
46+
47+
rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid)
48+
rtcworkspace.load()
49+
rtc.acceptchangesintoworkspace(rtc.getchangeentriesofstream(streamuuid))
3650
git.pushbranch(streamname)
37-
rtc.recreateworkspace(streamuuid)
38-
rtc.resetcomponentstobaseline(componentbaselineentries, streamuuid)
39-
rtc.reloadworkspace()
51+
shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname)
4052

53+
morestreamstomigrate = streamuuids.index(streamuuid) + 1 is not len(streamuuids)
54+
if morestreamstomigrate:
55+
rtcworkspace.recreateoldestworkspace()
4156

42-
config = configuration.readconfig()
43-
rtc = ImportHandler(config)
44-
gitInitializer = Initializer(config)
45-
git = Commiter()
4657
startmigration()

0 commit comments

Comments
 (0)