Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
WtfJoke committed Jun 14, 2015
2 parents 8ff45ed + 8743f78 commit 8d41086
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 157 deletions.
26 changes: 15 additions & 11 deletions config.ini.sample
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
[General]
Repo=https://rtc.mySite.com
Repo=https://rtc.mySite.com/ccm
User=USR
Password=secret
GIT-Reponame = myGitRepo.git
WorkspaceName=ToBeCreatedWorkspaceName
# If this value is set to True, the workspace referred with workspacename will just be loaded instead of newly created
useExistingWorkspace = False
# Folder to be created
# Folder to be created - where migration will take place
Directory = \temp\myWorkingDirectory
# Scm command to use (lscm or scm)
ScmCommand = lscm
# Optional - Set encoding of files (For example encoding = UTF-8)
# See https://github.com/WtfJoke/rtc2git/wiki/Encoding for further instructions
encoding =

[Migration]
# 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
# Stream to be migrated, referenced by Name or UUID
StreamToMigrate = MyDevelopmentStream

# 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)
# Optional, can be defined additionally to set the workspace to a specific baseline
# Use following format: ComponentName = BaseLineName, AnotherComponentName=BaseLineName
# If its not set, it will determine the oldest baseline (takes some time, depending of how much components you have in your stream)
InitialBaseLines =

# False - Rely on order of changeset provided by the rtc cli compare command (due wrong order, more likely to cause merge-conflicts
# True - (Component)History needs to be provided in a separate file by the user
# For more information read https://github.com/WtfJoke/rtc2git/wiki/Getting-your-History-Files
UseProvidedHistory = False

# Determines whether to prompt the user to accept change sets together to resolve accept errors.
# False - The user is prompted
# True - The user is not prompted
UseAutomaticConflictResolution = False

[Miscellaneous]
# Set to true if you want to see which commands are sent to command line
Expand Down
193 changes: 141 additions & 52 deletions configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import configparser
import shutil

from rtcFunctions import ComponentBaseLineEntry
import shell
Expand All @@ -10,92 +11,180 @@ def read():
config = configparser.ConfigParser()
config.read("config.ini")
generalsection = config['General']
migrationsection = config['Migration']

user = generalsection['User']
password = generalsection['Password']
repositoryurl = generalsection['Repo']
scmcommand = generalsection['ScmCommand']
shell.logcommands = config['Miscellaneous']['LogShellCommands'] == "True"
shell.setencoding(generalsection['encoding'])

workspace = generalsection['WorkspaceName']
gitreponame = generalsection['GIT-Reponame']

useexistingworkspace = generalsection['useExistingWorkspace']
repositoryurl = generalsection['Repo']
workdirectory = generalsection['Directory']
useprovidedhistory = migrationsection['UseProvidedHistory']
useautomaticconflictresolution = migrationsection['UseAutomaticConflictResolution']

workdirectory = getworkdirectory(generalsection['Directory'])
streamname = migrationsection['StreamToMigrate'].strip()
baselines = getinitialcomponentbaselines(migrationsection['InitialBaseLines'])

configbuilder = Builder().setuser(user).setpassword(password).setrepourl(repositoryurl).setscmcommand(scmcommand)
configbuilder.setworkspace(workspace).setgitreponame(gitreponame).setrootfolder(os.getcwd())
configbuilder.setuseexistingworkspace(useexistingworkspace).setuseprovidedhistory(useprovidedhistory)
configbuilder.setuseautomaticconflictresolution(useautomaticconflictresolution)
configbuilder.setworkdirectory(workdirectory).setstreamname(streamname).setinitialcomponentbaselines(baselines)
return configbuilder.build()


def getworkdirectory(workdirectory):
if not workdirectory:
workdirectory = "."
migrationsection = config['Migration']
oldeststream = migrationsection['OldestStream']
streamsfromconfig = migrationsection['StreamsToMigrate']
streamnames = getstreamnames(streamsfromconfig)
return workdirectory


