diff --git a/config.ini.sample b/config.ini.sample index cf120c1..5fc7387 100644 --- a/config.ini.sample +++ b/config.ini.sample @@ -45,4 +45,8 @@ LogShellCommands = False # Define a semicolon-separated list of extensions to be generally ignored # Example: # IgnoreFileExtensions = .zip; .jar; .exe; .dll -IgnoreFileExtensions = \ No newline at end of file +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 diff --git a/configuration.py b/configuration.py index 1f6e618..a4c43a3 100644 --- a/configuration.py +++ b/configuration.py @@ -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()) @@ -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 @@ -108,6 +110,7 @@ def __init__(self): self.clonedgitreponame = "" self.previousstreamname = "" self.ignorefileextensions = "" + self.includecomponentroots = "" def setuser(self, user): self.user = user @@ -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" @@ -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 @@ -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: diff --git a/rtcFunctions.py b/rtcFunctions.py index 30defb8..9a0d04e 100644 --- a/rtcFunctions.py +++ b/rtcFunctions.py @@ -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") diff --git a/tests/resources/test_config.ini b/tests/resources/test_config.ini index 3581204..501a970 100644 --- a/tests/resources/test_config.ini +++ b/tests/resources/test_config.ini @@ -6,7 +6,7 @@ GIT-Reponame = super.git WorkspaceName=Superworkspace Directory = /tmp/migration useExistingWorkspace = True -ScmCommand = lscm +ScmCommand = scm encoding = UTF-8 [Migration] @@ -19,3 +19,4 @@ UseAutomaticConflictResolution = True [Miscellaneous] LogShellCommands = True IgnoreFileExtensions = .zip; .jar +IncludeComponentRoots = True diff --git a/tests/resources/test_minimum_config.ini b/tests/resources/test_minimum_config.ini index 29b7b01..5fb5817 100644 --- a/tests/resources/test_minimum_config.ini +++ b/tests/resources/test_minimum_config.ini @@ -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 diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 9c2d60a..1d07a8d 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -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() @@ -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) @@ -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) @@ -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) diff --git a/tests/test_rtcFunctions.py b/tests/test_rtcFunctions.py index 8e388d1..9e0db81 100644 --- a/tests/test_rtcFunctions.py +++ b/tests/test_rtcFunctions.py @@ -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 @@ -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)