Set of utility functions used by SALOME python scripts. More...
Data Structures | |
| class | ColoredFormatter |
| class | BackTraceFormatter |
Functions | |
| def | _try_bool (arg) |
| def | getORBcfgInfo () |
| def | getHostFromORBcfg () |
| def | getPortFromORBcfg () |
| def | getUserName () |
| def | getHostName () |
| def | getShortHostName () |
| def | getAppName () |
| def | getPid () |
| def | getPortNumber (use_default=True) |
| def | getHomeDir () |
| def | getLogDir () |
| def | getTmpDir () |
| def | generateFileName (path, prefix=None, suffix=None, extension=None, unique=False, separator='_', hidden=False, **kwargs) |
| def | cleanDir (path) |
| def | makeDir (path, mode=0o777) |
| def | makeTmpDir (path, mode=0o777) |
| def | uniteFiles (src_file, dest_file) |
| def | positionVerbosityOfLogger (verboseLevel) |
| def | positionVerbosityOfLoggerRegardingState () |
| def | verbose () |
| def | setVerbose (status) |
| def | verboseLevel () |
| def | setVerboseLevel (level) |
| def | killPid (pid, sig=9) |
| def | getOmniNamesPid (port) |
| def | killOmniNames (port) |
Variables | |
| logger = logging.getLogger() | |
| Setting formatter in setVerbose() was commented because adding of handler breaks using of root logger in other modules and cause many double lines in logs. More... | |
| dictionary | KernelLogLevelToLogging = {"INFO":logging.INFO, "DEBUG":logging.DEBUG, "WARNING":logging.WARNING, "ERROR":logging.ERROR} |
| dictionary | LoggingToKernelLogLevel = {v: k for k, v in KernelLogLevelToLogging.items()} |
Set of utility functions used by SALOME python scripts.
|
private |
Convert given `arg` to a boolean value. String values like 'True', 'TRUE', 'YES', 'Yes', 'y', 'NO', 'false', 'n', etc. are supported. If `arg` does not represent a boolean, an exception is raised. :param arg : value being converted :return result of conversion: `True` or `False`
Referenced by generateFileName().
| def salome_utils.cleanDir | ( | path | ) |
Clear contents of directory. :param path directory path
Referenced by makeTmpDir().
| def salome_utils.generateFileName | ( | path, | |
prefix = None, |
|||
suffix = None, |
|||
extension = None, |
|||
unique = False, |
|||
separator = '_', |
|||
hidden = False, |
|||
| ** | kwargs | ||
| ) |
Generate file name.
:param path : directory path
:param prefix : file name prefix (none by default)
:param suffix : file name suffix (none by default)
:param extension : file extension (none by default)
:param unique : if `True`, function generates unique file name -
in this case, if file with the generated name already
exists in `path` directory, an integer suffix is appended
to the file name (`False` by default)
:param separator : words separator ('_' by default)
:param hidden : if `True`, file name is prepended with dot symbol
(`False` by default)
:param kwargs : additional keywrods arguments (see below)
:return generated file name
Additionally supported keyword parameters:
- with_username : use user name:
- with_hostname : use host name:
- with_port : use port number:
- with_app : use application name:
- with_pid : use current pid
Any of these keyword arguments can accept either explicit string value,
or `True` to automatically deduce value from current configuration.
References _try_bool().
Referenced by searchFreePort.__setup_config(), PortManager._getConfigurationFilename(), killSalomeWithPort.appliCleanOmniOrbConfig(), killSalomeWithPort.getPiDict(), setenv.set_env(), killSalomeWithPort.shutdownMyPort(), runSalomeOld.startSalome(), ORBConfigFile.writeORBConfigFile(), and ORBConfigFile.writeORBConfigFileSSL().
| def salome_utils.getAppName | ( | ) |
Get application name. The following procedure is perfomed to deduce application name: 1. try APPNAME environment variable 2. if (1) fails, return 'SALOME' as default application name :return application name
| def salome_utils.getHomeDir | ( | ) |
Get home directory. :return home directory path
Referenced by launchConfigureParser.defaultUserFile(), and launchConfigureParser.userFile().
| def salome_utils.getHostFromORBcfg | ( | ) |
Get current omniORB host name. :return host name
References getORBcfgInfo().
| def salome_utils.getHostName | ( | ) |
Get host name. The following procedure is perfomed to deduce host name: 1. try socket python module, gethostname() function 2. if (1) fails, try HOSTNAME environment variable 3. if (2) fails, try HOST environment variable 4. if (3) fails, tries 'unknown' as default host name 5. finally, checks that IP is configured for hostname; if not, returns 'localhost' :return host name
Referenced by killSalomeWithPort.__guessPiDictFilename(), searchFreePort.__setup_config(), getShortHostName(), nameserver.NamingServer.initNSArgs(), and runSalomeOld.main().
| def salome_utils.getLogDir | ( | ) |
Get directory that stores log files. :return path to the log directory
References getTmpDir(), and getUserName().
Referenced by killSalomeWithPort.getPiDict(), nameserver.NamingServer.initNSArgs(), and setenv.set_env().
| def salome_utils.getOmniNamesPid | ( | port | ) |
Get PID of omniNames process running on given `port`. :param port : port number :return omniNames process's PID
Referenced by killOmniNames().
| def salome_utils.getORBcfgInfo | ( | ) |
Get current omniORB configuration. The information is retrieved from the omniORB configuration file defined by the OMNIORB_CONFIG environment variable. If omniORB configuration file can not be accessed, a tuple of three empty strings is returned. :return tuple of three strings: (orb_version, host_name, port_number)
Referenced by getHostFromORBcfg(), NSparam.getNSparams(), and getPortFromORBcfg().
| def salome_utils.getPid | ( | ) |
| def salome_utils.getPortFromORBcfg | ( | ) |
Get current omniORB port. :return port number
References getORBcfgInfo().
Referenced by getPortNumber().
| def salome_utils.getPortNumber | ( | use_default = True | ) |
Get currently used omniORB port. The following procedure is perfomed to deduce port number: 1. try NSPORT environment variable 2. if (1) fails, try to parse config file defined by OMNIORB_CONFIG environment variable 3. if (2) fails, return 2809 as default port number (if use_default is `True`) or `None` (if use_default is `False`) :return port number
References getPortFromORBcfg().
Referenced by addToKillList.findFileDict(), runSalomeOld.foreGround(), launchConfigureParser.get_env(), setenv.set_env(), and runSalomeOld.startSalome().
| def salome_utils.getShortHostName | ( | ) |
Get short host name (with domain stripped). See `getHostName()` for more details. :return short host name
References getHostName().
| def salome_utils.getTmpDir | ( | ) |
Get directory to store temporary files. :return temporary directory path
Referenced by getLogDir(), and runSalomeOld.registerEnv().
| def salome_utils.getUserName | ( | ) |
Get user name. The following procedure is perfomed to deduce user name: 1. try USER (USERNAME on Windows) environment variable. 2. if (1) fails, try LOGNAME (un*x only). 3. if (2) fails, return 'unknown' as default user name :return user name
Referenced by killSalomeWithPort.__checkUnkilledProcesses(), runConsole.__get_running_session(), runRemote._writeConfigFile(), runSession._writeConfigFile(), killSalomeWithPort.appliCleanOmniOrbConfig(), runSession.configureSession(), update_catalogs.Resource.get_catalogs(), update_catalogs.Resource.get_components(), kill_remote_containers.Resource.get_user(), update_catalogs.Resource.get_user(), getLogDir(), runSalomeOld.registerEnv(), and IDLparser.run().
| def salome_utils.killOmniNames | ( | port | ) |
Kill omniNames process running on given `port`. :param port : port number
References getOmniNamesPid(), and killPid().
Referenced by killSalomeWithPort.shutdownMyPort().
| def salome_utils.killPid | ( | pid, | |
sig = 9 |
|||
| ) |
Send signal `sig` to the process with given `pid`. :param pid : PID of the process :param sig : signal to send; some of possible values: - 9 : kill process - 0 : do nothing, just check process existence (see below) NOTE: other values are not processed on Windows :return result of execution: - 1 : success - 0 : fail, no such process - -1 : fail, another reason
References verbose().
Referenced by killSalomeWithPort.killMyPortSpy(), and killOmniNames().
| def salome_utils.makeDir | ( | path, | |
mode = 0o777 |
|||
| ) |
Make directory with the specified path. :param path : directory path :param mode : access mode
Referenced by addToKillList.addToKillList(), nameserver.NamingServer.initNSArgs(), and makeTmpDir().
| def salome_utils.makeTmpDir | ( | path, | |
mode = 0o777 |
|||
| ) |
Make temporary directory with the specified path. If the directory exists, clear all its contents. :param path : directory path :param mode : access mode
References cleanDir(), and makeDir().
Referenced by setenv.set_env().
| def salome_utils.positionVerbosityOfLogger | ( | verboseLevel | ) |
References SalomeOnDemandTK.extension_utilities.format.
Referenced by positionVerbosityOfLoggerRegardingState(), and runSalomeCommon.setVerbose().
| def salome_utils.positionVerbosityOfLoggerRegardingState | ( | ) |
| def salome_utils.setVerbose | ( | status | ) |
Change verbosity activation status. The function `verbose()` can be used to get current verbosity level. :param status : verbosity status :type status: bool
| def salome_utils.setVerboseLevel | ( | level | ) |
Change verbosity level. The function `verboseLevel()` can be used to get current verbosity level. :param level : verbosity level
Referenced by testCrashProofContainer.testPerfLogManager1.test9(), and testPerfLogManager1.testPerfLogManager1.testSSDCopyMethod().
| def salome_utils.uniteFiles | ( | src_file, | |
| dest_file | |||
| ) |
Join contents of `src_file` and `dest_file` and put result to `dest_file`. File `dest_file` may not exist. :param src_file : source file path :param dest_file : destination file path
| def salome_utils.verbose | ( | ) |
Get current verbosity activation.
Default verbosity level is specified via the environment variable SALOME_VERBOSE,
e.g. in bash:
$ export SALOME_VERBOSE=1
The function `setVerbose()` can be used to explicitly set verbosity activation.
:return current verbosity level
Referenced by killPid().
| def salome_utils.verboseLevel | ( | ) |
Get current verbosity level.
Default verbosity level is specified via the environment variable SALOME_VERBOSE,
e.g. in bash:
$ export SALOME_VERBOSE_LEVEL=7
The function `setVerboseLevel()` can be used to explicitly set verbosity level.
:return current verbosity level
Referenced by positionVerbosityOfLoggerRegardingState().
| dictionary salome_utils.KernelLogLevelToLogging = {"INFO":logging.INFO, "DEBUG":logging.DEBUG, "WARNING":logging.WARNING, "ERROR":logging.ERROR} |
| salome_utils.logger = logging.getLogger() |
Setting formatter in setVerbose() was commented because adding of handler breaks using of root logger in other modules and cause many double lines in logs.
FORMAT = '%(levelname)s : %(asctime)s : [%(filename)s:%(funcName)s:%(lineno)s] : %(message)s' logging.basicConfig(format=FORMAT)
| dictionary salome_utils.LoggingToKernelLogLevel = {v: k for k, v in KernelLogLevelToLogging.items()} |