A collection of classes and commands for automated command line scripting using Python.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.8 KiB

# Use Script Tease With Common Kit
Since the focus of Script Tease is to convert plain text instructions into valid command line statements, it does *not* provide support for executing those statements either locally or remotely. However, the shell component of [python-commonkit](https://docs.develmaycare.com/en/python-commonkit/stable/components/#module-commonkit.shell) *does* provide support for executing commands in local POSIX environments.
Here is an example of how to use these packages together:
```python
from commonkit.shell import Command
from scripttease.exceptions import InvalidInput
from scripttease.lib.factories import command_factory
from scripttease.lib.loaders import INILoader
def execute(step):
command = Command(
step.statement,
comment=step.comment,
path=step.cd,
prefix=step.prefix,
shell=step.shell
)
# Sudo is a different class, but identical in behavior.
command.sudo = step.sudo
if command.run():
print("[success] %s" % step.comment)
else:
print("[failure] %s" % step.comment)
if step.stop:
print("I can't go on: %s" % command.error)
exit(command.code)
ini = INILoader("path/to/steps.ini")
ini.load()
try:
steps = command_factory(ini)
except InvalidInput as e:
print("%s: I can't go on." % e)
exit(1)
# A failure to load results in None.
if steps is None:
print("Failed to load steps. Bummer.")
exit(1)
# Iterate through each step to create a Common Kit command instance.
for step in steps:
# To preview ...
# print(step.get_statement(cd=True))
execute(step)
```
Common Kit is already a dependency of Script Tease, so it is installed by default. The ``execute()`` function provides the interface between Script Tease command instances and Common Kit command instances.