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
6 changes: 5 additions & 1 deletion config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ LogShellCommands = False
# Define a semicolon-separated list of extensions to be generally ignored
# Example:
# IgnoreFileExtensions = .zip; .jar; .exe; .dll
IgnoreFileExtensions =
IgnoreFileExtensions =

# Set to true if you want to include component root directories when loading the workspace
# (this will add the -i / --include-root option to the (l)scm load command)
IncludeComponentRoots = False
12 changes: 10 additions & 2 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def read(configname=None):
baselines = getinitialcomponentbaselines(migrationsection.get('InitialBaseLines'))
ignorefileextensionsproperty = parsedconfig.get(miscsectionname, 'IgnoreFileExtensions', fallback='')
ignorefileextensions = parseignorefileextensionsproperty(ignorefileextensionsproperty)
includecomponentroots = parsedconfig.get(miscsectionname, 'IncludeComponentRoots', fallback="False")

configbuilder = Builder().setuser(user).setpassword(password).setrepourl(repositoryurl).setscmcommand(scmcommand)
configbuilder.setworkspace(workspace).setgitreponame(gitreponame).setrootfolder(os.getcwd())
Expand All @@ -47,6 +48,7 @@ def read(configname=None):
configbuilder.setworkdirectory(workdirectory).setstreamname(streamname).setinitialcomponentbaselines(baselines)
configbuilder.setpreviousstreamname(previousstreamname)
configbuilder.setignorefileextensions(ignorefileextensions)
configbuilder.setincludecomponentroots(includecomponentroots)
global config
config = configbuilder.build()
return config
Expand Down Expand Up @@ -108,6 +110,7 @@ def __init__(self):
self.clonedgitreponame = ""
self.previousstreamname = ""
self.ignorefileextensions = ""
self.includecomponentroots = ""

def setuser(self, user):
self.user = user
Expand Down Expand Up @@ -174,6 +177,10 @@ def setignorefileextensions(self, ignorefileextensions):
self.ignorefileextensions = ignorefileextensions
return self

def setincludecomponentroots(self, includecomponentroots):
self.includecomponentroots = self.isenabled(includecomponentroots)
return self

@staticmethod
def isenabled(stringwithbooleanexpression):
return stringwithbooleanexpression == "True"
Expand All @@ -183,14 +190,14 @@ def build(self):
self.useexistingworkspace, self.workdirectory, self.initialcomponentbaselines,
self.streamname, self.gitreponame, self.useprovidedhistory,
self.useautomaticconflictresolution, self.clonedgitreponame, self.rootFolder,
self.previousstreamname, self.ignorefileextensions)
self.previousstreamname, self.ignorefileextensions, self.includecomponentroots)