def getinitialcomponentbaselines(definedbaselines):
initialcomponentbaselines = []
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']
useprovidedhistory = migrationsection['UseProvidedHistory']
shell.logcommands = config['Miscellaneous']['LogShellCommands'] == "True"
return ConfigObject(user, password, repositoryurl, workspace, useexistingworkspace, workdirectory,
initialcomponentbaselines, streamnames,
gitreponame, oldeststream, useprovidedhistory)
return initialcomponentbaselines


class Builder:
def __init__(self):
self.user = ""
self.password = ""
self.repourl = ""
self.scmcommand = "lscm"
self.workspace = ""
self.useexistingworkspace = ""
self.useprovidedhistory = ""
self.useautomaticconflictresolution = ""
self.workdirectory = os.path.dirname(os.path.realpath(__file__))
self.rootFolder = self.workdirectory
self.logFolder = self.rootFolder + os.sep + "Logs"
self.hasCreatedLogFolder = os.path.exists(self.logFolder)
self.initialcomponentbaselines = ""
self.streamname = ""
self.gitreponame = ""
self.clonedgitreponame = ""

def setuser(self, user):
self.user = user
return self

def setpassword(self, password):
self.password = password
return self

def getstreamnames(streamsfromconfig):
streamnames = []
for streamname in streamsfromconfig.split(","):
streamname = streamname.strip()
streamnames.append(streamname)
return streamnames
def setrepourl(self, repourl):
self.repourl = repourl
return self

def setscmcommand(self, scmcommand):
self.scmcommand = scmcommand
return self

def setworkspace(self, workspace):
self.workspace = workspace
return self

def setworkdirectory(self, workdirectory):
self.workdirectory = workdirectory
return self

def setrootfolder(self, rootfolder):
self.rootFolder = rootfolder
return self

def setlogfolder(self, logfolder):
self.logFolder = logfolder
return self

def setinitialcomponentbaselines(self, initialcomponentbaselines):
self.initialcomponentbaselines = initialcomponentbaselines
return self

def setstreamname(self, streamname):
self.streamname = streamname
return self

def setgitreponame(self, reponame):
self.gitreponame = reponame
self.clonedgitreponame = reponame[:-4] # cut .git
return self

def setuseexistingworkspace(self, useexistingworkspace):
self.useexistingworkspace = self.isenabled(useexistingworkspace)
return self

def setuseprovidedhistory(self, useprovidedhistory):
self.useprovidedhistory = self.isenabled(useprovidedhistory)
return self

def setuseautomaticconflictresolution(self, useautomaticconflictresolution):
self.useautomaticconflictresolution = self.isenabled(useautomaticconflictresolution)
return self

@staticmethod
def isenabled(stringwithbooleanexpression):
return stringwithbooleanexpression == "True"

def build(self):
return ConfigObject(self.user, self.password, self.repourl, self.scmcommand, self.workspace,
self.useexistingworkspace, self.workdirectory, self.initialcomponentbaselines,
self.streamname, self.gitreponame, self.useprovidedhistory,
self.useautomaticconflictresolution, self.clonedgitreponame, self.rootFolder)


class ConfigObject:
def __init__(self, user, password, repo, workspace, useexistingworkspace, workdirectory, initialcomponentbaselines,
streamnames,
gitreponame, oldeststream, useprovidedhistory):
def __init__(self, user, password, repourl, scmcommand, workspace, useexistingworkspace, workdirectory,
initialcomponentbaselines, streamname, gitreponame, useprovidedhistory,
useautomaticconflictresolution, clonedgitreponame, rootfolder):
self.user = user
self.password = password
self.repo = repo
self.repo = repourl
self.scmcommand = scmcommand
self.workspace = workspace
self.useexistingworkspace = useexistingworkspace == "True"
self.useprovidedhistory = useprovidedhistory == "True"
self.useexistingworkspace = useexistingworkspace
self.useprovidedhistory = useprovidedhistory
self.useautomaticconflictresolution = useautomaticconflictresolution
self.workDirectory = workdirectory
self.initialcomponentbaselines = initialcomponentbaselines
self.streamnames = streamnames
self.earlieststreamname = oldeststream
self.streamname = streamname
self.gitRepoName = gitreponame
self.clonedGitRepoName = gitreponame[:-4] # cut .git
self.rootFolder = os.getcwd()
self.logFolder = os.getcwd() + os.sep + "Logs"
self.clonedGitRepoName = clonedgitreponame
self.rootFolder = rootfolder
self.logFolder = rootfolder + os.sep + "Logs"
self.hasCreatedLogFolder = os.path.exists(self.logFolder)
self.streamuuids = []
self.streamuuid = ""

