Skip to content

Improve rpyc on linux supporting also relative ansysedt path #993

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

Merged
merged 5 commits into from
Mar 24, 2022
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
5 changes: 4 additions & 1 deletion pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,10 @@ def export_profile(self, setup_name, variation_string="", file_path=None):
"""
if not file_path:
file_path = os.path.join(self.working_directory, generate_unique_name("Profile") + ".prop")
self.odesign.ExportProfile(setup_name, variation_string, file_path)
try:
self.odesign.ExportProfile(setup_name, variation_string, file_path)
except:
self.odesign.ExportProfile(setup_name, variation_string, file_path, True)
self.logger.info("Exported Profile to file {}".format(file_path))
return file_path

Expand Down
5 changes: 4 additions & 1 deletion pyaedt/application/MessageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def _log_on_screen(self, val):
def logger(self):
"""Aedt Logger object."""
if self._log_on_file:
return logging.getLogger(__name__)
try:
return logging.getLogger(__name__)
except:
return None
else:
return None # pragma: no cover

Expand Down
16 changes: 11 additions & 5 deletions pyaedt/common_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def connect(server_name, aedt_client_port):
return "Error. No connection. Check if AEDT is running and if the port number is correct."


def client(server_name, server_port=18000, beta_options=None):
def client(server_name, server_port=18000, beta_options=None, use_aedt_relative_path=False):
"""Starts an rpyc client and connects to a remote machine.

Parameters
Expand All @@ -206,7 +206,8 @@ def client(server_name, server_port=18000, beta_options=None):
Port that the rpyc server is running on.
beta_options : list, optional
List of beta options to apply to the new service. The default is ``None``.

use_aedt_relative_path : bool, optional
Whether to use aedt executable full path or relative path call. Needed in case linux environment is defined.
Returns
-------
rpyc object.
Expand Down Expand Up @@ -253,7 +254,7 @@ def client(server_name, server_port=18000, beta_options=None):
if not c:
print("Failing to connect to {} on port {}. Check the settings".format(server_name, server_port))
return False
port = c.root.start_service(server_name, beta_options)
port = c.root.start_service(server_name, beta_options, use_aedt_relative_path=use_aedt_relative_path)
if not port:
return "Error connecting to the server. Check the server name and port and retry."
print("Connecting to a new session of AEDT on port {}. Wait.".format(port))
Expand Down Expand Up @@ -363,7 +364,9 @@ def _download_dir(remotepath, localpath, server_name, server_port=18000):
_download_file(rfn, lfn, server_name, server_port=18000)


def launch_ironpython_server(aedt_path, non_graphical=False, port=18000, launch_client=True):
def launch_ironpython_server(
aedt_path, non_graphical=False, port=18000, launch_client=True, use_aedt_relative_path=False
):
"""Start a process in IronPython and launch the rpc server on the specified port given an AEDT path on Linux.

.. warning::
Expand All @@ -382,6 +385,9 @@ def launch_ironpython_server(aedt_path, non_graphical=False, port=18000, launch_
Port number. The default is ``18000``.
launch_client : bool, optional
Whether to launch the client. The default is ``True.``
use_aedt_relative_path : bool, optional
Whether to use aedt executable full path or relative path call. Needed in case linux environment is defined.
aedt_path parameter is still needed since it is necessary to retrieve ipy64.exe full path.

Returns
-------
Expand Down Expand Up @@ -422,5 +428,5 @@ def launch_ironpython_server(aedt_path, non_graphical=False, port=18000, launch_
print("Known issues are in the returned list and dictionary.")
print("For these known issues, using the method client.convert_remote_object is recommended.")
if proc and launch_client:
return client(server_name=socket.getfqdn(), server_port=port1)
return client(server_name=socket.getfqdn(), server_port=port1, use_aedt_relative_path=use_aedt_relative_path)
return False
13 changes: 10 additions & 3 deletions pyaedt/edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,19 @@ def import_layout_pcb(
command += ".exe"
if not working_dir:
working_dir = os.path.dirname(input_file)
cmd_translator = '"{}" "{}" "{}"'.format(command, input_file, os.path.join(working_dir, aedb_name))
cmd_translator += ' -l="{}"'.format(os.path.join(working_dir, "Translator.log"))
if os.name == "posix":
cmd_translator = "{} {} {}".format(command, input_file, os.path.join(working_dir, aedb_name))
cmd_translator += " -l={}".format(os.path.join(working_dir, "Translator.log"))
else:
cmd_translator = '"{}" "{}" "{}"'.format(command, input_file, os.path.join(working_dir, aedb_name))
cmd_translator += ' -l="{}"'.format(os.path.join(working_dir, "Translator.log"))
if not use_ppe:
cmd_translator += " -ppe=false"
if control_file and input_file[-3:] == "gds":
cmd_translator += ' -c="{}"'.format(control_file)
if os.name == "posix":
cmd_translator += " -c={}".format(control_file)
else:
cmd_translator += ' -c="{}"'.format(control_file)
p = subprocess.Popen(cmd_translator)
p.wait()
if not os.path.exists(os.path.join(working_dir, aedb_name)):
Expand Down
11 changes: 8 additions & 3 deletions pyaedt/rpc/rpyc_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def on_disconnect(self, connection):
# (to finalize the service, if needed)
pass

def exposed_start_service(self, hostname, beta_options=None):
def exposed_start_service(self, hostname, beta_options=None, use_aedt_relative_path=False):
"""Starts a new Pyaedt Service and start listen.

Returns
Expand Down Expand Up @@ -802,14 +802,19 @@ def exposed_start_service(self, hostname, beta_options=None):
lines = f1.readlines()
for line in lines:
f.write(line)
if not use_aedt_relative_path:
aedt_exe = os.path.join(ansysem_path, executable)
else:
aedt_exe = executable
if non_graphical:
ng_feature = "-features=SF6694_NON_GRAPHICAL_COMMAND_EXECUTION,SF159726_SCRIPTOBJECT"
if beta_options:
for option in range(beta_options.__len__()):
if beta_options[option] not in ng_feature:
ng_feature += "," + beta_options[option]

command = [
os.path.join(ansysem_path, executable),
aedt_exe,
ng_feature,
"-ng",
"-RunScriptAndExit",
Expand All @@ -821,7 +826,7 @@ def exposed_start_service(self, hostname, beta_options=None):
for option in range(beta_options.__len__()):
if beta_options[option] not in ng_feature:
ng_feature += "," + beta_options[option]
command = [os.path.join(ansysem_path, executable), ng_feature, "-RunScriptAndExit", dest_file]
command = [aedt_exe, ng_feature, "-RunScriptAndExit", dest_file]
print(command)
subprocess.Popen(command)
return port
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/third_party/ironpython/rpyc_27/utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pyaedt.third_party.ironpython.rpyc_27.lib.compat import poll, get_exc_errno

signal = safe_import("signal")
gevent = safe_import("gevent")
#gevent = safe_import("gevent")


class Server(object):
Expand Down