class ConfigObject:
def __init__(self, user, password, repourl, scmcommand, workspace, useexistingworkspace, workdirectory,
initialcomponentbaselines, streamname, gitreponame, useprovidedhistory,
useautomaticconflictresolution, clonedgitreponame, rootfolder, previousstreamname,
ignorefileextensionsproperty):
ignorefileextensionsproperty, includecomponentroots):
self.user = user
self.password = password
self.repo = repourl
Expand All @@ -211,6 +218,7 @@ def __init__(self, user, password, repourl, scmcommand, workspace, useexistingwo
self.previousstreamname = previousstreamname
self.previousstreamuuid = ""
self.ignorefileextensions = ignorefileextensionsproperty
self.includecomponentroots = includecomponentroots

def getlogpath(self, filename):
if not self.hasCreatedLogFolder:
Expand Down
2 changes: 2 additions & 0 deletions rtcFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def createandload(self, stream, componentbaselineentries=[]):

def load(self):
command = "%s load -r %s %s --force" % (self.scmcommand, self.repo, self.workspace)
if self.config.includecomponentroots:
command += " --include-root"
shouter.shout("Start (re)loading current workspace: " + command)
shell.execute(command)
shouter.shout("Load of workspace finished")
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/test_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GIT-Reponame = super.git
WorkspaceName=Superworkspace
Directory = /tmp/migration
useExistingWorkspace = True
ScmCommand = lscm
ScmCommand = scm
encoding = UTF-8

[Migration]
Expand All @@ -19,3 +19,4 @@ UseAutomaticConflictResolution = True
[Miscellaneous]
LogShellCommands = True
IgnoreFileExtensions = .zip; .jar
IncludeComponentRoots = True
12 changes: 6 additions & 6 deletions tests/resources/test_minimum_config.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[General]
Repo = https://rtc.supercompany.com/ccm/
User = anyuser
Password = supersecret
GIT-Reponame = super.git
WorkspaceName = Superworkspace
Repo = https://rtc.minicompany.com/ccm/
User = miniuser
Password = minisecret
GIT-Reponame = mini.git
WorkspaceName = Miniworkspace

[Migration]
StreamToMigrate = Superstream
StreamToMigrate = Ministream
36 changes: 31 additions & 5 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class ConfigurationTestCase(unittest.TestCase):

def setUp(self):
self.workdirectory = os.path.dirname(os.path.realpath(__file__))
# reset global shell variables
shell.logcommands = False
shell.encoding = None

def test_DeletionOfFolder(self):
config = Builder().setworkdirectory(self.workdirectory).build()
Expand Down Expand Up @@ -60,17 +63,17 @@ def test_fileExtensionsToBeIgnored_MultipleExtensions(self):
self.assertEqual(['.zip', '.jar', '.exe'], config.ignorefileextensions)

def test_read_passedin_configfile(self):
self._assertConfig(configuration.read('resources/test_config.ini'))
self._assertTestConfig(configuration.read('resources/test_config.ini'))

def test_read_configfile_from_configuration(self):
configuration.setconfigfile('resources/test_config.ini')
self._assertConfig(configuration.read())
self._assertTestConfig(configuration.read())

def test_read_minimumconfigfile_shouldrelyonfallbackvalues(self):
configuration.setconfigfile('resources/test_minimum_config.ini')
configuration.read()
self._assertDefaultConfig(configuration.read())

def _assertConfig(self, config):
def _assertTestConfig(self, config):
# [General]
self.assertEqual('https://rtc.supercompany.com/ccm/', config.repo)
self.assertEqual('superuser', config.user)
Expand All @@ -79,7 +82,7 @@ def _assertConfig(self, config):
self.assertEqual('Superworkspace', config.workspace)
self.assertEqual('/tmp/migration', config.workDirectory)
self.assertTrue(config.useexistingworkspace)
self.assertEqual('lscm', config.scmcommand)
self.assertEqual('scm', config.scmcommand)
self.assertEqual('UTF-8', shell.encoding) # directly deviated to shell
# [Migration]
self.assertEqual('Superstream', config.streamname)
Expand All @@ -100,3 +103,26 @@ def _assertConfig(self, config):
self.assertEqual(2, len(ignorefileextensions))
self.assertEqual('.zip', ignorefileextensions[0])
self.assertEqual('.jar', ignorefileextensions[1])
self.assertTrue(config.includecomponentroots)

def _assertDefaultConfig(self, config):
# [General]
self.assertEqual('https://rtc.minicompany.com/ccm/', config.repo)
self.assertEqual('miniuser', config.user)
self.assertEqual('minisecret', config.password)
self.assertEqual('mini.git', config.gitRepoName)
self.assertEqual('Miniworkspace', config.workspace)
self.assertEqual(os.getcwd(), config.workDirectory)
self.assertFalse(config.useexistingworkspace)
self.assertEqual('lscm', config.scmcommand)
self.assertEqual(None, shell.encoding) # directly deviated to shell
# [Migration]
self.assertEqual('Ministream', config.streamname)
self.assertEqual('', config.previousstreamname)
self.assertEqual(0, len(config.initialcomponentbaselines))
self.assertFalse(config.useprovidedhistory)
self.assertFalse(config.useautomaticconflictresolution)
# [Miscellaneous]
self.assertFalse(shell.logcommands) # directly deviated to shell
self.assertEqual(0, len(config.ignorefileextensions))
self.assertFalse(config.includecomponentroots)
20 changes: 19 additions & 1 deletion tests/test_rtcFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest.mock import patch
import os

from rtcFunctions import Changes, ChangeEntry, ImportHandler
from rtcFunctions import Changes, ChangeEntry, ImportHandler, WorkspaceHandler
from configuration import Builder
import configuration
import shell
Expand Down Expand Up @@ -122,6 +122,24 @@ def test_useragreeing_answeris_n_expectfalseandexception(self, inputmock):
except SystemExit as e:
self.assertEqual("Please check the output/log and rerun program with resume", e.code)

@patch('rtcFunctions.shell')
def test_load(self, shellmock):
anyurl = "anyUrl"
config = self.configBuilder.setrepourl(anyurl).setworkspace(self.workspace).build()
configuration.config = config
WorkspaceHandler().load()
expected_load_command = "lscm load -r %s %s --force" % (anyurl, self.workspace)
shellmock.execute.assert_called_once_with(expected_load_command)

@patch('rtcFunctions.shell')
def test_load_includecomponentroots(self, shellmock):
anyurl = "anyUrl"
config = self.configBuilder.setrepourl(anyurl).setworkspace(self.workspace).setincludecomponentroots("True").build()
configuration.config = config
WorkspaceHandler().load()
expected_load_command = "lscm load -r %s %s --force --include-root" % (anyurl, self.workspace)
shellmock.execute.assert_called_once_with(expected_load_command)

def get_Sample_File_Path(self, filename):
testpath = os.path.realpath(__file__)
testdirectory = os.path.dirname(testpath)
Expand Down