Skip to content

Commit

Permalink
fix: resuse temp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
merydian committed Feb 13, 2024
1 parent 47d5b16 commit 1d6960f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ def __init__(self, iface, parent=None):
self.checkBox_elevation_profile.toggled.connect(self.toggle_elevation_profile)

def update_elevation_profile(self):
Elevation(self).make_image()
elev = Elevation(self)
elev.make_image()

def toggle_elevation_profile(self):
if self.routing_fromline_list.count() not in [0, 1]:
Expand Down
13 changes: 11 additions & 2 deletions ORStools/utils/elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self, dlg):
self.route = None

self.base()
self.make_image()

def base(self):
basepath = os.path.dirname(__file__)
Expand Down Expand Up @@ -200,7 +199,17 @@ def make_image(self):
ax.set_xlabel("Distance [km]")
ax.set_ylabel("Elevation [m]")

temp_dir = tempfile.mkdtemp(prefix="ORS_qgis_plugin_")
present = None
prefix = "ORS_qgis_plugin_"
for dirpath, dirnames, filenames in os.walk(tempfile.gettempdir()):
for dirname in dirnames:
if prefix in dirname:
temp_dir = os.path.join(dirpath, dirname)
present = True

if not present:
temp_dir = tempfile.mkdtemp(prefix=prefix)

temp_image_path = os.path.join(temp_dir, "elevation_profile.jpg")
fig.savefig(temp_image_path, dpi=100)

Expand Down

0 comments on commit 1d6960f

Please sign in to comment.