Skip to content

Commit

Permalink
Merge branch 'mets-server-reload'
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Oct 19, 2023
2 parents abc48ff + e41020b commit 96c2529
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ocrd/ocrd/mets_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def __str__(self):
def workspace_path(self):
return self.session.request('GET', f'{self.url}/workspace_path').text

def reload(self):
return self.session.request('POST', f'{self.url}/reload').text

@deprecated_alias(ID="file_id")
@deprecated_alias(pageId="page_id")
@deprecated_alias(fileGrp="file_grp")
Expand Down Expand Up @@ -283,6 +286,11 @@ async def unique_identifier():
async def workspace_path():
return Response(content=workspace.directory, media_type="text/plain")

@app.post('/reload')
async def workspace_reload_mets():
workspace.reload_mets()
return Response(content=f'Reloaded from {workspace.directory}', media_type="text/plain")

@app.delete('/')
async def stop():
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/test_mets_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,18 @@ def test_find_all_files(start_mets_server):
assert len(workspace_server.mets.find_all_files(pageId='//PHYS_000(1|2)')) == 34, '34 files in PHYS_001 and PHYS_0002'
assert len(workspace_server.mets.find_all_files(pageId='//PHYS_0001,//PHYS_0005')) == 18, '18 files in PHYS_001 and PHYS_0005 (two regexes)'
assert len(workspace_server.mets.find_all_files(pageId='//PHYS_0005,PHYS_0001..PHYS_0002')) == 35, '35 files in //PHYS_0005,PHYS_0001..PHYS_0002'

def test_reload(start_mets_server):
_, workspace_server = start_mets_server
workspace_server_copy = Workspace(Resolver(), workspace_server.directory)
assert len(workspace_server.mets.find_all_files()) == 35, '35 files total'
assert len(workspace_server_copy.mets.find_all_files()) == 35, '35 files total'

workspace_server_copy.add_file('FOO', ID='foo', mimetype='foo/bar', local_filename='mets.xml', pageId='foo')
assert len(workspace_server.mets.find_all_files()) == 35, '35 files total'
assert len(workspace_server_copy.mets.find_all_files()) == 36, '36 files total'

workspace_server_copy.save_mets()
print(workspace_server.mets.reload())
assert len(workspace_server.mets.find_all_files()) == 36, '36 files total'

0 comments on commit 96c2529

Please sign in to comment.