From 392f110c8de52ca7b03e151dd85e06d440b8499e Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Fri, 2 Oct 2015 13:51:26 +0200 Subject: [PATCH] new functions in the OBIDMS_column class to raise NotImplementedError exceptions and to get the creation date of a column --- python/obitools3/obidms/_obidms.pxd | 6 ++++ python/obitools3/obidms/_obidms.pyx | 30 ++++++++++++++++--- python/obitools3/obidms/capi/obidmscolumn.pxd | 5 ++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/python/obitools3/obidms/_obidms.pxd b/python/obitools3/obidms/_obidms.pxd index a12e620..386d672 100644 --- a/python/obitools3/obidms/_obidms.pxd +++ b/python/obitools3/obidms/_obidms.pxd @@ -4,7 +4,9 @@ from .capi.obidms cimport OBIDMS_p from .capi.obidmscolumn cimport OBIDMS_column_p from .capi.obitypes cimport obiversion_t, OBIType_t + cdef class OBIDMS_column + cdef class OBIDMS: @@ -33,6 +35,10 @@ cdef class OBIDMS_column: cdef str column_name cpdef object get_item(self, size_t line_nb, str element_name) +# cpdef set_item(self, size_t line_nb, str element_name, object value) TODO cpdef list get_elements_names(self) cpdef str get_data_type(self) cpdef size_t get_nb_lines_used(self) + cpdef str get_creation_date(self) + cpdef close(self) + diff --git a/python/obitools3/obidms/_obidms.pyx b/python/obitools3/obidms/_obidms.pyx index f1f7de6..7c90544 100644 --- a/python/obitools3/obidms/_obidms.pyx +++ b/python/obitools3/obidms/_obidms.pyx @@ -10,6 +10,8 @@ from .capi.obidmscolumn cimport obi_column_get_data_type_from_name, \ obi_column_get_line_count_from_name, \ obi_column_get_nb_lines_used, \ obi_column_get_elements_names, \ + obi_column_get_formatted_creation_date, \ + obi_column_get_formatted_creation_date_from_name, \ obi_create_column, \ obi_clone_column, \ obi_open_column, \ @@ -63,12 +65,17 @@ cdef class OBIDMS : cdef str column_name cdef bytes column_name_b cdef str data_type + cdef str creation_date cdef obiversion_t latest_version cdef size_t line_count p = Path(self.dms_name+'.obidms') - print("{:<25} {:<25} {:<25} {:<25}".format('-Column name-','-Data type-','-Latest version number-', '-Line count of latest version-')) + print("{:<25} {:<25} {:<25} {:<25}".format('-Column name-', + '-Data type-', + '-Latest version number-', + '-Line count of latest version-')) + #'-Creation date of latest version-')) for entry in p.iterdir(): if entry.suffix == ".obicol": column_name = entry.stem @@ -77,13 +84,19 @@ cdef class OBIDMS : data_type = bytes2str(name_data_type(obi_column_get_data_type_from_name(self.pointer, column_name_b))) latest_version = obi_column_get_latest_version_from_name(self.pointer, column_name_b) line_count = obi_column_get_line_count_from_name(self.pointer, column_name_b) + +# creation_date = bytes2str(obi_column_get_formatted_creation_date_from_name(self.pointer, column_name_b)) #TODO +# print(creation_date) + dms[column_name]['data_type'] = data_type dms[column_name]['latest_version'] = latest_version dms[column_name]['line_count'] = line_count +# dms[column_name]['creation_date'] = creation_date print("{:<25} {:<25} {:<25} {:<25}".format(column_name, data_type, latest_version, line_count)) return dms + cpdef OBIDMS_column open_column(self, str column_name, bint create=False, @@ -109,6 +122,9 @@ cdef class OBIDMS : data_type = obi_column_get_data_type_from_name(self.pointer, column_name_b) # Open the column with the right subclass depending on the data type and the mode (read-only or writable) + + # TODO : check that data type is the same as previous version if it exists? + if data_type == 1 : if (create or clone) : column = OBIDMS_column_int_writable(self, column_name, @@ -266,18 +282,24 @@ cdef class OBIDMS_column : cpdef object get_item(self, size_t line_nb, str element_name): raise NotImplementedError + +# cpdef set_item(self, size_t line_nb, str element_name, object value): TODO +# raise NotImplementedError cpdef list get_elements_names(self): cdef bytes elements_names elements_names = obi_column_get_elements_names(self.pointer) return (bytes2str(elements_names)).split(';') - cpdef str get_data_type(self): return self.data_type - cpdef size_t get_nb_lines_used(self): return obi_column_get_nb_lines_used(self.pointer) - + + cpdef str get_creation_date(self): + return bytes2str(obi_column_get_formatted_creation_date(self.pointer)) + + cpdef close(self): + raise NotImplementedError diff --git a/python/obitools3/obidms/capi/obidmscolumn.pxd b/python/obitools3/obidms/capi/obidmscolumn.pxd index 67c9549..0b314e6 100644 --- a/python/obitools3/obidms/capi/obidmscolumn.pxd +++ b/python/obitools3/obidms/capi/obidmscolumn.pxd @@ -56,6 +56,11 @@ cdef extern from "obidmscolumn.h" nogil: size_t obi_column_get_line_count_from_name(OBIDMS_p dms, const_char_p column_name) + char* obi_column_get_formatted_creation_date(OBIDMS_column_p column) + + char* obi_column_get_formatted_creation_date_from_name(OBIDMS_p dms, + const_char_p column_name) + cdef extern from "obidmscolumn_int.h" nogil: int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column,