Module shellutils :: Class Shell
[hide private]

Class Shell

source code

Class for managing Shell connections via SSH, Telnet, or NTCmd

Shell is not thread-safe. Every thread must have its own instance.

Instance Methods [hide private]
 
__init__(self, client) source code
 
getDefaultCommandTimeout(self)
Get default command timeout declared in globalSettings.xml
source code
 
setSessionLocale(self) source code
 
isWinOs(self) source code
 
getOsType(self)
Returns the type of the operating system running on the target host to which the shell client is connected
source code
 
_getOsType(self)
Template method for each derived class to get properly OS type
source code
 
isWindowsWithCygwin(self)
Indicates whether running commands in cygwin shell
source code
 
getOsVersion(self)
Get version of the OS running on the target host to which the shell client is connected
source code
 
getOsLanguage(self) source code
 
determineOsLanguage(self) source code
 
_getOsVersion(self)
Template method to get OS version for derived shell
source code
 
_getOsLanguageDiscoverer(self) source code
 
useCharset(self, charsetName)
Use specified character set for command encoding and output decoding in raw client
source code
 
getShellStatusVar(self)
Returns the shell command exit status code
source code
 
getCommandSeparator(self)
Get command separator depending on OS type
source code
 
getShellCmdSeperator(self)
Returns the shell command separator character.
source code
 
__addAlternateCmd(self, cmd, expectedReturnCode=None, sucessString=None, failureString=None)
Add alternative command to execute list
source code
 
__removeAllAlternateCmds(self) source code
 
__execCmdSet(self, timeout=0)
Go over all alternative commands list and execute each until the first successful command termination.
source code
 
execAlternateCmds(self, *commands)
Executes the input list of shell commands until one of them succeeds.
source code
 
execAlternateCmdsList(self, commands, timeout=0)
Executes the input list of shell commands until one of them succeeds.
source code
 
getLastCmdReturnCode(self)
Returns the exit status of the last shell command issued by execCmd or execAlternateCmds methods
source code
 
fsObjectExists(self, path)
Checks whether the file or directory exists on the File System
source code
 
execCmd(self, cmdLine, timeout=0, waitForTimeout=0, useSudo=1, checkErrCode=1, useCache=0, preserveSudoContext=0)
Executes a shell command and sets the exit status of the command.
source code
 
_execute(self, command)
Template method for derived shells for exact command execution
source code
 
execCmdAsBytes(self, cmdLine, timeout=0, waitForTimeout=0, useSudo=1)
Get raw data as list of bytes.
source code
 
resolveHost(self, hostName, nodeClassName='node')
Create host CI with IP as key resolved by host name
source code
 
resolveIp(self, hostName)
Resolve IP by host name
source code
 
getXML(self, path, forceSudo=0)
Get xml content with proper encoding
source code
 
safecat(self, path, forceSudo=0)
Get file content by specified path
source code
 
getClientType(self) source code
 
getPort(self) source code
 
getCredentialId(self) source code
 
closeClient(self)
Perform cleaning of temporary data on destination system and close the client
source code
 
__removeCopiedData(self) source code
 
canCopyFile(self)
Indicates whether client can copy files to the remote system
source code
 
rebuildPath(self, folder)
Normalize path to one used in OS client connected to
source code
 
createOutputHandler(self, cmd=None)
Create output handler depending OS type
source code
 
executeCommandAndDecodeByMatcher(self, cmd, matcher, framework, timeout=0, waitForTimeout=0, useSudo=1, language=None)
Execute command and try to decode output using predefined charsets.
source code
 
executeCommandAndDecode(self, cmd, keyword, framework, timeout=0, waitForTimeout=0, useSudo=1, language=None)
Execute command and try to decode output using predefined charsets.
source code
 
getCharsetName(self)
Get name of the character set for the latest command execution
source code
Class Variables [hide private]
  NO_CMD_RETURN_CODE_ERR_NUMBER = -9999
Method Details [hide private]

setSessionLocale(self)

source code 

Deprecated: Unix only dedicated

getOsType(self)

source code 

Returns the type of the operating system running on the target host to which the shell client is connected

Raises:
  • Exception - Failed getting machine OS type

_getOsType(self)

source code 

Template method for each derived class to get properly OS type

Raises:
  • Exception - Failed getting machine OS type

isWindowsWithCygwin(self)

source code 

Indicates whether running commands in cygwin shell

Deprecated: will be removed from public access

getOsVersion(self)

source code 

Get version of the OS running on the target host to which the shell client is connected

Deprecated: should be moved to the OS discoverer (domain layer)

determineOsLanguage(self)

source code 

Deprecated: will be removed from the public access

_getOsVersion(self)

source code 

Template method to get OS version for derived shell

Raises:
  • Exception - Failed to get OS version

useCharset(self, charsetName)

source code 

Use specified character set for command encoding and output decoding in raw client

Raises:
  • IllegalCharsetNameException - The given charset name is illegal
  • UnsupportedCharsetException - No support for the named charset is available in this instance of the JVM

getShellCmdSeperator(self)

source code 

Returns the shell command separator character. This is the character used between commands when more than one command is passed on the same command line.

Deprecated: Use getCommandSeparator instead

__execCmdSet(self, timeout=0)

source code 
Go over all alternative commands list and execute each until the first successful command termination.
 This method basically executes shell commands and retrieves terminate status of the executed command
 until a command ended successfully.
 command is successful when:
 1. it returned the expected return code.
 2. if no return code is given, the output of the command is compared against sucessString
      to determine command success.
 3. if failureString is given the output of the command is compared against failureString
      to determine command failure
@types: int -> str

execAlternateCmds(self, *commands)

source code 

Executes the input list of shell commands until one of them succeeds.

Returns:
output of the first successful command, otherwise None

execAlternateCmdsList(self, commands, timeout=0)

source code 

Executes the input list of shell commands until one of them succeeds.

Parameters:
  • timeout - timeout for each command in milliseconds
Returns:
output of the first successesfull command, otherwise None

getLastCmdReturnCode(self)

source code 

Returns the exit status of the last shell command issued by execCmd or execAlternateCmds methods

Returns:
exit status of the last command issued
Raises:
  • Exception - Cannot get last command return code: no command was issued

fsObjectExists(self, path)

source code 

Checks whether the file or directory exists on the File System

Deprecated: Use FileSystem methods instead

execCmd(self, cmdLine, timeout=0, waitForTimeout=0, useSudo=1, checkErrCode=1, useCache=0, preserveSudoContext=0)

source code 

Executes a shell command and sets the exit status of the command.

Parameters:
  • cmdLine - command to execute
  • timeout - time in ms or if < 1ms treated as coefficient for predefined timeout
Returns:
output of the executed shell command
Raises:
  • Exception - Command execution does not produced output nor return code

resolveHost(self, hostName, nodeClassName='node')

source code 

Create host CI with IP as key resolved by host name

Returns:
IP address or None if IP cannot be resolved or is local

Deprecated: Will be removed in further version

resolveIp(self, hostName)

source code 

Resolve IP by host name

Returns:
IP address or None if IP cannot be resolved or is local

Deprecated: Use netutils.IpResolver instead

getXML(self, path, forceSudo=0)

source code 

Get xml content with proper encoding

Parameters:
  • forceSudo - if true, always uses sudo, if false first tries to run command without sudo

Deprecated: Use file system module for such purposes

safecat(self, path, forceSudo=0)

source code 

Get file content by specified path

Parameters:
  • path - full path (including name) to the desired file
  • forceSudo - if true, always uses sudo, if false first tries to run command without sudo
Raises:
  • Exception - Redirection symbols used or getting content failed

Deprecated: Use methods from file system module instead

rebuildPath(self, folder)

source code 

Normalize path to one used in OS client connected to

Deprecated: Use methods from file system module instead

createOutputHandler(self, cmd=None)

source code 

Create output handler depending OS type

Raises:
  • ValueError - If decoding is not supported for used protocol type

Deprecated: Will be moved to the private scope

executeCommandAndDecodeByMatcher(self, cmd, matcher, framework, timeout=0, waitForTimeout=0, useSudo=1, language=None)

source code 

Execute command and try to decode output using predefined charsets. Decoded output considered as valid if it is matched by provided matcher.

Parameters:
  • matcher - defines matching case for valid character set

executeCommandAndDecode(self, cmd, keyword, framework, timeout=0, waitForTimeout=0, useSudo=1, language=None)

source code 

Execute command and try to decode output using predefined charsets. Decoded output considered as valid if it is matched by KEYWORD matcher.