cloudmesh-common.cloudmesh.common.Shell

A convenient method to execute shell commands and return their output. Note: that this method requires that the command be completely execute before the output is returned. FOr many activities in cloudmesh this is sufficient.

Module Contents

Classes

Brew

Pip

Subprocess

Executes a command. This class should not be directly used, but

Shell

The shell class allowing us to conveniently access many operating system commands.

Functions

NotImplementedInWindows()

main()

a test that should actually be added into a pytest

cloudmesh-common.cloudmesh.common.Shell.NotImplementedInWindows()
class cloudmesh-common.cloudmesh.common.Shell.Brew

Bases: object

classmethod install(cls, name)
classmethod version(cls, name)
class cloudmesh-common.cloudmesh.common.Shell.Pip

Bases: object

classmethod install(cls, name)
exception cloudmesh-common.cloudmesh.common.Shell.SubprocessError(cmd, returncode, stderr, stdout)

Bases: Exception

Manages the formatting of the error and stdout. This command should not be directly called. Instead use Shell

__str__(self)

Return str(self).

class cloudmesh-common.cloudmesh.common.Shell.Subprocess(cmd, cwd=None, stderr=subprocess.PIPE, stdout=subprocess.PIPE, env=None)

Bases: object

Executes a command. This class should not be directly used, but instead you should use Shell.

class cloudmesh-common.cloudmesh.common.Shell.Shell

Bases: object

The shell class allowing us to conveniently access many operating system commands. TODO: This works well on Linux and OSX, but has not been tested much on Windows

command
static run_timed(label, command, encoding=None, service=None)

runs teh command and uses the StopWatch to time it :param label: name of the StopWatch :param command: the command to be executed :param encoding: the encoding :param service: a prefix to the stopwatch label :return:

static run(command, exit='; exit 0', encoding='utf-8')

executes the command and returns the output as string :param command: :param encoding: :return:

static run2(command, encoding='utf-8')

executes the command and returns the output as string. This command also allows execution of 32 bit commands.

Parameters
  • command – the program or command to be executed

  • encoding – encoding of the output

Returns

classmethod execute(cls, cmd, arguments='', shell=False, cwd=None, traceflag=True, witherror=True)

Run Shell command

Parameters
  • witherror – if set to False the error will not be printed

  • traceflag – if set to true the trace is printed in case of an error

  • cwd – the current working directory in which the command is

supposed to be executed. :param shell: if set to true the subprocess is called as part of a shell :param cmd: command to run :param arguments: we do not know yet :return:

static oneline(script)

converts a script to one line command. THis is useful to run a single ssh command and pass a one line script.

Parameters

script

Returns

static is_root()
static rmdir(top, verbose=False)
static dot2svg(filename, engine='dot')
static browser(filename)
static terminal_title(name)
classmethod terminal(cls, command='pwd', title=None)
classmethod live(cls, command, cwd=None)
classmethod get_python(cls)

returns the python and pip version :return: python version, pip version

classmethod check_output(cls, *args, **kwargs)

Thin wrapper around subprocess.check_output()

classmethod ls(cls, match='.')

executes ls with the given arguments :param args: :return: list

classmethod unix_ls(cls, *args)

executes ls with the given arguments :param args: :return:

static ps()

using psutil to return the process information pid, name and comdline, cmdline may be a list

Returns

a list of dicts of process information

classmethod bash(cls, *args)

executes bash with the given arguments :param args: :return:

classmethod brew(cls, *args)

executes bash with the given arguments :param args: :return:

classmethod cat(cls, *args)

executes cat with the given arguments :param args: :return:

classmethod git(cls, *args)

executes git with the given arguments :param args: :return:

classmethod VBoxManage(cls, *args)

executes VboxManage with the given arguments :param args: :return:

classmethod blockdiag(cls, *args)

executes blockdiag with the given arguments :param args: :return:

classmethod cm(cls, *args)

executes cm with the given arguments :param args: :return:

