From 2f4780d5c46c5ac2f25f5d80c2b63646da2f203c Mon Sep 17 00:00:00 2001 From: Chandrasekhar Ramakrishnan <chandrasekhar.ramakrishnan@id.ethz.ch> Date: Fri, 3 Feb 2017 17:36:05 +0100 Subject: [PATCH] SSDM-4670: Simplify commands -- no need to add data. Commit automatically does this. --- src/python/OBis/obis/dm/data_mgmt.py | 35 +++++++++++++++-------- src/python/OBis/obis/dm/data_mgmt_test.py | 10 ++----- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/python/OBis/obis/dm/data_mgmt.py b/src/python/OBis/obis/dm/data_mgmt.py index e37fc61e027..c34575f039b 100644 --- a/src/python/OBis/obis/dm/data_mgmt.py +++ b/src/python/OBis/obis/dm/data_mgmt.py @@ -138,15 +138,14 @@ class AbstractDataMgmt(metaclass=abc.ABCMeta): return @abc.abstractmethod - def add_content(self, path): - """Add content to the repository.""" - return - - @abc.abstractmethod - def commit(self, msg): - """Commit the current repo. + def commit(self, msg, auto_add=True): + """ + Commit the current repo. This issues a git commit and connects to openBIS and creates a data set in openBIS. + :param msg: Commit message. + :param auto_add: Automatically add all files in the folder to the repo. Defaults to True. + :return: """ return @@ -160,10 +159,7 @@ class NoGitDataMgmt(AbstractDataMgmt): def init_analysis(self, path): self.error_raise("init analysis", "No git command found.") - def add_content(self, path): - self.error_raise("add", "No git command found.") - - def commit(self, msg): + def commit(self, msg, auto_add=True): self.error_raise("commit", "No git command found.") @@ -192,10 +188,20 @@ class GitDataMgmt(AbstractDataMgmt): self.error(result.output) return result - def commit(self, msg): + def commit(self, msg, auto_add=True): + if auto_add: + result = self.git_wrapper.get_top_level_path() + if result.returncode != 0: + self.error(result.output) + return result + result = self.add_content(result.output) + if result.returncode != 0: + self.error(result.output) + return result result = self.git_wrapper.git_commit(msg) if result.returncode != 0: self.error(result.output) + # TODO create a data set in openBIS return result @@ -239,6 +245,8 @@ class GitWrapper(object): if result.returncode != 0: return result + # TODO Create a .obis directory and add it to gitignore + cmd = [self.git_path, "-C", path, "commit", "-m", "Initial commit."] result = run_shell(cmd) return result @@ -248,3 +256,6 @@ class GitWrapper(object): def git_commit(self, msg): return run_shell([self.git_path, "commit", '-m', msg]) + + def get_top_level_path(self): + return run_shell([self.git_path, 'rev-parse', '--show-toplevel']) diff --git a/src/python/OBis/obis/dm/data_mgmt_test.py b/src/python/OBis/obis/dm/data_mgmt_test.py index 9cf0f8c24f6..8113f3851aa 100644 --- a/src/python/OBis/obis/dm/data_mgmt_test.py +++ b/src/python/OBis/obis/dm/data_mgmt_test.py @@ -56,13 +56,6 @@ def test_data_use_case(shared_dm, tmpdir): copy_test_data(tmpdir) with data_mgmt.cd(tmp_dir_path): - result = shared_dm.add_content(".") - assert result.returncode == 0 - - result = git_status() - assert result.returncode == 0 - assert result.output == "A snb-data.zip\nA test.txt" - result = shared_dm.commit("Added data.") assert result.returncode == 0 @@ -75,6 +68,9 @@ def test_data_use_case(shared_dm, tmpdir): result = data_mgmt.run_shell(['git', 'annex', 'info', 'test.txt']) present_p = result.output.split(' ')[-1] assert present_p == 'failed' + result = data_mgmt.run_shell(['git', 'log', '--oneline', 'test.txt']) + present_p = " ".join(result.output.split(' ')[1:]) + assert present_p == 'Added data.' def copy_test_data(tmpdir): -- GitLab