@@ -1786,6 +1786,24 @@ parse_table_collection_dict(tsk_table_collection_t *tables, PyObject *tables_dic
1786
1786
return ret ;
1787
1787
}
1788
1788
1789
+ static const char *
1790
+ parse_metadata_schema_arg (PyObject * arg , Py_ssize_t * metadata_schema_length )
1791
+ {
1792
+ const char * ret = NULL ;
1793
+ if (arg == NULL ) {
1794
+ PyErr_Format (
1795
+ PyExc_AttributeError ,
1796
+ "Cannot del metadata_schema, set to empty string (\"\") to clear." );
1797
+ goto out ;
1798
+ }
1799
+ ret = PyUnicode_AsUTF8AndSize (arg , metadata_schema_length );
1800
+ if (ret == NULL ) {
1801
+ goto out ;
1802
+ }
1803
+ out :
1804
+ return ret ;
1805
+ }
1806
+
1789
1807
static int
1790
1808
write_table_arrays (tsk_table_collection_t * tables , PyObject * dict )
1791
1809
{
@@ -2519,16 +2537,10 @@ IndividualTable_set_metadata_schema(IndividualTable *self, PyObject *arg, void *
2519
2537
const char * metadata_schema ;
2520
2538
Py_ssize_t metadata_schema_length ;
2521
2539
2522
- if (arg == NULL ) {
2523
- PyErr_Format (
2524
- PyExc_AttributeError ,
2525
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
2526
- goto out ;
2527
- }
2528
2540
if (IndividualTable_check_state (self ) != 0 ) {
2529
2541
goto out ;
2530
2542
}
2531
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
2543
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
2532
2544
if (metadata_schema == NULL ) {
2533
2545
goto out ;
2534
2546
}
@@ -2995,16 +3007,10 @@ NodeTable_set_metadata_schema(NodeTable *self, PyObject *arg, void *closure)
2995
3007
const char * metadata_schema ;
2996
3008
Py_ssize_t metadata_schema_length ;
2997
3009
2998
- if (arg == NULL ) {
2999
- PyErr_Format (
3000
- PyExc_AttributeError ,
3001
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
3002
- goto out ;
3003
- }
3004
3010
if (NodeTable_check_state (self ) != 0 ) {
3005
3011
goto out ;
3006
3012
}
3007
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
3013
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
3008
3014
if (metadata_schema == NULL ) {
3009
3015
goto out ;
3010
3016
}
@@ -3488,15 +3494,10 @@ EdgeTable_set_metadata_schema(EdgeTable *self, PyObject *arg, void *closure)
3488
3494
const char * metadata_schema ;
3489
3495
Py_ssize_t metadata_schema_length ;
3490
3496
3491
- if (arg == NULL ) {
3492
- PyErr_Format (PyExc_AttributeError ,
3493
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
3494
- goto out ;
3495
- }
3496
3497
if (EdgeTable_check_state (self ) != 0 ) {
3497
3498
goto out ;
3498
3499
}
3499
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
3500
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
3500
3501
if (metadata_schema == NULL ) {
3501
3502
goto out ;
3502
3503
}
@@ -3989,16 +3990,10 @@ MigrationTable_set_metadata_schema(MigrationTable *self, PyObject *arg, void *cl
3989
3990
const char * metadata_schema ;
3990
3991
Py_ssize_t metadata_schema_length ;
3991
3992
3992
- if (arg == NULL ) {
3993
- PyErr_Format (
3994
- PyExc_AttributeError ,
3995
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
3996
- goto out ;
3997
- }
3998
3993
if (MigrationTable_check_state (self ) != 0 ) {
3999
3994
goto out ;
4000
3995
}
4001
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
3996
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
4002
3997
if (metadata_schema == NULL ) {
4003
3998
goto out ;
4004
3999
}
@@ -4453,16 +4448,10 @@ SiteTable_set_metadata_schema(SiteTable *self, PyObject *arg, void *closure)
4453
4448
const char * metadata_schema ;
4454
4449
Py_ssize_t metadata_schema_length ;
4455
4450
4456
- if (arg == NULL ) {
4457
- PyErr_Format (
4458
- PyExc_AttributeError ,
4459
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
4460
- goto out ;
4461
- }
4462
4451
if (SiteTable_check_state (self ) != 0 ) {
4463
4452
goto out ;
4464
4453
}
4465
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
4454
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
4466
4455
if (metadata_schema == NULL ) {
4467
4456
goto out ;
4468
4457
}
@@ -4956,16 +4945,10 @@ MutationTable_set_metadata_schema(MutationTable *self, PyObject *arg, void *clos
4956
4945
const char * metadata_schema ;
4957
4946
Py_ssize_t metadata_schema_length ;
4958
4947
4959
- if (arg == NULL ) {
4960
- PyErr_Format (
4961
- PyExc_AttributeError ,
4962
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
4963
- goto out ;
4964
- }
4965
4948
if (MutationTable_check_state (self ) != 0 ) {
4966
4949
goto out ;
4967
4950
}
4968
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
4951
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
4969
4952
if (metadata_schema == NULL ) {
4970
4953
goto out ;
4971
4954
}
@@ -5375,16 +5358,10 @@ PopulationTable_set_metadata_schema(PopulationTable *self, PyObject *arg, void *
5375
5358
const char * metadata_schema ;
5376
5359
Py_ssize_t metadata_schema_length ;
5377
5360
5378
- if (arg == NULL ) {
5379
- PyErr_Format (
5380
- PyExc_AttributeError ,
5381
- "Cannot del metadata_schema, set to empty string (\"\") to clear." );
5382
- goto out ;
5383
- }
5384
5361
if (PopulationTable_check_state (self ) != 0 ) {
5385
5362
goto out ;
5386
5363
}
5387
- metadata_schema = PyUnicode_AsUTF8AndSize (arg , & metadata_schema_length );
5364
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
5388
5365
if (metadata_schema == NULL ) {
5389
5366
goto out ;
5390
5367
}
@@ -6083,6 +6060,71 @@ TableCollection_get_file_uuid(TableCollection *self, void *closure)
6083
6060
return Py_BuildValue ("s" , self -> tables -> file_uuid );
6084
6061
}
6085
6062
6063
+ static PyObject *
6064
+ TableCollection_get_metadata (TableCollection * self , void * closure )
6065
+ {
6066
+ return PyBytes_FromStringAndSize (self -> tables -> metadata , self -> tables -> metadata_length );
6067
+ }
6068
+
6069
+ static int
6070
+ TableCollection_set_metadata (TableCollection * self , PyObject * arg , void * closure )
6071
+ {
6072
+ int ret = -1 ;
6073
+ int err ;
6074
+ char * metadata ;
6075
+ Py_ssize_t metadata_length ;
6076
+
6077
+ if (arg == NULL ) {
6078
+ PyErr_Format (
6079
+ PyExc_AttributeError ,
6080
+ "Cannot del metadata, set to empty string (b\"\") to clear." );
6081
+ goto out ;
6082
+ }
6083
+ err = PyBytes_AsStringAndSize (arg , & metadata , & metadata_length );
6084
+ if (err != 0 ) {
6085
+ goto out ;
6086
+ }
6087
+ err = tsk_table_collection_set_metadata (
6088
+ self -> tables , metadata , metadata_length );
6089
+ if (err != 0 ) {
6090
+ handle_library_error (err );
6091
+ goto out ;
6092
+ }
6093
+ ret = 0 ;
6094
+ out :
6095
+ return ret ;
6096
+ }
6097
+
6098
+ static PyObject *
6099
+ TableCollection_get_metadata_schema (TableCollection * self , void * closure )
6100
+ {
6101
+ return make_Py_Unicode_FromStringAndLength (
6102
+ self -> tables -> metadata_schema , self -> tables -> metadata_schema_length );
6103
+ }
6104
+
6105
+ static int
6106
+ TableCollection_set_metadata_schema (TableCollection * self , PyObject * arg , void * closure )
6107
+ {
6108
+ int ret = -1 ;
6109
+ int err ;
6110
+ const char * metadata_schema ;
6111
+ Py_ssize_t metadata_schema_length ;
6112
+
6113
+ metadata_schema = parse_metadata_schema_arg (arg , & metadata_schema_length );
6114
+ if (metadata_schema == NULL ) {
6115
+ goto out ;
6116
+ }
6117
+ err = tsk_table_collection_set_metadata_schema (
6118
+ self -> tables , metadata_schema , metadata_schema_length );
6119
+ if (err != 0 ) {
6120
+ handle_library_error (err );
6121
+ goto out ;
6122
+ }
6123
+ ret = 0 ;
6124
+ out :
6125
+ return ret ;
6126
+ }
6127
+
6086
6128
static PyObject *
6087
6129
TableCollection_simplify (TableCollection * self , PyObject * args , PyObject * kwds )
6088
6130
{
@@ -6340,6 +6382,12 @@ static PyGetSetDef TableCollection_getsetters[] = {
6340
6382
(setter ) TableCollection_set_sequence_length , "The sequence length." },
6341
6383
{"file_uuid" , (getter ) TableCollection_get_file_uuid , NULL ,
6342
6384
"The UUID of the corresponding file." },
6385
+ {"metadata" ,
6386
+ (getter ) TableCollection_get_metadata ,
6387
+ (setter ) TableCollection_set_metadata , "The metadata." },
6388
+ {"metadata_schema" ,
6389
+ (getter ) TableCollection_get_metadata_schema ,
6390
+ (setter ) TableCollection_set_metadata_schema , "The metadata schema." },
6343
6391
{NULL } /* Sentinel */
6344
6392
};
6345
6393
@@ -6680,6 +6728,20 @@ TreeSequence_get_site(TreeSequence *self, PyObject *args)
6680
6728
return ret ;
6681
6729
}
6682
6730
6731
+ static PyObject *
6732
+ TreeSequence_get_metadata (TreeSequence * self ) {
6733
+ return PyBytes_FromStringAndSize (
6734
+ self -> tree_sequence -> tables -> metadata ,
6735
+ self -> tree_sequence -> tables -> metadata_length );
6736
+ }
6737
+
6738
+ static PyObject *
6739
+ TreeSequence_get_metadata_schema (TreeSequence * self ) {
6740
+ return make_Py_Unicode_FromStringAndLength (
6741
+ self -> tree_sequence -> tables -> metadata_schema ,
6742
+ self -> tree_sequence -> tables -> metadata_schema_length );
6743
+ }
6744
+
6683
6745
static PyObject *
6684
6746
TreeSequence_get_table_metadata_schemas (TreeSequence * self ) {
6685
6747
PyObject * ret = NULL ;
@@ -8173,6 +8235,10 @@ static PyMethodDef TreeSequence_methods[] = {
8173
8235
METH_NOARGS , "Returns the tree breakpoints as a numpy array." },
8174
8236
{"get_file_uuid" , (PyCFunction ) TreeSequence_get_file_uuid ,
8175
8237
METH_NOARGS , "Returns the UUID of the underlying file, if present." },
8238
+ {"get_metadata" , (PyCFunction ) TreeSequence_get_metadata , METH_NOARGS ,
8239
+ "Returns the metadata for the tree sequence" },
8240
+ {"get_metadata_schema" , (PyCFunction ) TreeSequence_get_metadata_schema , METH_NOARGS ,
8241
+ "Returns the metadata schema for the tree sequence metadata" },
8176
8242
{"get_num_sites" , (PyCFunction ) TreeSequence_get_num_sites ,
8177
8243
METH_NOARGS , "Returns the number of sites" },
8178
8244
{"get_num_mutations" , (PyCFunction ) TreeSequence_get_num_mutations , METH_NOARGS ,
0 commit comments