hnesk/browse-ocrd

chdir to workspace

Closed this issue · 1 comments

Since merging editable, there's a new problem: If I pass a filesystem path for METS on the command line that does not resolve to the current working directory, or if I select a METS in the open dialog that is in another directory, then as soon as I try to open the PageView or TextView, it crashes with the following trace:

  File "ocrd_browser/view/base.py", line 66, in <lambda>
    configurator.connect('changed', lambda _source, *value: self.config_changed(name, value))
  File "ocrd_browser/view/text.py", line 45, in config_changed
    self.reload()
  File "ocrd_browser/view/base.py", line 86, in reload
    self.current = self.document.page_for_id(self.page_id, self.use_file_group)
  File "ocrd_browser/model/document.py", line 356, in page_for_id
    image, _, _ = self.workspace.image_from_page(pcgts.get_Page(), page_id)
  File "ocrd/workspace.py", line 419, in image_from_page
    page_image_info = self.resolve_image_exif(page.imageFilename)
  File "ocrd/workspace.py", line 271, in resolve_image_exif
    ocrd_exif = exif_from_filename(image_filename)
  File "ocrd_modelfactory/__init__.py", line 32, in exif_from_filename
    with Image.open(image_filename) as pil_img:
  File "PIL/Image.py", line 2878, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: 'OCR-D-IMG/OCR-D-IMG_0001.tif'

This looks like we should chdir to the workspace directory after opening it (as all processors do; most core classes were written for them).

Thanks @hnesk!