The zenodo
submodule
This module provides functions to:
- handle the publication of datasets after they have been validated using safedata_validate, including the generation of HTML descriptions of datasets.
- maintain local copies of datasets in the folder structure expected by the safedata R package.
- compile a RIS format bibliographic file for published datasets.
create_deposit(concept_id=None, resources=None)
Create a new deposit.
Creates a new deposit draft, possibly as a new version of an existing published record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
concept_id |
int | None
|
An optional concept id of a published record to create a new version of an existing dataset. |
None
|
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
get_deposit(deposit_id, resources=None)
Download the metadata of a Zenodo deposit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deposit_id |
int
|
The Zenodo record id of an existing dataset. |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
upload_metadata(metadata, zenodo, resources=None)
Upload dataset metadata.
Takes a dictionary of dataset metadata, converts it to a JSON payload of Zenodo metadata and uploads it to a deposit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
dict
|
The metadata dictionary for a dataset |
required |
zenodo |
dict
|
The zenodo metadata dictionary for a deposit |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
update_published_metadata(zenodo, resources=None)
Update published deposit metadata.
Updates the metadata on a published deposit, for example to modify the access status of deposit. In general, metadata should be updated by releasing a new version of the dataset, and this function should only be used where it is essential that the published version by altered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zenodo |
dict
|
A Zenodo metadata dictionary, with an updated metadata section |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
upload_file(metadata, filepath, zenodo_filename=None, progress_bar=True, resources=None)
Upload a file to Zenodo.
Uploads the contents of a specified file to an unpublished Zenodo deposit, optionally using an alternative filename. If the file already exists in the deposit, it will be replaced.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
dict
|
The Zenodo metadata dictionary for a deposit |
required |
filepath |
str
|
The path to the file to be uploaded |
required |
zenodo_filename |
str | None
|
An optional alternative file name to be used on Zenodo |
None
|
progress_bar |
bool
|
Should the upload progress be displayed |
True
|
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
discard_deposit(metadata, resources=None)
Discard a deposit.
Deposits can be discarded - the associated files and metadata will be deleted and the Zenodo ID no longer exists. Once deposits are published to records, they cannot be deleted via the API - contact the Zenodo team for help.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
dict
|
The Zenodo metadata dictionary for a deposit |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
publish_deposit(zenodo, resources=None)
Publish a created deposit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zenodo |
dict
|
The dataset metadata dictionary for a deposit |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|
delete_file(metadata, filename, resources=None)
Delete an uploaded file from an unpublished Zenodo deposit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
dict
|
The Zenodo metadata dictionary for a deposit |
required |
filename |
str
|
The file to delete from the deposit |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
ZenodoFunctionResponseType
|
See here. |
Source code in safedata_validator/zenodo.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
|
dataset_description(dataset_metadata, zenodo_metadata, render=True, extra=None, resources=None)
Create an HTML dataset description.
This function turns a dataset metadata JSON into html for inclusion in published datasets. This content is used to populate the dataset description section in the Zenodo metadata. Zenodo has a limited set of permitted HTML tags, so this is quite simple HTML.
The available tags are: a, p, br, blockquote, strong, b, u, i, em, ul, ol,
li, sub, sup, div, strike. Note that <a>
is currently only available on
Zenodo when descriptions are uploaded programmatically as a bug in their
web interface strips links.
The description can be modified for specific uses by including HTML via the extra argument. This content is inserted below the dataset description.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_metadata |
dict
|
The dataset metadata |
required |
zenodo_metadata |
dict
|
The Zenodo deposit metadata |
required |
render |
bool
|
Should the html be returned as text or as the underlying dominate.tags.div object. |
True
|
extra |
str | None
|
Additional HTML content to include in the description. |
None
|
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
Returns:
Type | Description |
---|---|
div | str
|
Either a string of rendered HTML or a dominate.tags.div object. |
Source code in safedata_validator/zenodo.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
|
table_description(tab)
Convert a dict containing table contents into an HTML table.
Function to return a description for an individual source file in a dataset. Typically datasets only have a single source file - the Excel workbook that also contains the metadata - but they may also report on external files loaded directly to Zenodo, and which uses the same mechanism.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tab |
dict
|
A dict describing a data table |
required |
Returns:
Type | Description |
---|---|
div
|
A |
Source code in safedata_validator/zenodo.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
|
generate_inspire_xml(dataset_metadata, zenodo_metadata, resources, lineage_statement=None)
Convert dataset and zenodo metadata into GEMINI XML.
Produces an INSPIRE/GEMINI formatted XML record from dataset metadata,
and Zenodo record metadata using a template XML file. The dataset URL
defaults to the Zenodo record but can be replaced if a separate URL (such as
a project specific website) is used. The Gemini XML standard requires a
statement about the lineage of a dataset - this is automatically taken from the
package configuration but can be overridden for individual datasets, for example to
add dataset specific links, using the lineage_statement
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_metadata |
dict
|
A dictionary of the dataset metadata |
required |
zenodo_metadata |
dict
|
A dictionary of the Zenodo record metadata |
required |
resources |
Resources
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
required |
lineage_statement |
str | None
|
An optional alternative lineage statement about the data. |
None
|
Returns:
Type | Description |
---|---|
str
|
A string containing GEMINI compliant XML. |
Source code in safedata_validator/zenodo.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
|
download_ris_data(resources=None, ris_file=None)
Downloads Zenodo records into a RIS format bibliography file.
This function is used to maintain a bibliography file of the records uploaded to a safedata community on Zenodo. It accesses the Zenodo community specified in the resource configuration and downloads all records. It then optionally checks the list of downloaded DOIs against the content of an existing RIS file and then downloads citations for all new DOIs from datacite.org.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
ris_file |
str | None
|
The path to an existing RIS format file containing previously downloaded records. |
None
|
Returns:
Type | Description |
---|---|
None
|
A list of strings containing RIS formatted citation data. |
Source code in safedata_validator/zenodo.py
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
|
sync_local_dir(datadir, xlsx_only=True, replace_modified=False, resources=None)
Synchronise a local data directory with a Zenodo community.
The safedata R package defines a directory structure used to store metadata and files downloaded from a safedata community on Zenodo and from a safedata metadata server. This tool allows a safedata developer or community maintainer to create or update such a directory with all of the resources in the Zenodo community, regardless of their public access status. This forms a backup (although Zenodo is heavily backed up) but also provides local copies of the files for testing and development of the code packages.
This function requires that the resources are configured with access tokens for Zenodo and the details of the metadata server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datadir |
str
|
The path to a local directory containing an existing safedata directory or an empty folder in which to create one. |
required |
resources |
Resources | None
|
The safedata_validator resource configuration to be used. If none is provided, the standard locations are checked. |
None
|
xlsx_only |
bool
|
Should the download ignore large non-xlsx files, defaulting to True. |
True
|
replace_modified |
bool
|
Should the synchronisation replace locally modified files with the archived version. By default, modified local files are left alone. |
False
|
Source code in safedata_validator/zenodo.py
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 |
|
taxon_index_to_text(taxa, html=False, indent_width=4, auth='GBIF')
Render a taxon index as text or html.
This function takes a taxon index and renders the contents into either a text or
html representation of the taxonomic hierarchy used in the dataset. Taxonomic ranks
are indented to render a nested hierarchy. The auth
argument is used to set
whether the taxa are validated using GBIF or NCBI and this only affects the
formatting of the names in the representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxa |
list[dict]
|
A list of taxon dictionaries containing the taxa for a dataset. |
required |
html |
bool
|
Render as html or text. |
False
|
indent_width |
int
|
The indentation width to use for successive taxonomic ranks. |
4
|
auth |
str
|
The taxonomic authority that the taxa are taken from. |
'GBIF'
|
Returns:
Type | Description |
---|---|
str | div
|
Either a HTML or text representation of the taxa tree. |
Source code in safedata_validator/taxa.py
2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 |
|
ZenodoFunctionResponseType = tuple[dict, Optional[str]]
module-attribute
Function return value
The functions interacting with Zenodo all return a common format of tuple of length 2:
- A dictionary containing the response content. For responses that do not generate a response content but just indicate success via HTTP status codes, an empty dictionary is returned. An empty dictionary is also returned when the function results in an error.
- An error message on failure or None on success
So, for example:
({'key': 'value'}, None)
({}, 'Something went wrong')
The expected use pattern is then:
response, error = zenodo_function(args)