Skip to content
Snippets Groups Projects
Commit 383ea6ab authored by yvesn's avatar yvesn
Browse files

obis: implemented init_analysis

parent e0e8e156
No related branches found
No related tags found
No related merge requests found
...@@ -179,6 +179,9 @@ class GitDataMgmt(AbstractDataMgmt): ...@@ -179,6 +179,9 @@ class GitDataMgmt(AbstractDataMgmt):
with cd(path): with cd(path):
return self.config_resolver.config_dict().get('data_set_id') return self.config_resolver.config_dict().get('data_set_id')
def get_config(self, path, key):
with cd(path):
return self.config_resolver.config_dict().get(key)
def init_data(self, path, desc=None, create=True, apply_config=False): def init_data(self, path, desc=None, create=True, apply_config=False):
if not os.path.exists(path) and create: if not os.path.exists(path) and create:
...@@ -202,31 +205,24 @@ class GitDataMgmt(AbstractDataMgmt): ...@@ -202,31 +205,24 @@ class GitDataMgmt(AbstractDataMgmt):
# get data_set_id of parent from current folder or explicit parent argument # get data_set_id of parent from current folder or explicit parent argument
parent_folder = parent if parent is not None and len(parent) > 0 else "." parent_folder = parent if parent is not None and len(parent) > 0 else "."
parent_data_set_id = self.get_data_set_id(parent_folder) parent_data_set_id = self.get_data_set_id(parent_folder)
# check that data_set_id is set - parent repository has been added to openBIS # check that parent repository has been added to openBIS
if parent_data_set_id is None: if self.get_config(parent_folder, 'repository_id') is None:
return CommandResult(returncode=-1, output="Parent data set must be committed to openBIS before creating an analysis data set.") return CommandResult(returncode=-1, output="Parent data set must be committed to openBIS before creating an analysis data set.")
# check that analysis repository does not already exist
if os.path.exists(path):
return CommandResult(returncode=-1, output="Data set already exists: " + path)
# init analysis repository # init analysis repository
result = self.init_data(path, desc, create, apply_config) result = self.init_data(path, desc, create, apply_config)
if result.failure(): if result.failure():
return result return result
# add analysis repository folder to .gitignore of parent # add analysis repository folder to .gitignore of parent
if os.path.exists('.obis'): if os.path.exists('.obis'):
with open(".gitignore", "a") as gitignore: self.git_wrapper.git_ignore(path)
gitignore.write(path)
gitignore.write("\n")
elif parent is None: elif parent is None:
return CommandResult(returncode=-1, output="Not within a repository and no parent set.") return CommandResult(returncode=-1, output="Not within a repository and no parent set.")
# set data_set_id to analysis repository so it will be used as parent when committing
with cd(path): with cd(path):
cli.config_internal(self, False, "data_set_id", parent_data_set_id) cli.config_internal(self, False, "data_set_id", parent_data_set_id)
# TODO init repo and link new data set as child.
# add to gitignore of parent data set
# add parameter to reference parent in case it's not in the same folder
# TODO use git check-ignore to not add folder twice
# TODO cleanup when something goes wrong
return result return result
......
...@@ -79,6 +79,13 @@ class GitWrapper(object): ...@@ -79,6 +79,13 @@ class GitWrapper(object):
def git_reset_to(self, commit_hash): def git_reset_to(self, commit_hash):
return run_shell([self.git_path, 'reset', commit_hash]) return run_shell([self.git_path, 'reset', commit_hash])
def git_ignore(self, path):
result = run_shell([self.git_path, 'check-ignore', path])
if result.returncode == 1:
with open(".gitignore", "a") as gitignore:
gitignore.write(path)
gitignore.write("\n")
class GitRepoFileInfo(object): class GitRepoFileInfo(object):
"""Class that gathers checksums and file lengths for all files in the repo.""" """Class that gathers checksums and file lengths for all files in the repo."""
......
...@@ -151,11 +151,11 @@ def init_data_impl(ctx, object_id, collection_id, folder, desc): ...@@ -151,11 +151,11 @@ def init_data_impl(ctx, object_id, collection_id, folder, desc):
init_handle_cleanup(result, object_id, collection_id) init_handle_cleanup(result, object_id, collection_id)
def init_analysis_impl(ctx, object_id, collection_id, folder, parent, desc): def init_analysis_impl(ctx, parent, object_id, collection_id, folder, description):
click_echo("init_analysis {}".format(folder)) click_echo("init_analysis {}".format(folder))
data_mgmt = shared_data_mgmt(ctx.obj) data_mgmt = shared_data_mgmt(ctx.obj)
desc = desc if desc != "" else None description = description if description != "" else None
result = data_mgmt.init_analysis(folder, parent, desc, create=True) result = data_mgmt.init_analysis(folder, parent, description, create=True)
init_handle_cleanup(result, object_id, collection_id) init_handle_cleanup(result, object_id, collection_id)
...@@ -193,14 +193,14 @@ def init_data(ctx, object_id, collection_id, folder, description): ...@@ -193,14 +193,14 @@ def init_data(ctx, object_id, collection_id, folder, description):
@cli.command() @cli.command()
@click.pass_context @click.pass_context
@click.option('-p', '--parent', type=click.Path(exists=False, file_okay=False))
@click.option('-oi', '--object_id', help='Set the id of the owning sample.') @click.option('-oi', '--object_id', help='Set the id of the owning sample.')
@click.option('-ci', '--collection_id', help='Set the id of the owning experiment.') @click.option('-ci', '--collection_id', help='Set the id of the owning experiment.')
@click.argument('folder', type=click.Path(exists=False, file_okay=False)) @click.argument('folder', type=click.Path(exists=False, file_okay=False))
@click.argument('description', default="") @click.argument('description', default="")
@click.option('-p', '--parent', type=click.Path(exists=False, file_okay=False)) def init_analysis(ctx, parent, object_id, collection_id, folder, description):
def init_analysis(ctx, object_id, collection_id, folder, description, parent):
"""Initialize the folder as an analysis folder.""" """Initialize the folder as an analysis folder."""
return init_analysis_impl(ctx, object_id, collection_id, folder, description, parent) return init_analysis_impl(ctx, parent, object_id, collection_id, folder, description)
@cli.command() @cli.command()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment