SimulationHelper
1# coding: utf-8 2import os 3import shutil 4import platform 5 6 7class SimulationHelper(object): 8 def __init__(self, less_install_root_path): 9 self.less_install_root_path = less_install_root_path 10 11 def get_less_py_dir(self): 12 currdir = os.path.split(os.path.realpath(__file__))[0] 13 if currdir.startswith(r"E:\03-Coding\lessrt"): 14 __lesspy_dir = r"E:\03-Coding\lessrt\python\lesspy" if platform.system() == "Windows" else "" 15 else: 16 __lesspy_dir = os.path.join(self.less_install_root_path, "app", "bin", "scripts", "Lesspy") \ 17 if platform.system() == "Windows" else "" 18 return __lesspy_dir 19 20 def get_py_interpreter_path(self): 21 currdir = os.path.split(os.path.realpath(__file__))[0] 22 if currdir.startswith(r"E:\03-Coding\lessrt"): 23 __py_interpreter_path = r"E:\03-Coding\lessrt\Utility\Python310\python.exe" if platform.system() == "Windows" else "" 24 else: 25 __py_interpreter_path = os.path.join(self.less_install_root_path, "app", "bin", "python", "python.exe") \ 26 if platform.system() == "Windows" else "" 27 return __py_interpreter_path 28 29 def get_script_less_py_path(self): 30 return os.path.join(self.get_less_py_dir(), "less.py") 31 32 def get_default_config_file(self): 33 return os.path.join(self.get_less_py_dir(), "default.conf") 34 35 def create_new_sim(self, new_sim_path): 36 if not os.path.exists(new_sim_path): 37 os.makedirs(new_sim_path) 38 dirs = os.listdir(new_sim_path) 39 if len(dirs) == 0: 40 cwd = os.getcwd() 41 os.chdir(new_sim_path) 42 interpreter = self.get_py_interpreter_path() 43 script_lesspy_path = self.get_script_less_py_path() 44 os.system(interpreter + " " + script_lesspy_path + " -n") 45 shutil.copy(self.get_default_config_file(), os.path.join(new_sim_path, "Parameters", "input.conf")) 46 os.chdir(cwd) 47 else: 48 print("Warning: The simulation directory is not empty, skip creating")
class
SimulationHelper:
8class SimulationHelper(object): 9 def __init__(self, less_install_root_path): 10 self.less_install_root_path = less_install_root_path 11 12 def get_less_py_dir(self): 13 currdir = os.path.split(os.path.realpath(__file__))[0] 14 if currdir.startswith(r"E:\03-Coding\lessrt"): 15 __lesspy_dir = r"E:\03-Coding\lessrt\python\lesspy" if platform.system() == "Windows" else "" 16 else: 17 __lesspy_dir = os.path.join(self.less_install_root_path, "app", "bin", "scripts", "Lesspy") \ 18 if platform.system() == "Windows" else "" 19 return __lesspy_dir 20 21 def get_py_interpreter_path(self): 22 currdir = os.path.split(os.path.realpath(__file__))[0] 23 if currdir.startswith(r"E:\03-Coding\lessrt"): 24 __py_interpreter_path = r"E:\03-Coding\lessrt\Utility\Python310\python.exe" if platform.system() == "Windows" else "" 25 else: 26 __py_interpreter_path = os.path.join(self.less_install_root_path, "app", "bin", "python", "python.exe") \ 27 if platform.system() == "Windows" else "" 28 return __py_interpreter_path 29 30 def get_script_less_py_path(self): 31 return os.path.join(self.get_less_py_dir(), "less.py") 32 33 def get_default_config_file(self): 34 return os.path.join(self.get_less_py_dir(), "default.conf") 35 36 def create_new_sim(self, new_sim_path): 37 if not os.path.exists(new_sim_path): 38 os.makedirs(new_sim_path) 39 dirs = os.listdir(new_sim_path) 40 if len(dirs) == 0: 41 cwd = os.getcwd() 42 os.chdir(new_sim_path) 43 interpreter = self.get_py_interpreter_path() 44 script_lesspy_path = self.get_script_less_py_path() 45 os.system(interpreter + " " + script_lesspy_path + " -n") 46 shutil.copy(self.get_default_config_file(), os.path.join(new_sim_path, "Parameters", "input.conf")) 47 os.chdir(cwd) 48 else: 49 print("Warning: The simulation directory is not empty, skip creating")
def
get_less_py_dir(self):
12 def get_less_py_dir(self): 13 currdir = os.path.split(os.path.realpath(__file__))[0] 14 if currdir.startswith(r"E:\03-Coding\lessrt"): 15 __lesspy_dir = r"E:\03-Coding\lessrt\python\lesspy" if platform.system() == "Windows" else "" 16 else: 17 __lesspy_dir = os.path.join(self.less_install_root_path, "app", "bin", "scripts", "Lesspy") \ 18 if platform.system() == "Windows" else "" 19 return __lesspy_dir
def
get_py_interpreter_path(self):
21 def get_py_interpreter_path(self): 22 currdir = os.path.split(os.path.realpath(__file__))[0] 23 if currdir.startswith(r"E:\03-Coding\lessrt"): 24 __py_interpreter_path = r"E:\03-Coding\lessrt\Utility\Python310\python.exe" if platform.system() == "Windows" else "" 25 else: 26 __py_interpreter_path = os.path.join(self.less_install_root_path, "app", "bin", "python", "python.exe") \ 27 if platform.system() == "Windows" else "" 28 return __py_interpreter_path
def
create_new_sim(self, new_sim_path):
36 def create_new_sim(self, new_sim_path): 37 if not os.path.exists(new_sim_path): 38 os.makedirs(new_sim_path) 39 dirs = os.listdir(new_sim_path) 40 if len(dirs) == 0: 41 cwd = os.getcwd() 42 os.chdir(new_sim_path) 43 interpreter = self.get_py_interpreter_path() 44 script_lesspy_path = self.get_script_less_py_path() 45 os.system(interpreter + " " + script_lesspy_path + " -n") 46 shutil.copy(self.get_default_config_file(), os.path.join(new_sim_path, "Parameters", "input.conf")) 47 os.chdir(cwd) 48 else: 49 print("Warning: The simulation directory is not empty, skip creating")