@@ -80,17 +80,18 @@ def caltechdata_edit(
8080 # Check if file links were provided in the metadata
8181 descriptions = []
8282 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
9495
9596 # If user has provided file links as a cli option, we add those
9697 if file_links :
@@ -131,7 +132,8 @@ def caltechdata_edit(
131132 if existing .status_code != 200 :
132133 raise Exception (f"Record { idv } does not exist, cannot edit" )
133134
134- status = existing .json ()["status" ]
135+ existing = existing .json ()
136+ status = existing ["status" ]
135137
136138 # Determine whether we need a new version
137139 version = False
@@ -161,7 +163,7 @@ def caltechdata_edit(
161163 pids = {}
162164 oai = False
163165 doi = False
164- if "identifiers" in metadata :
166+ if "identifiers" in metadata and version == False :
165167 for identifier in metadata ["identifiers" ]:
166168 if identifier ["identifierType" ] == "DOI" :
167169 doi = True
@@ -198,9 +200,17 @@ def caltechdata_edit(
198200 "provider" : "datacite" ,
199201 "client" : "datacite" ,
200202 }
201- metadata ["pids" ] = pids
202203
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 )
204214
205215 if files :
206216 if default_preview :
0 commit comments