Pycommands help you to build system remote call commands
Project description
pycommands
Handle a list of commands that should be executed easily and with undo support.
How to use
Install
pycommands is available on PyPI
pip install pycommands
Basic usage
Definition of commands
from commands.base import BaseCommand
from commands.exceptions import CommandException
from commands.invoker import Invoker
class Command1(BaseCommand):
def build(self):
return "touch content.txt"
def build_undo(self):
return "rm content.txt"
class Command2(BaseCommand):
def build(self):
return "mv content.txt content-replaced.txt"
def build_undo(self):
return "mv content-replaced.txt content.txt"
class InvalidCommand(BaseCommand):
def build(self):
raise CommandException()
Simple default execution with success commands
from commands.invoker import Invoker
invoker = Invoker()
invoker.execute([
Command1(),
Command2(),
], run_undo=False)
# output
running command: touch content.txt
running command: mv content.txt content-replaced.txt
# If a invoker.undo() is called then all commands undo operation will be done in the LIFO order.
invoker.undo()
# output
running undo command: mv content-replaced.txt content.txt
running undo command: rm content.txt
# If a invoker.execute() is called with run_undo as True, then the undo operation will be done always
# that a command raise CommandException
invoker = Invoker()
invoker.execute([
Command1(),
Command2(),
InvalidCommand(),
], run_undo=True)
# output
running command: touch content.txt
running command: mv content.txt content-replaced.txt
running command: touch content.txt
running command: mv content.txt content-replaced.txt
running undo command: mv content-replaced.txt content.txt
running undo command: rm content.txt
How to contribute
We welcome contributions of many forms, for example:
- Code (by submitting pull requests)
- Documentation improvements
- Bug reports and feature requests
Setting up for local development
We use pipenv to manage dependencies, so make sure you have it installed.
Creating environment
/<project-path>/pipenv install --python=3
Activing environment
/<project-path>/pipenv shell
Install pre-commit hooks:
pre-commit install
Run tests by evoking pytest:
pytest
That's it! You're ready from development
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycommands-0.0.1.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file pycommands-0.0.1.tar.gz
.
File metadata
- Download URL: pycommands-0.0.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f00d2dfd3022f0d219b5eaddf49912cffab67f8016dd46140f0743543bb42d6 |
|
MD5 | 0dacc5f398199db86cb83e31ec068ad7 |
|
BLAKE2b-256 | dcffd004782d95f7201957452a14933a4268f369af3ebd475dfc4f39217004ea |
File details
Details for the file pycommands-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pycommands-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91f34d88b260a55bf8a946cdd78dc5385c16a020d929dc6b82eb9101a782207c |
|
MD5 | d809083cab13c5b9dd815682e0047da3 |
|
BLAKE2b-256 | 56d14dfecd568f2558b166974ad372df9a4e188b207e010ddc8657b4e3c7cdad |