From 0810c8b9b0a215aff485bf2b04176466fa149943 Mon Sep 17 00:00:00 2001 From: xywei Date: Mon, 25 Jun 2018 07:20:40 -0500 Subject: [PATCH 1/4] Add an option to keep the tmp dir --- gmsh_interop/runner.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/gmsh_interop/runner.py b/gmsh_interop/runner.py index 6991718..b4a8478 100644 --- a/gmsh_interop/runner.py +++ b/gmsh_interop/runner.py @@ -95,7 +95,7 @@ class GmshRunner(object): def __init__(self, source, dimensions=None, order=None, incomplete_elements=None, other_options=[], extension="geo", gmsh_executable="gmsh", - output_file_name="output.msh"): + output_file_name="output.msh", keep_tmp_dir=False): if isinstance(source, str): from warnings import warn warn("passing a string as 'source' is deprecated--use " @@ -111,6 +111,7 @@ class GmshRunner(object): self.other_options = other_options self.gmsh_executable = gmsh_executable self.output_file_name = output_file_name + self.keep_tmp_dir = keep_tmp_dir if dimensions not in [1, 2, 3, None]: raise RuntimeError("dimensions must be one of 1,2,3 or None") @@ -197,6 +198,24 @@ class GmshRunner(object): self.output_file = open(output_file_name, "r") + if self.keep_tmp_dir: + import shutil, errno + try: + shutil.copytree(working_dir, "./gmsh_tmp") + except FileExistsError as exc: + import select, sys + print("File ./gmsh_tmp exists! Overwrite? (Y/N, will default to Y in 10sec).") + i, o, e = select.select([sys.stdin], [], [], 10) + if i == "N": + pass + else: + shutil.rmtree("./gmsh_tmp") + shutil.copytree(working_dir, "./gmsh_tmp") + except OSError as exc: + if exc.errno == errno.ENOTDIR: + shutil.copy(output_file_name, "./" + self.output_file_name) + else: raise + self.temp_dir_mgr = temp_dir_mgr return self except: -- GitLab From 128f4a517c3ca5e6297db9b5a3456ff9cee2a319 Mon Sep 17 00:00:00 2001 From: xywei Date: Sat, 26 Jan 2019 20:24:16 -0600 Subject: [PATCH 2/4] Bug fixes --- gmsh_interop/runner.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gmsh_interop/runner.py b/gmsh_interop/runner.py index 2dc73b3..43067cb 100644 --- a/gmsh_interop/runner.py +++ b/gmsh_interop/runner.py @@ -126,7 +126,7 @@ class GmshRunner(object): extension="geo", gmsh_executable="gmsh", output_file_name="output.msh", target_unit=None, - keep_tmp_dir=False) + keep_tmp_dir=False): if isinstance(source, str): from warnings import warn warn("passing a string as 'source' is deprecated--use " @@ -169,7 +169,9 @@ class GmshRunner(object): from pytools.prefork import call_capture_output retcode, stdout, stderr = call_capture_output(cmdline) - version = stderr.decode().strip() + # stderr can contain irregular info + import re + version = re.search(r'[0-9].[0-9].[0-9]', stderr.decode().strip()).group() return LooseVersion(version) def __enter__(self): -- GitLab From 66cd4f1c241e44fa24099202c99b4c227b841370 Mon Sep 17 00:00:00 2001 From: xywei Date: Sun, 17 Feb 2019 21:34:21 -0600 Subject: [PATCH 3/4] Resolve github discussion --- gmsh_interop/runner.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/gmsh_interop/runner.py b/gmsh_interop/runner.py index 43067cb..f2fb1c8 100644 --- a/gmsh_interop/runner.py +++ b/gmsh_interop/runner.py @@ -126,7 +126,7 @@ class GmshRunner(object): extension="geo", gmsh_executable="gmsh", output_file_name="output.msh", target_unit=None, - keep_tmp_dir=False): + save_tmp_files_in=None): if isinstance(source, str): from warnings import warn warn("passing a string as 'source' is deprecated--use " @@ -148,7 +148,7 @@ class GmshRunner(object): self.other_options = other_options self.gmsh_executable = gmsh_executable self.output_file_name = output_file_name - self.keep_tmp_dir = keep_tmp_dir + self.save_tmp_files_in = save_tmp_files_in self.target_unit = target_unit.upper() if self.dimensions not in [1, 2, 3, None]: @@ -171,7 +171,7 @@ class GmshRunner(object): # stderr can contain irregular info import re - version = re.search(r'[0-9].[0-9].[0-9]', stderr.decode().strip()).group() + version = re.search(r'[0-9]+.[0-9]+.[0-9]+', stderr.decode().strip()).group() return LooseVersion(version) def __enter__(self): @@ -280,22 +280,34 @@ class GmshRunner(object): self.output_file = open(output_file_name, "r") - if self.keep_tmp_dir: + if self.save_tmp_files_in: import shutil, errno try: - shutil.copytree(working_dir, "./gmsh_tmp") + shutil.copytree(working_dir, self.save_tmp_files_in) except FileExistsError as exc: import select, sys - print("File ./gmsh_tmp exists! Overwrite? (Y/N, will default to Y in 10sec).") - i, o, e = select.select([sys.stdin], [], [], 10) - if i == "N": + print("%s exists! Overwrite? (Y/N, will default to Y in 10sec)." + % self.save_tmp_files_in) + decision = None + while not decision: + i, o, e = select.select([sys.stdin], [], [], 10) + if i == "N" or i == "n": + decision = 0 + elif i == "Y" or i == "y" or not i: + decision = 1 + else: + print("Illegal input %s, please retry." % i) + if decision == 0: pass else: - shutil.rmtree("./gmsh_tmp") - shutil.copytree(working_dir, "./gmsh_tmp") + assert decision == 1: + shutil.rmtree(self.save_tmp_files_in) + shutil.copytree(working_dir, self.save_tmp_files_in) except OSError as exc: if exc.errno == errno.ENOTDIR: - shutil.copy(output_file_name, "./" + self.output_file_name) + shutil.copy(output_file_name, + '/'.join([self.save_tmp_files_in, + self.output_file_name])) else: raise self.temp_dir_mgr = temp_dir_mgr -- GitLab From 1ac941b03b5c1d644da89684bfcf83b657913fa8 Mon Sep 17 00:00:00 2001 From: xywei Date: Sun, 17 Feb 2019 21:38:43 -0600 Subject: [PATCH 4/4] Bug fix --- gmsh_interop/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gmsh_interop/runner.py b/gmsh_interop/runner.py index f2fb1c8..9ef66e1 100644 --- a/gmsh_interop/runner.py +++ b/gmsh_interop/runner.py @@ -300,7 +300,7 @@ class GmshRunner(object): if decision == 0: pass else: - assert decision == 1: + assert decision == 1 shutil.rmtree(self.save_tmp_files_in) shutil.copytree(working_dir, self.save_tmp_files_in) except OSError as exc: -- GitLab