def test_tool_git_submodules_default(self): self.defconfig_add('VERSION', DEFAULT_BRANCH) with generate_temp_dir() as repo2: # prepare additional mock repository directories repo1 = self.repo_dir self.prepare_repo_dir(repo2) # dummy file on repo1 touch(os.path.join(repo1, 'file1')) self._create_commit('add file', repo=repo1, add=True) # dummy file on repo2 touch(os.path.join(repo2, 'file2')) self._create_commit('add file', repo=repo2, add=True) # add a submodule repo2 to repo1 self._git_repo('submodule', 'add', repo2, 'repo2', repo=repo1) self._create_commit('add module', repo=repo1, add=True) # extract package but not submodules (by default) self.engine.opts.gbl_action = GlobalAction.EXTRACT rv = self.engine.run() self.assertTrue(rv) # verify expected content from main package; not submodules out_dir = os.path.join(self.engine.opts.build_dir, 'test-' + DEFAULT_BRANCH) repo1_file = os.path.join(out_dir, 'file1') repo2_file = os.path.join(out_dir, 'repo2', 'file2') self.assertTrue(os.path.exists(repo1_file)) self.assertFalse(os.path.exists(repo2_file))
def test_utilio_touch(self): with prepare_workdir() as work_dir: test_file = os.path.join(work_dir, 'test-file') created = touch(test_file) self.assertTrue(created) exists = os.path.isfile(test_file) self.assertTrue(exists) updated = touch(test_file) self.assertTrue(updated)
def process_file_flag(flag, file, quiet=False): """ process a file flag event Will either write a file flag configuration event or attempt to read a file flag state. If the ``flag`` option is set to ``True``, this process event will assume that this instance is attempting to configure a file flag (on) state and generate the target file flag on the system. If the flag option is set to ``False``, the file's existence will be checked to reflect whether or not the flag is considered enabled. Args: flag: the flag option to used; ``None`` to check flag state file: the filename quiet: suppression of any error messages to standard out Returns: ``FileFlag.EXISTS`` if the flag is enabled; ``FileFlag.NO_EXIST`` if the flag is not enabled; ``FileFlag.CONFIGURED`` if the flag was configured as requested; ``FileFlag.NOT_CONFIGURED`` if the flag could not be configured as requested """ if flag: # When checking if the file flag exists, attempt to update the access/ # modified times. For the case where may experience issues creating the # file flag themselves (permission errors, etc.), fallback on just the # existence of the file flag to still be considered as configured. if touch(file): rv = FileFlag.CONFIGURED else: if os.path.isfile(file): rv = FileFlag.CONFIGURED else: rv = FileFlag.NOT_CONFIGURED if not quiet: err('unable to configure file flag: {}', file) elif flag is None and os.path.isfile(file): rv = FileFlag.EXISTS else: rv = FileFlag.NO_EXIST return rv
def test_tool_git_submodules_branch_revision(self): self.defconfig_add('GIT_SUBMODULES', True) self.defconfig_add('VERSION', DEFAULT_BRANCH) with generate_temp_dir() as repo2: # prepare additional mock repository directories repo1 = self.repo_dir self.prepare_repo_dir(repo2) # dummy file on repo1 touch(os.path.join(repo1, 'file1')) self._create_commit('add file', repo=repo1, add=True) # dummy files on repo2 for two branches CUSTOM_BRANCH = 'custom' touch(os.path.join(repo2, 'file2')) self._create_commit('add file', repo=repo2, add=True) self._git_repo('checkout', '-b', CUSTOM_BRANCH, repo=repo2) touch(os.path.join(repo2, 'file3')) self._create_commit('add file', repo=repo2, add=True) self._git_repo('checkout', DEFAULT_BRANCH, repo=repo2) # add a submodule repo2 to repo1 self._git_repo('submodule', 'add', repo2, 'repo2', repo=repo1) self._create_commit('add module', repo=repo1, add=True) # extract package but not submodules (by default) self.engine.opts.gbl_action = GlobalAction.EXTRACT rv = self.engine.run() self.assertTrue(rv) # verify expected content from main package; not submodules out_dir = os.path.join(self.engine.opts.build_dir, 'test-' + DEFAULT_BRANCH) repo1_file = os.path.join(out_dir, 'file1') repo2_file = os.path.join(out_dir, 'repo2', 'file2') self.assertTrue(os.path.exists(repo1_file)) self.assertTrue(os.path.exists(repo2_file)) # cleanup self.cleanup_outdir() # adjust submodule to target the custom branch self._git_repo('config', '-f', '.gitmodules', 'submodule.repo2.branch', CUSTOM_BRANCH, repo=repo1) # force a fetch (which should update the cache) self.engine.opts.gbl_action = GlobalAction.FETCH rv = self.engine.run() self.assertTrue(rv) # re-extract package and submodules self.engine.opts.gbl_action = GlobalAction.EXTRACT rv = self.engine.run() self.assertTrue(rv) # verify expected content from main package and submodules repo3_file = os.path.join(out_dir, 'repo2', 'file3') self.assertTrue(os.path.exists(repo3_file))
def test_tool_git_devmode_auto_fetch_branch(self): # create a new branch with a commit TARGET_BRANCH = 'target' self._git_repo('checkout', '-b', TARGET_BRANCH) first_hash = self._create_commit('first') # enable development mode touch(self.engine.opts.ff_devmode) # note: default state should be automatic cache-ignoring # (i.e enabled in development mode) # fetch the target self.defconfig_add('VERSION', TARGET_BRANCH) rv = self.engine.run() self.assertTrue(rv) current_hash = self._git_cache('rev-parse', 'HEAD') self.assertEqual(current_hash, first_hash) # cleanup self.cleanup_outdir() self.engine.opts.devmode = None # create a new commit second_hash = self._create_commit('second') # extract project; should be the second commit rv = self.engine.run() self.assertTrue(rv) current_hash = self._git_cache('rev-parse', 'HEAD') self.assertEqual(current_hash, second_hash) # cleanup self.cleanup_outdir() self.engine.opts.devmode = None # create a new commit third_hash = self._create_commit('third') # explicitly indicate that cache-ignoring should not happen self.defconfig_add('DEVMODE_IGNORE_CACHE', False) self.defconfig_dump() # extract; should be the second commit rv = self.engine.run() self.assertTrue(rv) current_hash = self._git_cache('rev-parse', 'HEAD') self.assertEqual(current_hash, second_hash) # cleanup self.cleanup_outdir() self.engine.opts.devmode = None # explicitly indicate that cache-ignoring can happen self.defconfig_add('DEVMODE_IGNORE_CACHE', True) # extract; should be the third commit rv = self.engine.run() self.assertTrue(rv) current_hash = self._git_cache('rev-parse', 'HEAD') self.assertEqual(current_hash, third_hash)