From bb8adcc0b0730db6a974e637ce2acacc1a3f1f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Artelt?= Date: Wed, 1 May 2024 07:33:59 +0200 Subject: [PATCH] Bugfixes regarding closing EPANET and EPANET-MSX --- epyt/epanet.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/epyt/epanet.py b/epyt/epanet.py index 7155e24..4a9933d 100644 --- a/epyt/epanet.py +++ b/epyt/epanet.py @@ -10379,28 +10379,19 @@ def unload(self): See also epanet, saveInputFile, closeNetwork(). """ try: - self.api.ENclose() + if self.api._ph is not None: + self.api.ENdeleteproject() + else: + self.api.ENclose() finally: try: safe_delete(self.TempInpFile) + files_to_delete = [self.TempInpFile[0:-4] + '.txt', self.InputFile[0:-4] + '.txt', self.BinTempfile] for file in files_to_delete: safe_delete(file) for file in Path(".").glob("@#*.txt"): safe_delete(file) - safe_delete(self.TempInpFile) - - cwd = os.getcwd() - files = os.listdir(cwd) - tmp_files = [ - f for f in files - if os.path.isfile(os.path.join(cwd, f)) and - (f.startswith('s') or f.startswith('en')) and - 5 <= len(f) <= 8 and - "." not in f - ] - tmp_files_paths = [os.path.join(cwd, f) for f in tmp_files] - safe_delete(tmp_files_paths) except: pass print(f'Close toolkit for the input file "{self.netName[0:-4]}". EPANET Toolkit is unloaded.\n') @@ -11259,9 +11250,6 @@ def unloadMSX(self): d.unloadMSX() """ self.msx.MSXclose() - msx_temp_files = list(filter(lambda f: os.path.isfile(os.path.join(os.getcwd(), f)) - and f.startswith("msx") and "." not in f, os.listdir(os.getcwd()))) - safe_delete(msx_temp_files) def getMSXSpeciesCount(self): """ Retrieves the number of species. @@ -13243,8 +13231,6 @@ def ENdeleteproject(self): if self._ph is not None: self.errcode = self._lib.EN_deleteproject(self._ph) - else: - self.errcode = self._lib.ENdeleteproject() self.ENgeterror() return @@ -16280,4 +16266,4 @@ def MSXgeterror(self, err): if e: Warning(errmsg.value.decode()) - return errmsg.value.decode() \ No newline at end of file + return errmsg.value.decode()