Quellcode durchsuchen

Fixed error in btr downloading script (trying to unlock files not yet known to datalad)

Johannes Gütschow vor 2 Monaten
Ursprung
Commit
cbb4d83e6c
1 geänderte Dateien mit 7 neuen und 1 gelöschten Zeilen
  1. 7 1
      src/unfccc_ghg_data/unfccc_downloader/download_btr.py

+ 7 - 1
src/unfccc_ghg_data/unfccc_downloader/download_btr.py

@@ -162,7 +162,13 @@ if __name__ == "__main__":
                         # unlock files in folder as they might be updated by the zip
                         # file. Sometimes a new zip file contains files with the same
                         # name (updated) as older zip files
-                        dlds.unlock(local_filename.parent)
+                        # as we can't unlock files which have just been added we catch
+                        # and discard exceptions
+                        for file in local_filename.parent.glob():
+                            try:
+                                dlds.unlock(file)
+                            except Exception:  # noqa: S110
+                                pass
                         zipped_file = zipfile.ZipFile(str(local_filename), "r")
                         zipped_file.extractall(str(local_filename.parent))
                         print(f"Extracted {len(zipped_file.namelist())} files.")