Skip to content

Commit 734906e

Browse files
committed
support localhost testing and repos with no reocrds
1 parent 615084f commit 734906e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

iga/invenio.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,19 @@ def invenio_server_name(server_url):
121121
server_host = netloc(server_url)
122122
endpoint = '/api/records?size=1'
123123
try:
124-
log(f'testing if we can reach {server_url} in 5 sec or less')
125-
socket.setdefaulttimeout(5)
126-
# If the next one can't reach the host, it'll throw an exception.
127-
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((server_host, 443))
128-
# If we can reach the host, check that it responds to the API endpoint.
129124
if response := network('get', server_url + endpoint):
130125
log(f'we can reach {server_url} and it responds to {endpoint}')
131126
data = response.json()
132-
record = data.get('hits', {}).get('hits', {})[0]
133-
if publisher := record.get('metadata', {}).get('publisher'):
134-
return publisher
127+
records = data.get('hits', {}).get('hits', {})
128+
if records:
129+
if publisher := records[0].get('metadata', {}).get('publisher'):
130+
return publisher
131+
else:
132+
# Fall back to the host name
133+
return server_host
135134
else:
136135
# Fall back to the host name.
137136
return server_host
138-
return record['metadata']['publisher']
139137
except KeyboardInterrupt:
140138
raise
141139
except socket.error:

0 commit comments

Comments
 (0)