This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Execute commands on local machine and on remote machine via ssh, and a wrapper for paramikos scp.

Project Description

Execute commands on local machine and on remote machine via ssh, and a wrapper for paramikos scp.

shell command

Wrapper around subprocess.call with shell=True

shell(cmd)

Background Unix command running

Runs a blocking unix command and returns the result

cmd_run(cmd, pr=False, streamoutput=True, returnoutput=True, cwd=None, prefix=None)

# example
cmd_run('date "+%Y-%m-%d% %H:%M"', pr=False, streamoutput=False, returnoutput=True)

# more params
call_command(command, cmdfolder=os.getcwd(), verbose=False, streamoutput=True,\
             returnoutput=False, prefix=None, ret_and_code=False)

Parameters:

  • command: unix command
  • cmdfolder=os.getcwd() -> working folder command
  • verbose=False -> prints the command
  • streamoutput=True -> prints output to stdout (keeps buffering)
  • returnoutput=False -> return the buffered output
  • prefix=None -> string to place before streaming output
  • ret_and_code=False -> return exit code also (code, val)

Variant background unix command

Common usecase scenario, run a command and get the result, possibly print to the console using an optional filter.

# example filter:
def onlyerrors(data):
    if "ERROR" in data:
        return data

cmd_exec(cmd, cmdtoprint=None, display=True, myfilter=onlyerrors)
  • cmdtoprint: unix command
  • display: print to console
  • myfilter: function used to print

SSH: run command on remote machine

Uses ssh and key authentication to logon to a remote ssh server and execute a command there.

def remote_cmd(server, cmd, username=None, timeout=60, keypath=None):

#example
remote_cmd("localhost", "rm -Rf ~/Desktop/foobar")

Parameters:

  • server: ip or domain name of server
  • cmd: unix command to execute
  • username: username used to login
  • timeout: try time to connect to server
  • keypath: path to the public key of username

tuplebased interface:

remote_cmd_map(servercmd)
  • servercmd: tuple with ( server, cmd, username, keypath )

SSH: Secure Copy Protocol

scp_get(server, fp1, fp2, username=None, keypath=None)
scp_put(server, fp1, fp2, username=None, keypath=None)

Parameters:

  • server: ip or domain name of server
  • fp1: source filepath
  • fp2: target filepath
  • username: username used to login
  • keypath: path to the public key of username

SSH: Shell

Invoke a shell on a machine

invoke_shell(server, username, keypath)

Parameters:

  • server: ip or domain name of server
  • username: username used to login
  • keypath: path to the public key of username

Download file

Wrapper around the requests library. Downloads a file with a progress bar.

download(url, mypath):

parameters:

  • url: url to download
  • mypath: filepath where to create the downloaded file

example output:

download: http://download.thinkbroadband.com/5MB.zip
00:00:02|███████████████████████         | 3.7Mi/5.0Mi
Release History

Release History

This version
History Node

54

History Node

53

History Node

50

History Node

49

History Node

48

History Node

47

History Node

46

History Node

45

History Node

44

History Node

43

History Node

41

History Node

40

History Node

39

History Node

38

History Node

37

History Node

36

History Node

34

History Node

33

History Node

32

History Node

31

History Node

30

History Node

29

History Node

28

History Node

27

History Node

26

History Node

25

History Node

24

History Node

23

History Node

22

History Node

21

History Node

20

History Node

19

History Node

18

History Node

16

History Node

15

History Node

14

History Node

13

History Node

12

History Node

11

History Node

10

History Node

9

History Node

8

History Node

7

History Node

6

History Node

5

History Node

4

History Node

3

History Node

1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cmdssh-54.tar.gz (9.7 kB) Copy SHA256 Checksum SHA256 Source Jul 7, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting