From 70cc659c147198c2555246f6af737c4eb019e25a Mon Sep 17 00:00:00 2001 From: Koa Wells Date: Tue, 12 Sep 2023 14:57:13 -0400 Subject: [PATCH 1/3] Add load_compressed function to city.py --- hub/city_model_structure/city.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hub/city_model_structure/city.py b/hub/city_model_structure/city.py index 567b1937..37c8d30e 100644 --- a/hub/city_model_structure/city.py +++ b/hub/city_model_structure/city.py @@ -299,6 +299,21 @@ class City: with open(city_filename, 'rb') as file: return pickle.load(file) + @staticmethod + def load_compressed(compressed_city_filename, destination_filename) -> City: + """ + Load the pickle file name in the current city + :param source_file: Compressed pickle as source + :param destination_file: Pickle file as destination + :return: City + """ + with open(str(compressed_city_filename), 'rb') as source, open(str(destination_filename), 'wb') as destination: + destination.write(bz2.decompress(source.read())) + return City.load(destination_filename) + + @staticmethod + def load_compressed(city_filename, ): + def save(self, city_filename): """ Save a city into the given filename From 29ba43f1d95e379b0d83acb0dc13ce1369b181bd Mon Sep 17 00:00:00 2001 From: Koa Wells Date: Tue, 12 Sep 2023 14:59:44 -0400 Subject: [PATCH 2/3] Update function comment and remove empty function --- hub/city_model_structure/city.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hub/city_model_structure/city.py b/hub/city_model_structure/city.py index 37c8d30e..8b6014bc 100644 --- a/hub/city_model_structure/city.py +++ b/hub/city_model_structure/city.py @@ -302,18 +302,15 @@ class City: @staticmethod def load_compressed(compressed_city_filename, destination_filename) -> City: """ - Load the pickle file name in the current city - :param source_file: Compressed pickle as source - :param destination_file: Pickle file as destination + Load a city from compressed_city_filename + :param compressed_city_filename: Compressed pickle as source + :param destination_filename: Pickle file as destination :return: City """ with open(str(compressed_city_filename), 'rb') as source, open(str(destination_filename), 'wb') as destination: destination.write(bz2.decompress(source.read())) return City.load(destination_filename) - @staticmethod - def load_compressed(city_filename, ): - def save(self, city_filename): """ Save a city into the given filename From a97c0685134cf39c235a512866ee2bf859f0b9a2 Mon Sep 17 00:00:00 2001 From: Koa Wells Date: Wed, 4 Oct 2023 15:11:35 -0400 Subject: [PATCH 3/3] Add removal of decompressed pickle file --- hub/city_model_structure/city.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hub/city_model_structure/city.py b/hub/city_model_structure/city.py index 8b6014bc..97000fbb 100644 --- a/hub/city_model_structure/city.py +++ b/hub/city_model_structure/city.py @@ -14,6 +14,7 @@ import math import pickle import sys import pathlib +import os from pathlib import Path from typing import List, Union @@ -309,7 +310,9 @@ class City: """ with open(str(compressed_city_filename), 'rb') as source, open(str(destination_filename), 'wb') as destination: destination.write(bz2.decompress(source.read())) - return City.load(destination_filename) + loaded_city = City.load(destination_filename) + os.unlink(destination_filename) + return loaded_city def save(self, city_filename): """