classmethod cms(cls, *args)

executes cm with the given arguments :param args: :return:

classmethod cmsd(cls, *args)

executes cm with the given arguments :param args: :return:

classmethod head(cls, *args)

executes head with the given arguments :param args: :return:

classmethod keystone(cls, *args)

executes keystone with the given arguments :param args: :return:

static kill_pid(pid)
classmethod kill(cls, *args)

executes kill with the given arguments :param args: :return:

classmethod mount(cls, *args)

mounts a given mountpoint to a file :param args: :return:

classmethod umount(cls, *args)

umounts a given mountpoint to a file :param args: :return:

classmethod nova(cls, *args)

executes nova with the given arguments :param args: :return:

classmethod ping(cls, host=None, count=1)

execute ping :param host: the host to ping :param count: the number of pings :return:

classmethod pwd(cls, *args)

executes pwd with the given arguments :param args: :return:

classmethod rackdiag(cls, *args)

executes rackdiag with the given arguments :param args: :return:

classmethod rm(cls, location)

executes rm tree with the given arguments :param args: :return:

classmethod rsync(cls, *args)

executes rsync with the given arguments :param args: :return:

classmethod scp(cls, *args)

executes scp with the given arguments :param args: :return:

classmethod sort(cls, *args)

executes sort with the given arguments :param args: :return:

classmethod sh(cls, *args)

executes sh with the given arguments :param args: :return:

classmethod ssh(cls, *args)

executes ssh with the given arguments :param args: :return:

classmethod sudo(cls, *args)

executes sudo with the given arguments :param args: :return:

classmethod tail(cls, *args)

executes tail with the given arguments :param args: :return:

classmethod vagrant(cls, *args)

executes vagrant with the given arguments :param args: :return:

classmethod pandoc(cls, *args)

executes vagrant with the given arguments :param args: :return:

classmethod mongod(cls, *args)

executes mongod with the given arguments :param args: :return:

classmethod dialog(cls, *args)

executes dialof with the given arguments :param args: :return:

classmethod pip(cls, *args)

executes pip with the given arguments :param args: :return:

classmethod fgrep(cls, *args)

executes fgrep with the given arguments :param args: :return:

classmethod grep(cls, *args)

executes grep with the given arguments :param args: :return:

classmethod cm_grep(cls, lines, what)

returns all lines that contain what :param lines: :param what: :return:

classmethod remove_line_with(cls, lines, what)

returns all lines that do not contain what :param lines: :param what: :return:

classmethod find_lines_with(cls, lines, what)

returns all lines that contain what :param lines: :param what: :return:

classmethod find_lines_from(cls, lines, what)

returns all lines that come after a particular line :param lines: :param what: :return:

classmethod find_lines_between(cls, lines, what_from, what_to)

returns all lines that come between the markers :param lines: :param what: :return:

classmethod find_lines_to(cls, lines, what)

returns all lines that come before a particular line :param lines: :param what: :return:

classmethod terminal_type(cls)

returns darwin, cygwin, cmd, or linux

classmethod which(cls, command)

returns the path of the command with which :param command: teh command :return: the path

classmethod command_exists(cls, name)

returns True if the command exists :param name: :return:

classmethod operating_system(cls)

the name of the os :return: the name of the os

static get_pid(name, service='psutil')
static cms(command, encoding='utf-8')
classmethod check_python(cls)

checks if the python version is supported :return: True if it is supported

classmethod mkdir(cls, directory)

creates a directory with all its parents in ots name :param directory: the path of the directory :return:

unzip(cls, source_filename, dest_dir)

unzips a file into the destination directory :param source_filename: the source :param dest_dir: the destination directory :return:

static edit(filename)
classmethod lsb_release(cls)

executes lsb_release command :param args: :return:

classmethod distribution(cls)

executes lsb_release command :param args: :return:

TODO: needs testing

cloudmesh-common.cloudmesh.common.Shell.main()

a test that should actually be added into a pytest :return: