diff --git a/python/obitools3/commands/rm.pyx b/python/obitools3/commands/rm.pyx new file mode 100644 index 0000000..55c2f0a --- /dev/null +++ b/python/obitools3/commands/rm.pyx @@ -0,0 +1,44 @@ +#cython: language_level=3 + +from obitools3.uri.decode import open_uri +from obitools3.apps.config import logger +from obitools3.dms import DMS +from obitools3.apps.optiongroups import addMinimalInputOption +from obitools3.dms.view.view cimport View +import os + +__title__="Delete a view" + + +def addOptions(parser): + addMinimalInputOption(parser) + +def run(config): + + DMS.obi_atexit() + + logger("info", "obi rm") + + # Open the input + input = open_uri(config['obi']['inputURI']) + if input is None: + raise Exception("Could not read input") + + # Check that it's a view + if isinstance(input[1], View) : + view = input[1] + else: + raise NotImplementedError() + + # Get the path to the view file to remove + path = input[0].full_path # dms path + path+=b"/VIEWS/" + path+=view.name + path+=b".obiview" + + # Close the view and the DMS + view.close() + input[0].close(force=True) + + # Rm + os.remove(path) diff --git a/python/obitools3/dms/view/view.pyx b/python/obitools3/dms/view/view.pyx index 2314bdd..2cda8a2 100755 --- a/python/obitools3/dms/view/view.pyx +++ b/python/obitools3/dms/view/view.pyx @@ -600,7 +600,8 @@ cdef class View(OBIWrapper) : if element is not None: if element.comments[b"input_dms_name"] is not None : for i in range(len(element.comments[b"input_dms_name"])) : - if element.comments[b"input_dms_name"][i] == element.dms.name and b"/" not in element.comments[b"input_view_name"][i]: # Same DMS and not a special element like a taxonomy + if b"/" not in element.comments[b"input_view_name"][i] and element.comments[b"input_view_name"][i] in element.dms \ + and element.comments[b"input_dms_name"][i] == element.dms.name : # Same DMS and not a special element like a taxonomy and view was not deleted top_level.append(element.dms[element.comments[b"input_view_name"][i]]) else: top_level.append(None)