libcsm.os
module
Module for handling command line calls.
Note
The _CLI
object is private, the intended usage is to use
run_command
.
- libcsm.os.chdir(directory, create=False)
Change directories and run a command.
Change into a given directory and returns to the original directory on exit.
Note
This does not wrap the yield in a ‘try’, everything done within the else is the user’s responsibility.
from libcsm.os import chdir print('doing things in /dir/foo') with chdir('/some/other/dir'): # doing things in /some/other/dir print('doing more things in /dir/foo')
- Parameters:
directory (
str
) – Where you want to go.create (
bool
) – Whether you want the entire tree created or not.
- Return type:
None
- libcsm.os.run_command(args, in_shell=False, silence=False, charset=None)
Run a given command or list of commands by instantiating a
CLI
object.from libcsm.os import run_command result = run_command(['my', 'args']) print(vars(result))
- Parameters:
args ([<class ‘list’>, <class ‘str’>]) – List of arguments to run, can also be a string. If a string,
in_shell (
bool
) – Whether to use a shell when invoking the command.silence (
bool
) – Tells this not to output the command to console.charset (
str
) – Returns the commandstdout
andstderr
as a string instead of bytes, and decoded with the givencharset
.
- Return type:
_CLI