def getlogpath(self, filename):
if not self.hasCreatedLogFolder:
os.makedirs(self.logFolder)
self.hasCreatedLogFolder = True
return self.logFolder + os.sep + filename

def deletelogfolder(self):
if self.hasCreatedLogFolder:
shutil.rmtree(self.logFolder)
self.hasCreatedLogFolder = False

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:
streamname = streamname.strip()
showuuidcommand = "lscm --show-alias n --show-uuid y show attributes -r %s -w %s" % (self.repo, streamname)
output = shell.getoutput(showuuidcommand)
splittedfirstline = output[0].split(" ")
streamuuid = splittedfirstline[0].strip()[1:-1]
self.streamuuids.append(streamuuid)












def collectstreamuuid(self):
shouter.shout("Get UUID of configured stream")
showuuidcommand = "%s --show-alias n --show-uuid y show attributes -r %s -w %s" % (
self.scmcommand, self.repo, self.streamname)
output = shell.getoutput(showuuidcommand)
splittedfirstline = output[0].split(" ")
self.streamuuid = splittedfirstline[0].strip()[1:-1]
1 change: 1 addition & 0 deletions gitFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ def pushbranch(branchname):

@staticmethod
def checkout(branchname):
shell.execute("git stash") # in case there are changes, stash them before checkout new branch
shell.execute("git checkout " + branchname)
48 changes: 23 additions & 25 deletions migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def initialize(config):
directory = config.workDirectory
if os.path.exists(directory):
sys.exit("Configured directory already exists, please make sure to use a non-existing directory")
os.mkdir(directory)
os.makedirs(directory)
os.chdir(directory)
config.deletelogfolder()
git = Initializer(config)
git.initalize()
RTCInitializer.initialize(config)
Expand All @@ -25,7 +26,7 @@ def initialize(config):
def resume(config):
os.chdir(config.workDirectory)
os.chdir(config.clonedGitRepoName)
RTCInitializer.loginandcollectstreams(config)
RTCInitializer.loginandcollectstreamuuid(config)
WorkspaceHandler(config).load()


Expand All @@ -34,34 +35,31 @@ def migrate():
rtc = ImportHandler(config)
rtcworkspace = WorkspaceHandler(config)
git = Commiter

initialize(config)
streamuuids = config.streamuuids
for streamuuid in streamuuids:
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
streamname = config.streamnames[streamuuids.index(streamuuid)]
rtcworkspace.setnewflowtargets(streamuuid)
git.branch(streamname)
streamuuid = config.streamuuid
streamname = config.streamname
branchname = streamname + "_branchpoint"

history = rtc.readhistory(componentbaselineentries, streamname)
changeentries = rtc.getchangeentriesofstreamcomponents(componentbaselineentries)
componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid)
rtcworkspace.setnewflowtargets(streamuuid)
git.branch(branchname)

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

rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid)
rtcworkspace.load()
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history))
shouter.shout("All changes until creation of stream '%s' accepted" % streamname)
git.pushbranch(branchname)
git.branch(streamname)

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

morestreamstomigrate = streamuuids.index(streamuuid) + 1 is not len(streamuuids)
if morestreamstomigrate:
git.checkout("master")
rtcworkspace.recreateoldestworkspace()
changeentries = rtc.getchangeentriesofstream(streamuuid)
rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history))
git.pushbranch(streamname)
shouter.shout("All changes of stream '%s' accepted - Migration of stream completed" % streamname)


migrate()
if __name__ == "__main__":
migrate()
Loading

0 comments on commit 8d41086

Please sign in to comment.