Big refactoring 4
This commit is contained in:
@ -15,9 +15,9 @@ from .capi.obitypes cimport obiversion_t, \
|
|||||||
|
|
||||||
from .capi.obiutils cimport obi_format_date
|
from .capi.obiutils cimport obi_format_date
|
||||||
|
|
||||||
from ._obiview cimport OBIView
|
from .view cimport View
|
||||||
|
|
||||||
cdef class OBIDMS_column:
|
cdef class Column:
|
||||||
|
|
||||||
cdef bytes _alias # associated property: alias
|
cdef bytes _alias # associated property: alias
|
||||||
cdef OBIDMS_column_p* _pointer
|
cdef OBIDMS_column_p* _pointer
|
||||||
@ -28,7 +28,7 @@ cdef class OBIDMS_column:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
cdef type get_subclass_type(OBIDMS_column_p column_p)
|
cdef type get_subclass_type(OBIDMS_column_p column_p)
|
||||||
|
|
||||||
cdef class OBIDMS_column_line:
|
cdef class Column_line:
|
||||||
|
|
||||||
cdef OBIDMS_column _column
|
cdef OBIDMS_column _column
|
||||||
cdef OBIDMS_column_p _column_p
|
cdef OBIDMS_column_p _column_p
|
||||||
@ -38,4 +38,4 @@ cdef class OBIDMS_column_line:
|
|||||||
|
|
||||||
cpdef update(self, data)
|
cpdef update(self, data)
|
||||||
|
|
||||||
cdef register_column_class(OBIType_t obitype,type classe)
|
cdef register_column_class(OBIType_t obitype,type classe, type python)
|
@ -1,12 +1,13 @@
|
|||||||
#cython: language_level=3
|
#cython: language_level=3
|
||||||
|
|
||||||
cdef dict __OBIDMS_COLUMN_CLASS__ = {}
|
from .dms cimport __OBIDMS_COLUMN_CLASS__
|
||||||
|
|
||||||
|
|
||||||
cdef class Column :
|
cdef class Column :
|
||||||
"""
|
"""
|
||||||
The OBIDMS.Column class
|
The obitools3.dms.column.Column class wraps a c instance of a column in the context of a View
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Note: should only be initialized through a subclass
|
# Note: should only be initialized through a subclass
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
View view,
|
View view,
|
||||||
@ -172,11 +173,15 @@ cdef class OBIDMS_column_line :
|
|||||||
######################################################################################################
|
######################################################################################################
|
||||||
|
|
||||||
|
|
||||||
cdef register_column_class(OBIType_t obitype,type classe):
|
cdef register_column_class(OBIType_t obitype,
|
||||||
|
type classe,
|
||||||
|
type python):
|
||||||
"""
|
"""
|
||||||
Each sub class of `OBIDMS_column` needs to be registered after its declaration
|
Each sub class of `OBIDMS_column` needs to be registered after its declaration
|
||||||
to declare its relationship with an `OBIType_t`
|
to declare its relationship with an `OBIType_t`
|
||||||
"""
|
"""
|
||||||
assert issubclass(classe,OBIDMS_column)
|
global __OBIDMS_COLUMN_CLASS__
|
||||||
|
|
||||||
|
assert issubclass(classe,Column)
|
||||||
|
|
||||||
__OBIDMS_COLUMN_CLASS__[obitype]=classe
|
__OBIDMS_COLUMN_CLASS__[obitype]=(classe,python)
|
@ -36,13 +36,27 @@ from obitools3.utils cimport bytes2str, \
|
|||||||
|
|
||||||
from .taxonomy cimport Taxonomy
|
from .taxonomy cimport Taxonomy
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
__OBIDMS_COLUMN_CLASS__ = {}
|
||||||
|
|
||||||
|
|
||||||
cdef class DMS :
|
cdef class DMS :
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
cdef type get_column_class(obitype_t obitype):
|
||||||
|
"""
|
||||||
|
Internal function returning the python class representing
|
||||||
|
a column for a given obitype.
|
||||||
|
"""
|
||||||
|
return __OBIDMS_COLUMN_CLASS__[obitype][0]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
cdef type get_python_type(obitype_t obitype):
|
||||||
|
"""
|
||||||
|
Internal function returning the python type representing
|
||||||
|
an instance for a given obitype.
|
||||||
|
"""
|
||||||
|
return __OBIDMS_COLUMN_CLASS__[obitype][1]
|
||||||
|
|
||||||
def __init__(self, object dms_name) :
|
def __init__(self, object dms_name) :
|
||||||
'''
|
'''
|
||||||
Constructor of a obitools3.dms.DMS instance.
|
Constructor of a obitools3.dms.DMS instance.
|
||||||
|
@ -32,7 +32,6 @@ from obitools3.utils cimport tobytes, \
|
|||||||
|
|
||||||
from .dms cimport DMS
|
from .dms cimport DMS
|
||||||
|
|
||||||
|
|
||||||
cdef class View:
|
cdef class View:
|
||||||
|
|
||||||
cdef DMS _dms
|
cdef DMS _dms
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
|
|
||||||
cdef class View :
|
cdef class View :
|
||||||
|
|
||||||
|
|
||||||
def __init__(self,dms,int __internalCall__):
|
def __init__(self,dms,int __internalCall__):
|
||||||
|
|
||||||
if __internalCall__!=987654:
|
if __internalCall__!=987654:
|
||||||
@ -116,97 +117,31 @@ cdef class View :
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
cpdef delete_column(self, column_name) :
|
cpdef delete_column(self,
|
||||||
|
object column_name) :
|
||||||
if obi_view_delete_column(self._pointer, tobytes(column_name)) < 0 :
|
if obi_view_delete_column(self._pointer, tobytes(column_name)) < 0 :
|
||||||
raise Exception("Problem deleting column %s from a view",
|
raise Exception("Problem deleting column %s from a view",
|
||||||
tostr(column_name))
|
tostr(column_name))
|
||||||
# Update the dictionary of column objects:
|
# Update the dictionary of column objects:
|
||||||
(self._columns).pop(column_name)
|
|
||||||
self.update_column_pointers()
|
self.update_column_pointers()
|
||||||
|
|
||||||
cpdef add_column(self,
|
|
||||||
str column_name,
|
|
||||||
obiversion_t version_number=-1,
|
|
||||||
object alias=None,
|
|
||||||
object type=b'',
|
|
||||||
index_t nb_lines=0,
|
|
||||||
index_t nb_elements_per_line=1,
|
|
||||||
list elements_names=None,
|
|
||||||
object indexer_name=b"",
|
|
||||||
object associated_column_name=b"",
|
|
||||||
obiversion_t associated_column_version=-1,
|
|
||||||
object comments=b"",
|
|
||||||
bint create=True
|
|
||||||
) :
|
|
||||||
|
|
||||||
cdef bytes column_name_b
|
|
||||||
cdef bytes elements_names_b
|
|
||||||
cdef bytes alias_b
|
|
||||||
cdef object subclass
|
|
||||||
cdef OBIDMS_column_p column_p
|
|
||||||
|
|
||||||
column_name_b = tobytes(column_name)
|
|
||||||
if alias is None :
|
|
||||||
alias_b = column_name_b
|
|
||||||
else :
|
|
||||||
alias_b = tobytes(alias)
|
|
||||||
|
|
||||||
if elements_names is None :
|
|
||||||
elements_names_b = b""
|
|
||||||
else :
|
|
||||||
elements_names_b = b';'.join([tobytes(i) for i in elements_names])
|
|
||||||
|
|
||||||
if type : # TODO make C function that does that
|
|
||||||
if type == 'OBI_INT' :
|
|
||||||
data_type = OBI_INT
|
|
||||||
elif type == 'OBI_FLOAT' :
|
|
||||||
data_type = OBI_FLOAT
|
|
||||||
elif type == 'OBI_BOOL' :
|
|
||||||
data_type = OBI_BOOL
|
|
||||||
elif type == 'OBI_CHAR' :
|
|
||||||
data_type = OBI_CHAR
|
|
||||||
elif type == 'OBI_QUAL' :
|
|
||||||
data_type = OBI_QUAL
|
|
||||||
elif type == 'OBI_STR' :
|
|
||||||
data_type = OBI_STR
|
|
||||||
elif type == 'OBI_SEQ' :
|
|
||||||
data_type = OBI_SEQ
|
|
||||||
else :
|
|
||||||
raise Exception("Invalid provided data type")
|
|
||||||
|
|
||||||
if (obi_view_add_column(self._pointer, column_name_b, version_number, alias_b,
|
|
||||||
data_type, nb_lines, nb_elements_per_line,
|
|
||||||
elements_names_b, str2bytes(indexer_name),
|
|
||||||
str2bytes(associated_column_name), associated_column_version,
|
|
||||||
str2bytes(comments), create) < 0) :
|
|
||||||
raise Exception("Problem adding a column in a view")
|
|
||||||
|
|
||||||
# Get the column pointer
|
|
||||||
column_p = obi_view_get_column(self._pointer, alias_b)
|
|
||||||
|
|
||||||
# Open and store the subclass
|
|
||||||
subclass = OBIDMS_column.get_subclass_type(column_p)
|
|
||||||
(self._columns)[alias] = subclass(self, alias)
|
|
||||||
|
|
||||||
|
cpdef rename_column(self,
|
||||||
cpdef change_column_alias(self, bytes current_alias, bytes new_alias):
|
object current_name,
|
||||||
|
object new_name):
|
||||||
|
|
||||||
cdef OBIDMS_column column
|
cdef OBIDMS_column column
|
||||||
if (obi_view_create_column_alias(self._pointer, current_alias, new_alias) < 0) :
|
cdef bytes current_name_b = tobytes(current_name)
|
||||||
raise Exception("Problem changing a column alias")
|
cdef bytes new_name_b = tobyes(new_name)
|
||||||
# Update the dictionaries of column objects
|
|
||||||
self._columns[new_alias] = self._columns[current_alias]
|
if (obi_view_create_column_alias(self._pointer,
|
||||||
column = self._columns[new_alias]
|
tobytes(current_name_b),
|
||||||
column._alias = new_alias
|
tobytes(new_name_b)) < 0) :
|
||||||
(self._columns).pop(current_alias)
|
raise Exception("Problem in renaming column %s to %s" % (
|
||||||
|
bytes2str(current_name_b),
|
||||||
|
bytes2str(new_name_b)))
|
||||||
cdef update_column_pointers(self):
|
|
||||||
cdef str column_n
|
|
||||||
cdef OBIDMS_column column
|
|
||||||
for column_n in self._columns :
|
|
||||||
column = self._columns[column_n]
|
|
||||||
column._pointer = <OBIDMS_column_p*> obi_view_get_pointer_on_column_in_view(self._pointer, str2bytes(column_n))
|
|
||||||
|
|
||||||
cpdef OBIView_line_selection new_selection(self,list lines=None):
|
cpdef OBIView_line_selection new_selection(self,list lines=None):
|
||||||
return OBIView_line_selection(self,lines)
|
return OBIView_line_selection(self,lines)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user