Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download remote files on demand #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ocrd_browser/model/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def path(self, other: Union[OcrdFile, Path, str]) -> Optional[Path]:
if not self.directory:
return None
if isinstance(other, OcrdFile):
if not other.local_filename:
other = self.workspace.download_file(other)
return self.directory.joinpath(other.local_filename)
elif isinstance(other, Path):
return self.directory.joinpath(other)
Expand Down Expand Up @@ -258,7 +260,7 @@ def get_image_paths(self, file_group: FileGroupHandle) -> Dict[str, Path]:
for page_id in self.page_ids:
images = [image for image in file_index.values() if image.static_page_id == page_id and file_group.match(image)]
if len(images) > 0:
image_paths[page_id] = self.directory.joinpath(images[0].local_filename)
image_paths[page_id] = self.path(images[0])
else:
log.warning('Found no images for PAGE %s and fileGrp %s', page_id, file_group)
image_paths[page_id] = None
Expand Down Expand Up @@ -319,7 +321,7 @@ def page_for_file(self, page_file: OcrdFile) -> PcGtsType:

def resolve_image(self, image_file: OcrdFile) -> Image:
with pushd_popd(self.workspace.directory):
pil_image = Image.open(self.workspace.download_file(image_file).local_filename)
pil_image = Image.open(self.path(image_file))
# pil_image.load()
return pil_image

Expand Down