obi ls: various improvements
This commit is contained in:
@ -3,7 +3,9 @@
|
|||||||
from obitools3.uri.decode import open_uri
|
from obitools3.uri.decode import open_uri
|
||||||
from obitools3.apps.config import logger
|
from obitools3.apps.config import logger
|
||||||
from obitools3.dms import DMS
|
from obitools3.dms import DMS
|
||||||
|
from obitools3.dms.taxo.taxo cimport Taxonomy
|
||||||
from obitools3.apps.optiongroups import addMinimalInputOption
|
from obitools3.apps.optiongroups import addMinimalInputOption
|
||||||
|
from obitools3.utils cimport tostr
|
||||||
|
|
||||||
|
|
||||||
__title__="Print a preview of a DMS, view, column...."
|
__title__="Print a preview of a DMS, view, column...."
|
||||||
@ -11,6 +13,12 @@ __title__="Print a preview of a DMS, view, column...."
|
|||||||
|
|
||||||
def addOptions(parser):
|
def addOptions(parser):
|
||||||
addMinimalInputOption(parser)
|
addMinimalInputOption(parser)
|
||||||
|
group = parser.add_argument_group('obi ls specific options')
|
||||||
|
|
||||||
|
group.add_argument('-l',
|
||||||
|
action="store_true", dest="ls:longformat",
|
||||||
|
default=False,
|
||||||
|
help="Detailed list in long format with all metadata.")
|
||||||
|
|
||||||
|
|
||||||
def run(config):
|
def run(config):
|
||||||
@ -23,6 +31,21 @@ def run(config):
|
|||||||
input = open_uri(config['obi']['inputURI'])
|
input = open_uri(config['obi']['inputURI'])
|
||||||
if input is None:
|
if input is None:
|
||||||
raise Exception("Could not read input")
|
raise Exception("Could not read input")
|
||||||
|
if input[2] == DMS and not config['ls']['longformat']:
|
||||||
print(repr(input[1]))
|
dms = input[0]
|
||||||
|
l = []
|
||||||
|
for view in input[0]:
|
||||||
|
l.append(tostr(view) + "\t(Date created: " + tostr(dms[view].comments["Date created"])+")")
|
||||||
|
l.sort()
|
||||||
|
for v in l:
|
||||||
|
print(v)
|
||||||
|
else:
|
||||||
|
print(repr(input[1]))
|
||||||
|
if input[2] == DMS:
|
||||||
|
print("\n### Taxonomies:")
|
||||||
|
for t in Taxonomy.list_taxos(input[0]):
|
||||||
|
print("\t", tostr(t))
|
||||||
|
if config['ls']['longformat'] and len(input[1].comments) > 0:
|
||||||
|
print("\n### Comments:")
|
||||||
|
print(str(input[1].comments))
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#cython: language_level=3
|
#cython: language_level=3
|
||||||
|
|
||||||
from obitools3.utils cimport str2bytes, bytes2str, tobytes, tostr
|
from obitools3.utils cimport str2bytes, bytes2str, tobytes, tostr
|
||||||
|
from ..capi.obidms cimport OBIDMS_p, obi_dms_get_full_path
|
||||||
|
|
||||||
from ..capi.obitaxonomy cimport obi_taxonomy_exists, \
|
from ..capi.obitaxonomy cimport obi_taxonomy_exists, \
|
||||||
obi_read_taxonomy, \
|
obi_read_taxonomy, \
|
||||||
@ -17,8 +18,9 @@ from ..capi.obitaxonomy cimport obi_taxonomy_exists, \
|
|||||||
ecotx_t
|
ecotx_t
|
||||||
|
|
||||||
from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
|
from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
|
||||||
|
|
||||||
import tarfile
|
import tarfile
|
||||||
|
from pathlib import Path
|
||||||
|
from libc.stdlib cimport free
|
||||||
|
|
||||||
|
|
||||||
cdef class Taxonomy(OBIWrapper) :
|
cdef class Taxonomy(OBIWrapper) :
|
||||||
@ -38,6 +40,24 @@ cdef class Taxonomy(OBIWrapper) :
|
|||||||
return e
|
return e
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def list_taxos(DMS dms):
|
||||||
|
|
||||||
|
cdef OBIDMS_p dms_p
|
||||||
|
cdef const char* path
|
||||||
|
|
||||||
|
dms_p = dms.pointer()
|
||||||
|
path = obi_dms_get_full_path(dms_p, b"TAXONOMY")
|
||||||
|
if path == NULL:
|
||||||
|
raise RuntimeError("Cannot retrieve the taxonomy directory path")
|
||||||
|
|
||||||
|
p = Path(bytes2str(path))
|
||||||
|
free(path)
|
||||||
|
|
||||||
|
for tax in p.glob("*") :
|
||||||
|
yield str2bytes(tax.stem)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open(DMS dms, object name) :
|
def open(DMS dms, object name) :
|
||||||
|
|
||||||
|
@ -177,8 +177,7 @@ cdef class View(OBIWrapper) :
|
|||||||
|
|
||||||
@OBIWrapper.checkIsActive
|
@OBIWrapper.checkIsActive
|
||||||
def __repr__(self) :
|
def __repr__(self) :
|
||||||
cdef str s = "#View name:\n{name:s}\n#Comments:\n{comments:s}\n#Line count:\n{line_count:d}\n#Columns:\n".format(name = bytes2str(self.name),
|
cdef str s = "#View name:\n{name:s}\n#Line count:\n{line_count:d}\n#Columns:\n".format(name = bytes2str(self.name),
|
||||||
comments = str(self.comments),
|
|
||||||
line_count = self.line_count)
|
line_count = self.line_count)
|
||||||
for column_name in self.keys() :
|
for column_name in self.keys() :
|
||||||
s = s + repr(self[column_name]) + '\n'
|
s = s + repr(self[column_name]) + '\n'
|
||||||
|
@ -1096,6 +1096,16 @@ static int finish_view(Obiview_p view)
|
|||||||
(column->header)->finished = true;
|
(column->header)->finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the time in the view comments
|
||||||
|
time_t t;
|
||||||
|
t = time(&t);
|
||||||
|
if (obi_view_add_comment(view, "Date created", strtok(ctime(&t), "\n")) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBIVIEW_ERROR);
|
||||||
|
obidebug(1, "\nError adding the date of creation when finishing a view");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Flag the view as finished
|
// Flag the view as finished
|
||||||
(view->infos)->finished = true;
|
(view->infos)->finished = true;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user