Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Library for wrapping CLI commands with static configuration.

Project Description
abcmd
=====

.. image:: https://img.shields.io/pypi/v/abcmd.svg
:target: https://pypi.python.org/pypi/abcmd
:alt: Latest PyPI version

.. image:: https://travis-ci.org/modulus-sa/abcmd.svg?branch=master
:target: https://travis-ci.org/modulus-sa/abcmd

.. image:: https://codecov.io/gh/modulus-sa/abcmd/branch/master/graph/badge.svg
:target: https://codecov.io/gh/modulus-sa/abcmd

A library for wrapping shell commands with static configuration.

Usage
-----

The library provides the ``abcmd.Command`` ABC that can be used
to create shell command wrappers.

Examples
--------

Automating backup of dotfiles

First we subclass ``Command`` and describe the procedure:

.. code-block:: python

import datetime
import os

import abcmd

class Backup(abcmd.Command):
make = 'mkdir {directory}'
copy = 'cp {files} {directory}'
sync = 'rsync {directory} {user}@{server}:'

def run(self, *args, **kwargs):
os.chdir(os.environ['HOME'])
self.make()
self.copy()
self.sync()

def dont_run(self, *args, **kwargs):
# don't run between working hours
return dt.datetime.now().hour in range(8, 16)

def handle_error(self, cmd, error):
# if the backup directory exists ignore the error and continue
return cmd.startswith('mkdir') and error.endswith('File exists')

then we instantiate with a mapping that is used to render the templates,
this will return a callable object that when called will run the procedure:

.. code-block:: python

config = {
'user': 'laerus',
'directory': 'dotfiles',
'files': ['.vimrc', '.bashrc', '.inputrc'],
'server': '192.168.1.10'
}

runner = Backup(config)
runner()


This would be equivalent with running the following commands:

.. code-block:: shell

$ cd ~
$ mkdir dotfiles
$ cp .vimrc .bashrc .inputrc dotfiles
$ rsync dotfiles laerus@192.168.1.10:


Installation
------------

.. code-block:: shell

$ pip install abcmd

Compatibility
-------------
python3.5+

Licence
-------
MIT

Authors
-------

`abcmd` was written by `Konstantinos Tsakiltzidis <https://github.com/laerus>`_.
Release History

Release History

This version
History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
abcmd-0.3.2.tar.gz (4.4 kB) Copy SHA256 Checksum SHA256 Source Oct 10, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting