cup.shell package

Submodules

cup.shell.expect module

description:Guannan just made a wraper out of pexpect. The original copyright belongs to the author of pexpect module. See it at http://pexpect.sourceforge.net/pexpect.html
cup.shell.expect.go(hostname, username, passwd, command='', timeout=800, b_print_stdout=True)[source]

deprecated, recommand using go_ex or go_with_scp

cup.shell.expect.go_ex(hostname, username, passwd, command='', timeout=800, b_print_stdout=True)[source]

Run [command] on remote [hostname] and return result. If you have a lot of escape sign in the command, recommand using go_with_scp

Parameters:timeout – execution timeout, by default 800 seconds
Returns:return a dict with keys (‘exitstatus’ ‘remote_exitstatus’ ‘result’)
cup.shell.expect.checkssh(hostname, username, passwd)[source]

check if we can ssh to hostname. Return True if succeed, False otherwise.

cup.shell.expect.go_with_scp(hostname, username, passwd, command='', host_tmp='/tmp/', remote_tmp='/tmp/', timeout=800, b_print_stdout=True)[source]

Recommand using this function to remotely execute cmds.

go_witch_scp will write a temp script file and scp to hostname:[host_tmp]. Then execute it and get the result back.

Parameters:
  • host_tmp – temp folder for keeping the temporary script file (contains the cmd)
  • remote_tmp – remote temp folder for keeping the temporary script file
  • timeout – timeout
Returns:

a dict with keys (‘exitstatus’ ‘remote_exitstatus’ ‘result’)

cup.shell.expect.lscp(src, hostname, username, passwd, dst, timeout=800, b_print_stdout=True)[source]

copy [localhost]:src to [hostname]:[dst]

Returns:return a dict with keys (‘exitstatus’ ‘remote_exitstatus’ ‘result’)
cup.shell.expect.dscp(hostname, username, passwd, src, dst, timeout=9000, b_print_stdout=False)[source]

copy [hostname]:[src] to [localhost]:[dst].

Returns:return a dict with keys (‘exitstatus’ ‘remote_exitstatus’ ‘result’)

cup.shell.oper module

description:shell operations related module
cup.shell.oper.contains_file(dstpath, expected_name, recursive=False, follow_link=False)[source]

judge if the dstfile is in dstpath

Parameters:
  • dstpath – search path
  • dstfile – file
  • recursive – search recursively or not. False by default.
Returns:

return True on success, False otherwise

cup.shell.oper.backup_file(srcpath, filename, dstpath, label=None)[source]

Backup srcpath/filename to dstpath/filenamne.label. If label is None, cup will use time.strftime(‘%H:%M:S’)

Dstpath:will create the folder if no existence

Module contents

description:shell related module