From a2c483826ec5c4a1b64aeaec552409c12fcd0c31 Mon Sep 17 00:00:00 2001 From: maxcapodi78 Date: Tue, 21 Mar 2023 17:46:30 +0100 Subject: [PATCH 1/3] Added Linux support to Console.py_build --- pyaedt/misc/Console.py_build | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pyaedt/misc/Console.py_build b/pyaedt/misc/Console.py_build index 0c25108699c..566b8dcb78e 100644 --- a/pyaedt/misc/Console.py_build +++ b/pyaedt/misc/Console.py_build @@ -22,7 +22,25 @@ pyaedt_toolkit_dir = os.path.normpath(os.path.join(current_dir, r"##TOOLKIT_REL_ python_exe = r"##IPYTHON_EXE##" % version pyaedt_script = os.path.join(pyaedt_toolkit_dir, "console_setup.py") if os.name =="posix": + terminals = ['x-terminal-emulator', 'xterm', 'gnome-terminal', 'konsole', 'lxterminal', 'mlterm'] + term = None + for terminal in terminals: + p = subprocess.Popen(['which',terminal], stdout=subprocess.PIPE) + output = p.stdout.readlines() + if "which: no" in output or output == []: + continue + else: + term = terminal + break + if not term: + oDesktop.AddMessage("", "", 2, "No Terminals found.") + sys.exit() + em_var = "ANSYSEM_ROOT{}".format(version) + os.environ[em_var]= oDesktop.GetExeDir() + command = [ + term, + "-e", '{}'.format(python_exe), "-i", '{}'.format(pyaedt_script), From e58f8f0ad672a745e63837cc7618d4eafdf33eab Mon Sep 17 00:00:00 2001 From: Karan Bhagat Date: Fri, 17 Mar 2023 21:19:29 -0400 Subject: [PATCH 2/3] Toolkit setup to work on Linux --- pyaedt/__init__.py | 2 ++ pyaedt/generic/general_methods.py | 2 ++ pyaedt/misc/aedtlib_personalib_install.py | 33 ++++++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pyaedt/__init__.py b/pyaedt/__init__.py index 5c6f8bc399c..a6e29e2c48b 100644 --- a/pyaedt/__init__.py +++ b/pyaedt/__init__.py @@ -23,6 +23,8 @@ from pyaedt.generic.general_methods import generate_unique_project_name from pyaedt.generic.general_methods import inside_desktop from pyaedt.generic.general_methods import is_ironpython +from pyaedt.generic.general_methods import is_linux +from pyaedt.generic.general_methods import is_windows from pyaedt.generic.general_methods import pyaedt_function_handler from pyaedt.generic.general_methods import settings diff --git a/pyaedt/generic/general_methods.py b/pyaedt/generic/general_methods.py index 6c48414fdc9..78568ba4d41 100644 --- a/pyaedt/generic/general_methods.py +++ b/pyaedt/generic/general_methods.py @@ -26,6 +26,8 @@ from pyaedt.generic.constants import CSS4_COLORS is_ironpython = "IronPython" in sys.version or ".NETFramework" in sys.version +is_linux = os.name == "posix" +is_windows = not is_linux _pythonver = sys.version_info[0] inside_desktop = True if is_ironpython and "4.0.30319.42000" in sys.version else False diff --git a/pyaedt/misc/aedtlib_personalib_install.py b/pyaedt/misc/aedtlib_personalib_install.py index dd4b0b82db2..6775670e423 100644 --- a/pyaedt/misc/aedtlib_personalib_install.py +++ b/pyaedt/misc/aedtlib_personalib_install.py @@ -7,11 +7,13 @@ from xml.etree.ElementTree import ParseError current_dir = os.path.dirname(os.path.realpath(__file__)) -pyaedt_path = os.path.join( - current_dir, - "..", +pyaedt_path = os.path.normpath( + os.path.join( + current_dir, + "..", + ) ) -sys.path.append(os.path.join(pyaedt_path, "..")) +sys.path.append(os.path.normpath(os.path.join(pyaedt_path, ".."))) pid = 0 @@ -28,7 +30,10 @@ def add_pyaedt_to_aedt(aedt_version, is_student_version=False, use_sys_lib=False if os.path.exists(pers1): d.logger.info("PersonalLib already mapped") else: - os.system('mklink /D "{}" "{}"'.format(pers1, pyaedt_path)) + if is_windows(): + os.system('mklink /D "{}" "{}"'.format(pers1, pyaedt_path)) + else: + os.system('ln -s "{}" "{}"'.format(pyaedt_path, pers1)) toolkits = ["Project"] @@ -68,8 +73,8 @@ def install_toolkit(toolkit_dir, product, aedt_version): version_agnostic = True else: executable_version_agnostic = sys.executable - jupyter_executable = executable_version_agnostic.replace("python.exe", "jupyter.exe") - ipython_executable = executable_version_agnostic.replace("python.exe", "ipython.exe") + jupyter_executable = executable_version_agnostic.replace("python" + exe(), "jupyter" + exe()) + ipython_executable = executable_version_agnostic.replace("python" + exe(), "ipython" + exe()) for file_name in files_to_copy: with open(os.path.join(current_dir, file_name + ".py_build"), "r") as build_file: file_name_dest = file_name.replace("_", " ") + ".py" @@ -151,6 +156,20 @@ def write_pretty_xml(root, file_path): f.write(xml_str) +def exe(): + if is_windows(): + return ".exe" + return "" + + +def is_windows(): + return not is_linux() + + +def is_linux(): + return os.name == "posix" + + if __name__ == "__main__": student_version = False if len(sys.argv) < 2: From c283e4f39746b015adfb0d41c612be10a995edfc Mon Sep 17 00:00:00 2001 From: Karan Bhagat Date: Tue, 21 Mar 2023 19:24:41 -0400 Subject: [PATCH 3/3] Enable Linux support for Console Launcher on CentOS - separate out functions --- pyaedt/misc/Console.py_build | 107 +++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/pyaedt/misc/Console.py_build b/pyaedt/misc/Console.py_build index 566b8dcb78e..9dd3f63c876 100644 --- a/pyaedt/misc/Console.py_build +++ b/pyaedt/misc/Console.py_build @@ -10,49 +10,82 @@ interactive Python session. """ import os +import sys if os.name == "posix": import subprocessdotnet as subprocess else: import subprocess -# Launch file -version = oDesktop.GetVersion()[2:6].replace(".", "") -current_dir = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) -pyaedt_toolkit_dir = os.path.normpath(os.path.join(current_dir, r"##TOOLKIT_REL_LIB_DIR##")) -python_exe = r"##IPYTHON_EXE##" % version -pyaedt_script = os.path.join(pyaedt_toolkit_dir, "console_setup.py") -if os.name =="posix": - terminals = ['x-terminal-emulator', 'xterm', 'gnome-terminal', 'konsole', 'lxterminal', 'mlterm'] - term = None - for terminal in terminals: - p = subprocess.Popen(['which',terminal], stdout=subprocess.PIPE) - output = p.stdout.readlines() - if "which: no" in output or output == []: - continue - else: - term = terminal - break - if not term: - oDesktop.AddMessage("", "", 2, "No Terminals found.") - sys.exit() - em_var = "ANSYSEM_ROOT{}".format(version) - os.environ[em_var]= oDesktop.GetExeDir() - - command = [ - term, - "-e", - '{}'.format(python_exe), + +def main(): + # Launch file + version = oDesktop.GetVersion()[2:6].replace(".", "") + current_dir = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) + pyaedt_toolkit_dir = os.path.normpath(os.path.join(current_dir, r"##TOOLKIT_REL_LIB_DIR##")) + python_exe = r"##IPYTHON_EXE##" % version + pyaedt_script = os.path.join(pyaedt_toolkit_dir, "console_setup.py") + if os.name == "posix": + term = get_linux_terminal() + if not term: + oDesktop.AddMessage("", "", 2, "No Terminals found.") + sys.exit() + edt_root = os.path.normpath(oDesktop.GetExeDir()) + os.environ["ANSYSEM_ROOT{}".format(version)] = edt_root + ld_library_path_dirs_to_add = [ + "{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), + "{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), + "{}/common/mono/Linux64/lib64".format(edt_root), + "{}/Delcross".format(edt_root), + "{}".format(edt_root), + ] + os.environ["LD_LIBRARY_PATH"] = ":".join(ld_library_path_dirs_to_add) + ":" + os.getenv("LD_LIBRARY_PATH", "") + + command = [ + term, + "-e", + '{}'.format(python_exe), + "-i", + '{}'.format(pyaedt_script), + str(oDesktop.GetProcessID()), + str(oDesktop.GetVersion()[:6]), + ] + else: + command = [ + '"{}"'.format(python_exe), "-i", - '{}'.format(pyaedt_script), + '"{}"'.format(pyaedt_script), str(oDesktop.GetProcessID()), str(oDesktop.GetVersion()[:6]), ] -else: - command = [ - '"{}"'.format(python_exe), - "-i", - '"{}"'.format(pyaedt_script), - str(oDesktop.GetProcessID()), - str(oDesktop.GetVersion()[:6]), - ] -subprocess.Popen(" ".join(command)) + subprocess.Popen(" ".join(command)) + + +def get_linux_terminal(): + for terminal in ['x-terminal-emulator', 'konsole', 'xterm', 'gnome-terminal', 'lxterminal', 'mlterm']: + term = which(terminal) + if term: + return term + return None + + +def which(program): + # http://stackoverflow.com/a/377028 + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + + +if __name__ == "__main__": + main()