diff --git a/config.ini.minimum.sample b/config.ini.minimum.sample index 4a2ff4c..ab48f29 100644 --- a/config.ini.minimum.sample +++ b/config.ini.minimum.sample @@ -4,6 +4,7 @@ User=USR Password=secret GIT-Reponame = myGitRepo.git WorkspaceName=ToBeCreatedWorkspaceName +SVNRepoDir = SVNemptyRepoDirectory [Migration] # Stream to be migrated, referenced by Name or UUID diff --git a/config.ini.sample b/config.ini.sample index a19409a..5018139 100644 --- a/config.ini.sample +++ b/config.ini.sample @@ -13,6 +13,8 @@ ScmCommand = lscm # Optional - Set encoding of files (For example encoding = UTF-8) # See "https://github.com/rtcTo/rtc2git/wiki/Encoding" for further instructions encoding = +# Optional - Set empty SVN repo directory if you want to commit also on a SVN repo +SVNRepoDir = [Migration] # Stream to be migrated, referenced by Name or UUID diff --git a/configuration.py b/configuration.py index 4db6290..e4c4469 100644 --- a/configuration.py +++ b/configuration.py @@ -36,6 +36,7 @@ def read(configname=None): workspace = shlex.quote(generalsection['WorkspaceName']) gitreponame = generalsection['GIT-Reponame'] + svnrepodir = shlex.quote(generalsection['SVNRepoDir']) useexistingworkspace = generalsection.get('useExistingWorkspace', "False") useprovidedhistory = migrationsection.get('UseProvidedHistory', "False") @@ -66,6 +67,7 @@ def read(configname=None): configbuilder.setignoredirectories(ignoredirectories) configbuilder.setincludecomponentroots(includecomponentroots).setcommitmessageprefix(commitmessageprefix) configbuilder.setgitattributes(gitattributes) + configbuilder.setsvnrepodir(svnrepodir) global config config = configbuilder.build() return config @@ -141,6 +143,7 @@ def __init__(self): self.includecomponentroots = "" self.commitmessageprefix = "" self.gitattributes = "" + self.svnrepodir = "" def setuser(self, user): self.user = user @@ -162,6 +165,10 @@ def setworkspace(self, workspace): self.workspace = workspace return self + def setsvnrepodir(self, svnrepodir): + self.svnrepodir = svnrepodir + return self + def setworkdirectory(self, workdirectory): self.workdirectory = workdirectory return self @@ -237,14 +244,15 @@ def build(self): self.streamname, self.gitreponame, self.useprovidedhistory, self.useautomaticconflictresolution, self.maxchangesetstoaccepttogether, self.clonedgitreponame, self.rootFolder, self.previousstreamname, self.ignorefileextensions, self.ignoredirectories, self.includecomponentroots, - self.commitmessageprefix, self.gitattributes) + self.commitmessageprefix, self.gitattributes, self.svnrepodir) class ConfigObject: def __init__(self, user, password, repourl, scmcommand, workspace, useexistingworkspace, workdirectory, initialcomponentbaselines, streamname, gitreponame, useprovidedhistory, useautomaticconflictresolution, maxchangesetstoaccepttogether, clonedgitreponame, rootfolder, previousstreamname, - ignorefileextensions, ignoredirectories, includecomponentroots, commitmessageprefix, gitattributes): + ignorefileextensions, ignoredirectories, includecomponentroots, commitmessageprefix, gitattributes, + svnrepodir): self.user = user self.password = password self.repo = repourl @@ -270,6 +278,7 @@ def __init__(self, user, password, repourl, scmcommand, workspace, useexistingwo self.includecomponentroots = includecomponentroots self.commitmessageprefix = commitmessageprefix self.gitattributes = gitattributes + self.svnrepodir = svnrepodir def getlogpath(self, filename): if not self.hasCreatedLogFolder: diff --git a/rtcFunctions.py b/rtcFunctions.py index 0c0ab84..fc8d085 100644 --- a/rtcFunctions.py +++ b/rtcFunctions.py @@ -9,7 +9,7 @@ import sorter from configuration import ComponentBaseLineEntry from gitFunctions import Commiter, Differ - +from svnFunctions import svnCommiter class RTCInitializer: @staticmethod @@ -229,6 +229,9 @@ def acceptchangesintoworkspace(self, changeentries): self.is_user_aborting(changeentries) shouter.shout("Accepted change %d/%d into working directory" % (amountofacceptedchanges, amountofchanges)) Commiter.addandcommit(changeEntry) + # SVN support + if self.config.svnrepodir: + svnCommiter.addandcommit(changeEntry) return amountofacceptedchanges @staticmethod diff --git a/svnFunctions.py b/svnFunctions.py new file mode 100644 index 0000000..7fe06b5 --- /dev/null +++ b/svnFunctions.py @@ -0,0 +1,38 @@ +import os +import configuration +import shouter +import shell +from gitFunctions import Commiter + +class svnCommiter: + + @staticmethod + def getcommitcommand(changeentry, comment): + msg = (comment, "[RTC commit", changeentry.date, "by", changeentry.getgitauthor() + "]") + return "svn commit -m %s" % (shell.quote(" ".join(msg))) + + @staticmethod + def addandcommit(changeentry): + config = configuration.get() + if config.svnrepodir: + shouter.shout("[SVN] current dir=%s svndir=%s" % (os.getcwd(), config.svnrepodir)) + # 1 - rsync current git dir to svn dir + gitrepodir = os.getcwd() + cmd = "rsync -r %s %s" % ( + os.path.join(gitrepodir, config.component2load, "*"), + config.svnrepodir) + shouter.shout("[SVN] %s" % cmd) + shell.execute(cmd) + # 2 - chdir to svnrepo, add and commit + os.chdir(config.svnrepodir) + cmd = "svn add --force * --auto-props --parents --depth infinity -q" + shouter.shout("[SVN] %s" % cmd) + shell.execute(cmd) + comment = Commiter.getcommentwithprefix(changeentry.comment) + cmd = svnCommiter.getcommitcommand(changeentry, comment) + shouter.shout("[SVN] %s" % cmd) + shell.execute(cmd) + shell.execute("svn update") + # 3 - go back to current dir + os.chdir(gitrepodir) + diff --git a/tests/resources/test_config.ini b/tests/resources/test_config.ini index 2627793..8a5ae36 100644 --- a/tests/resources/test_config.ini +++ b/tests/resources/test_config.ini @@ -8,6 +8,7 @@ Directory = /tmp/migration useExistingWorkspace = True ScmCommand = scm encoding = UTF-8 +SVNRepoDir = [Migration] StreamToMigrate = Superstream diff --git a/tests/resources/test_minimum_config.ini b/tests/resources/test_minimum_config.ini index 5fb5817..5ff6c47 100644 --- a/tests/resources/test_minimum_config.ini +++ b/tests/resources/test_minimum_config.ini @@ -4,6 +4,7 @@ User = miniuser Password = minisecret GIT-Reponame = mini.git WorkspaceName = Miniworkspace +SVNRepoDir = [Migration] StreamToMigrate = Ministream