Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Linux support to Console.py_build #2670

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyaedt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions pyaedt/generic/general_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
89 changes: 70 additions & 19 deletions pyaedt/misc/Console.py_build
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +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":
command = [
'{}'.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()
33 changes: 26 additions & 7 deletions pyaedt/misc/aedtlib_personalib_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down