43
43
from ansys .aedt .core .generic .numbers import Quantity
44
44
from ansys .aedt .core .generic .settings import settings
45
45
from ansys .aedt .core .internal .aedt_versions import aedt_versions
46
+ from ansys .aedt .core .internal .errors import AEDTRuntimeError
46
47
47
48
is_linux = os .name == "posix"
48
49
is_windows = not is_linux
@@ -918,6 +919,13 @@ def available_license_feature(
918
919
feature : str = "electronics_desktop" , input_dir : Union [str , Path ] = None , port : int = 1055 , name : str = "127.0.0.1"
919
920
) -> int : # pragma: no cover
920
921
"""Check available license feature.
922
+
923
+ .. warning::
924
+
925
+ Do not execute this function with untrusted function argument, environment
926
+ variables or pyaedt global settings.
927
+ See the :ref:`security guide<ref_security_consideration>` for details.
928
+
921
929
The method retrieves the port and name values from the ``ANSYSLMD_LICENSE_FILE`` environment variable if available.
922
930
If not, the default values are applied.
923
931
@@ -939,7 +947,7 @@ def available_license_feature(
939
947
int
940
948
Number of available license features, ``False`` when license server is down.
941
949
"""
942
- import subprocess # nosec B404
950
+ import subprocess # nosec
943
951
944
952
if os .getenv ("ANSYSLMD_LICENSE_FILE" , None ):
945
953
name_env = os .getenv ("ANSYSLMD_LICENSE_FILE" )
@@ -972,11 +980,11 @@ def available_license_feature(
972
980
973
981
cmd = [str (ansysli_util_path ), "lmstat" , "-f" , feature , "-c" , str (port ) + "@" + str (name )]
974
982
975
- f = open ( str ( tempfile_checkout ), "w" )
976
-
977
- subprocess .Popen (cmd , stdout = f , stderr = f , env = my_env ). wait ( ) # nosec
978
-
979
- f . close ()
983
+ try :
984
+ with tempfile_checkout . open ( "w" ) as f :
985
+ subprocess .run (cmd , stdout = f , stderr = f , env = my_env , check = True ) # nosec
986
+ except Exception as e :
987
+ raise AEDTRuntimeError ( "Failed to check available licenses" ) from e
980
988
981
989
available_licenses = 0
982
990
pattern_license = r"Total of\s+(\d+)\s+licenses? issued;\s+Total of\s+(\d+)\s+licenses? in use"
0 commit comments