The main interface to clom is the clom object:
>>> from clom import clom
>>> clom.cat
'cat'
Each attribute of the clom object is a clom.command.Command.
Manager for generating commands.
Represents an argument that is not set as opposed to None which is a valid value
Standard In file descriptor
Standard Out file descriptor
Standard Error file descriptor
Combine commands together that must execute together.
Parameters: | commands – List of Commands or Operations to combine |
---|
>>> from clom import clom
>>> AND(clom.echo('foo'), clom.echo('bar'))
'( echo foo && echo bar )'
Combine commands together that must not execute together.
Parameters: | commands – List of Commands or Operations to combine |
---|
>>> from clom import clom
>>> OR(clom.echo('foo'), clom.echo('bar'))
'( echo foo || echo bar )'
A command line command.
Don’t use directly, instead use a clom object.
>>> from clom import clom
>>> type(clom.cat)
<class 'clom.command.Command'>
Append this command’s output to a file.
Parameters: |
|
---|---|
Returns: | Operation |
>>> clom.ls.append_to_file('list.txt')
'ls >> list.txt'
>>> clom.ls.append_to_file('list.txt', arg.STDERR)
'ls 2>> list.txt'
Shortcut for command.with_opts(**kwargs).with_args(*args)
Returns: | str - Command suitable to pass to the command line |
---|
Run the command in the background and don’t block for output.
>>> clom.ls.background()
'nohup ls &> /dev/null &'
Read a file’s contents with this command’s stdin.
Parameters: | filename – The filename to read input from |
---|---|
Returns: | Command |
>>> clom.cat.from_file('list.txt')
'cat < list.txt'
Redirect a command’s file descriptors to /dev/null.
Parameters: | fd – File descriptor to redirect to /dev/null |
---|---|
Returns: | Operation |
>>> clom.cat.hide_output()
'cat > /dev/null'
>>> clom.cat.hide_output(STDERR)
'cat 2> /dev/null'
Replace a file’s contents with this command’s output.
Parameters: |
|
---|---|
Returns: | Operation |
>>> clom.ls.output_to_file('list.txt')
'ls > list.txt'
>>> clom.ls.output_to_file('list.txt', STDERR)
'ls 2> list.txt'
Pipe this command to another.
Parameters: | to_cmd – Operation or Command to pipe to |
---|---|
Returns: | Operation |
>>> clom.ls.pipe_to(clom.grep)
'ls | grep'
Redirect a command’s file descriptors.
Parameters: |
|
---|---|
Returns: | Operation |
>>> clom.cat.redirect(STDERR, STDOUT)
'cat 2>&1'
Returns a Shell that will allow you to execute commands on the shell.
Arguments to call the command with.
Parameters: | args – A list of arguments to pass to the command. Arguments are by automatically escaped as a clom.arg.LiteralArg unless you pass in a clom.arg.RawArg. |
---|---|
Returns: | Command |
>>> clom.echo("don't test me")
'echo 'don'\''t test me''
Run the operation with environmental variables.
Parameters: | kwargs – dict - Environmental variables to run command with |
---|
Options to call the command with.
Parameters: |
|
---|---|
Returns: | Command |
>>> clom.curl.with_opts('--basic', f=True, header='X-Test: 1')
'curl --basic --header 'X-Test: 1' -f'
Base class for all command line operations, functions, commands, etc.
Append this command’s output to a file.
Parameters: |
|
---|---|
Returns: | Operation |
>>> clom.ls.append_to_file('list.txt')
'ls >> list.txt'
>>> clom.ls.append_to_file('list.txt', arg.STDERR)
'ls 2>> list.txt'
Run the command in the background and don’t block for output.
>>> clom.ls.background()
'nohup ls &> /dev/null &'
Redirect a command’s file descriptors to /dev/null.
Parameters: | fd – File descriptor to redirect to /dev/null |
---|---|
Returns: | Operation |
>>> clom.cat.hide_output()
'cat > /dev/null'
>>> clom.cat.hide_output(STDERR)
'cat 2> /dev/null'
Replace a file’s contents with this command’s output.
Parameters: |
|
---|---|
Returns: | Operation |
>>> clom.ls.output_to_file('list.txt')
'ls > list.txt'
>>> clom.ls.output_to_file('list.txt', STDERR)
'ls 2> list.txt'
Pipe this command to another.
Parameters: | to_cmd – Operation or Command to pipe to |
---|---|
Returns: | Operation |
>>> clom.ls.pipe_to(clom.grep)
'ls | grep'
Easily run `Command`s on the system’s shell.
Executes the command and returns a list of the lines of the result.
Alias for shell(...).all()
>>> str(clom.echo.shell.all('foo\nfoobar'))
"['foo', 'foobar']"
Execute the command on the shell without capturing output.
Use this if the result is very large or you do not care about the results.
Raises : | CommandError |
---|---|
Returns: | CommandResult |
Executes the command and returns the first line.
Alias for shell(...).first()
>>> str(clom.echo.shell.first('foo\nfoobar'))
'foo'
An error returned from a shell command.
The result of a command execution.
Get the first line of the results.
You can also get the return code:
>>> r = CommandResult(2)
>>> r.first().return_code
2
Iterate over the command results split by lines with whitespace optionally stripped.
Parameters: | strip – bool - Strip whitespace for each line |
---|