This commit is contained in:
Celine Mercier
2015-09-25 11:28:23 +02:00
parent 68b6ab3224
commit 0951934f77
5 changed files with 24 additions and 52 deletions

View File

@ -0,0 +1,158 @@
#cython: language_level=3
from obitools3.utils cimport bytes2str, str2bytes
from obitools3.obidms.obidmscolumn._obidmscolumn cimport OBIDMS_column
from pathlib import Path
# from obitools3.obidms.obidmscolumn.capidmscolumn cimport OBIDMS_column
# from obitools3.obidms.obidmscolumn.capidmscolumn cimport obiversion_t # TODO pourquoi je peux pas les declarer dans le pxd?
# from obitools3.obidms.obidmscolumn.capidmscolumn cimport name_data_type
# from obitools3.obidms.obidmscolumn.capidmscolumn cimport obi_column_get_data_type_from_name
# from obitools3.obidms.obidmscolumn.capidmscolumn cimport obi_column_get_latest_version_from_name
# from obitools3.obidms.obidmscolumn.capidmscolumn cimport obi_column_get_line_count_from_name
#
from obitools3.obidms.obidmscolumn.obidmscolumn_int.capidmscolumn_int cimport OBIDMS_column_int_writable # TODO pourquoi pas cimport?
from obitools3.obidms.obidmscolumn.obidmscolumn_int.capidmscolumn_int cimport OBIDMS_column_int_read
from obitools3.obidms.obidmscolumn.obidmscolumn_float.capidmscolumn_float cimport OBIDMS_column_float_writable
from obitools3.obidms.obidmscolumn.obidmscolumn_float.capidmscolumn_float cimport OBIDMS_column_float_read
from obitools3.obidms.obidmscolumn.obidmscolumn_bool.capidmscolumn_bool cimport OBIDMS_column_bool_writable
from obitools3.obidms.obidmscolumn.obidmscolumn_bool.capidmscolumn_bool cimport OBIDMS_column_bool_read
from obitools3.obidms.obidmscolumn.obidmscolumn_char.capidmscolumn_char cimport OBIDMS_column_char_writable
from obitools3.obidms.obidmscolumn.obidmscolumn_char.capidmscolumn_char cimport OBIDMS_column_char_read
from obitools3.obidms.obidmscolumn.obidmscolumn_idx.capidmscolumn_idx cimport OBIDMS_column_idx_writable
from obitools3.obidms.obidmscolumn.obidmscolumn_idx.capidmscolumn_idx cimport OBIDMS_column_idx_read
cdef class OBIDMS :
def __init__(self, str dms_name) : # TODO
# Declarations
cdef bytes dms_name_b
# Format the character string to send to C function
dms_name_b = str2bytes(dms_name)
# Fill structure and create or open the DMS
self.dms_name = dms_name
self.pointer = obi_dms(<const_char_p> dms_name_b)
# def __del__(self) : # TODO problem with closing dir breaking everything
# obi_close_dms(self.pointer)
cpdef dict list(self):
# Declarations
cdef object p
cdef dict dms = {}
cdef str column_name
cdef bytes column_name_b
cdef str data_type
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-'))
for entry in p.iterdir():
if entry.suffix == ".obicol":
column_name = entry.stem
column_name_b = str2bytes(column_name)
dms[column_name] = {}
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)
dms[column_name]['data_type'] = data_type
dms[column_name]['latest_version'] = latest_version
dms[column_name]['line_count'] = line_count
print("{:<25} {:<25} {:<25} {:<25}".format(column_name, data_type, latest_version, line_count))
return dms
cpdef OBIDMS_column open_column(self, # TODO j'arrive pas a le passer en cpdef
str column_name, # TODO
bint create=False,
bint clone=False, bint clone_data=True,
obiversion_t version_number=-1,
OBIType_t data_type=0, # TODO
size_t nb_lines=0,
size_t nb_elements_per_line=1,
str elements_names=None):
# Declarations
cdef OBIDMS_column column # TODO not sure object
cdef bytes column_name_b
# Format the character string to send to C function
column_name_b = str2bytes(column_name)
# Get the data type if not provided
if not data_type :
if create :
raise Exception("A data type must be specified")
else :
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)
if data_type == 1 :
if (create or clone) :
column = OBIDMS_column_int_writable(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_int_read(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
elif data_type == 2 :
if (create or clone) :
column = OBIDMS_column_float_writable(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_float_read(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
elif data_type == 3 :
if (create or clone) :
column = OBIDMS_column_bool_writable(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_bool_read(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
elif data_type == 4 :
if (create or clone) :
column = OBIDMS_column_char_writable(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_char_read(self, column_name,
create, clone, clone_data,
version_number, data_type,
nb_lines, nb_elements_per_line,
elements_names)
else :
raise Exception("Problem with the data type")
return column