cubes.piws.importer.base.Base¶
-
class
cubes.piws.importer.base.
Base
(session, can_read=True, can_update=False, use_store=True, piws_security_model=True)[source]¶ This class enables us to add new entities and relations in CW.
Notes
Here is an example of the definition of the ‘relations’ parameter:
relations = [ ("CWUser", "in_group", "CWGroup") ]
Attributes
relations: list of 3-uplet (mandatory) all the relations involved in schema we want to document. -
__init__
(session, can_read=True, can_update=False, use_store=True, piws_security_model=True)[source]¶ Initialize the SeniorData class.
Parameters: session: Session (mandatory) :
a cubicweb session.
can_read: bool (optional, default True) :
set the read permission to the imported data.
can_update: bool (optional, default False) :
set the update permission to the imported data.
use_store: bool (optional, default True) :
if True use an SQLGenObjectStore, otherwise the session.
piws_security_model: bool (optional, default True) :
if True apply the PIWS security model.
Methods
__init__
(session[, can_read, can_update, ...])Initialize the SeniorData class. cleanup
()Method to cleanup temporary items and to commit changes. import_data
()Method that import the data in cw. schema
(outfname[, text_font, node_text_size])Create a view of the schema described in a python structure. Attributes
assessment_relations
device_relations
fileset_relations
relations
-
__module__
= 'cubes.piws.importer.base'¶
-
_create_assessment
(assessment_struct, subject_eids, study_eid, center_eid, groups)[source]¶ Create an assessment and its associated relations.
The groups that can access the ‘in_assessment’ linked entities are generated dynamically from the assessment identifiers:
- we ‘_’ split the string and create a group with the first returned item and the concatenation of the two first items.
- the permissions ‘can_read’, ‘can_update’ relate the assessments with the corresponding groups.
-
_create_device
(device_struct, center_eid, assessment_eid, center_name)[source]¶ Create a device and its associated relations.
-
_get_or_create_unique_entity
(rql, entity_name, check_unicity=True, *args, **kwargs)[source]¶ Method to create a new unique entity.
First check that the entity do not exists by executing the rql request if ‘check_unicity’ is True.
Parameters: rql: str (madatory) :
the rql request to check unicity.
entity_name: str (madatory) :
the name of the entity we want to create.
check_unicity: bool (optional) :
if True check if the entity already exists in the data base.
Returns: entity: CW entity :
the requested entity.
is_created: bool :
return True if the entity has been created, False otherwise.
-
_import_file_set
(fset_struct, extfiles, parent_eid, assessment_eid)[source]¶ Add the file set attached to a parent entity.
-
_md5_sum
(path)[source]¶ Create a md5 sum of a path.
Parameters: path: str (madatory) :
a string to hash.
Returns: out: str :
the input hashed string.
-
_progress_bar
(ratio, title='', bar_length=40, maxsize=20)[source]¶ Method to generate a progress bar.
Parameters: ratio: float (mandatory 0<ratio<1) :
float describing the current processing status.
title: str (optional) :
a title to identify the progress bar.
bar_length: int (optional) :
the length of the bar that will be ploted.
maxsize: int (optional) :
use to justify title.
-
_set_unique_relation
(source_eid, relation_name, detination_eid, check_unicity=True, subjtype=None)[source]¶ Method to create a new unique relation.
First check that the relation do not exists if ‘check_unicity’ is True.
Parameters: source_eid: int (madatory) :
the CW identifier of the object entity in the relation.
relation_name: str (madatory) :
the relation name.
detination_eid: int (madatory) :
the CW identifier of the subject entity in the relation.
check_unicity: bool (optional) :
if True check if the relation already exists in the data base.
subjtype: str (optional) :
give the subject etype for inlined relation when using a store.
-
assessment_relations
= [('Assessment', 'study', 'Study'), ('Study', 'assessments', 'Assessment'), ('Subject', 'assessments', 'Assessment'), ('Assessment', 'subjects', 'Subject'), ('Center', 'assessments', 'Assessment'), ('Assessment', 'center', 'Center'), ('CWGroup', 'can_read', 'Assessment'), ('CWGroup', 'can_update', 'Assessment'), ('Assessment', 'device', 'Device'), ('Device', 'device_assessments', 'Assessment')]¶
-
device_relations
= [['Scan', 'filesets', 'FileSet'], ('FileSet', 'in_assessment', 'Assessment'), ('FileSet', 'external_files', 'ExternalFile'), ('ExternalFile', 'fileset', 'FileSet'), ('ExternalFile', 'in_assessment', 'Assessment'), ('Device', 'center', 'Center')]¶
-
fileset_relations
= [['Scan', 'filesets', 'FileSet'], ('FileSet', 'in_assessment', 'Assessment'), ('FileSet', 'external_files', 'ExternalFile'), ('ExternalFile', 'fileset', 'FileSet'), ('ExternalFile', 'in_assessment', 'Assessment')]¶
-
relations
= []¶
-
classmethod
schema
(outfname, text_font='sans-serif', node_text_size=12)[source]¶ Create a view of the schema described in a python structure.
Parameters: outfname: str (mandatory) :
the path to the output file where the graph will be saved. The directory containing this file must be created.
text_font: str (optional, default ‘sans-serif’) :
the font used to display the text in the final image.
node_text_size: int (optional, default 12) :
the text size.
-