@@ -80,17 +80,18 @@ def caltechdata_edit(
80
80
# Check if file links were provided in the metadata
81
81
descriptions = []
82
82
ex_file_links = []
83
- for d in metadata ["descriptions" ]:
84
- if d ["description" ].startswith ("Files available via S3" ):
85
- file_text = d ["description" ]
86
- file_list = file_text .split ('href="' )
87
- # Loop over links in description, skip header text
88
- for file in file_list [1 :]:
89
- ex_file_links .append (file .split ('"\n ' )[0 ])
90
- else :
91
- descriptions .append (d )
92
- # We remove file link descriptions, and re-add below
93
- metadata ["descriptions" ] = descriptions
83
+ if "descriptions" in metadata :
84
+ for d in metadata ["descriptions" ]:
85
+ if d ["description" ].startswith ("Files available via S3" ):
86
+ file_text = d ["description" ]
87
+ file_list = file_text .split ('href="' )
88
+ # Loop over links in description, skip header text
89
+ for file in file_list [1 :]:
90
+ ex_file_links .append (file .split ('"\n ' )[0 ])
91
+ else :
92
+ descriptions .append (d )
93
+ # We remove file link descriptions, and re-add below
94
+ metadata ["descriptions" ] = descriptions
94
95
95
96
# If user has provided file links as a cli option, we add those
96
97
if file_links :
@@ -131,7 +132,8 @@ def caltechdata_edit(
131
132
if existing .status_code != 200 :
132
133
raise Exception (f"Record { idv } does not exist, cannot edit" )
133
134
134
- status = existing .json ()["status" ]
135
+ existing = existing .json ()
136
+ status = existing ["status" ]
135
137
136
138
# Determine whether we need a new version
137
139
version = False
@@ -161,7 +163,7 @@ def caltechdata_edit(
161
163
pids = {}
162
164
oai = False
163
165
doi = False
164
- if "identifiers" in metadata :
166
+ if "identifiers" in metadata and version == False :
165
167
for identifier in metadata ["identifiers" ]:
166
168
if identifier ["identifierType" ] == "DOI" :
167
169
doi = True
@@ -198,9 +200,17 @@ def caltechdata_edit(
198
200
"provider" : "datacite" ,
199
201
"client" : "datacite" ,
200
202
}
201
- metadata ["pids" ] = pids
202
203
203
- data = customize_schema .customize_schema (metadata , schema = schema )
204
+ # If no metadata is provided, use existing. Otherwise customize provided
205
+ # metadata
206
+ if metadata == {}:
207
+ data = existing
208
+ if version == True :
209
+ # We want to have the system set new DOIs
210
+ data ["pids" ] = {}
211
+ else :
212
+ metadata ["pids" ] = pids
213
+ data = customize_schema .customize_schema (metadata , schema = schema )
204
214
205
215
if files :
206
216
if default_preview :
0 commit comments