GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - six8/python-clom: The easiest way to run shell commands with Python. A python command line object mapper.

BranchesTags
Open more actions menu

Latest commit

 

History

64 Commits
64 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
requirements.d
requirements.d
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
Makefile
Makefile
 
 
README.rst
README.rst
 
 
VERSION.txt
VERSION.txt
 
 
fabfile.py
fabfile.py
 
 
pytest.ini
pytest.ini
 
 
runtests
runtests
 
 
setup.py
setup.py
 
 

Repository files navigation

Clom is a Python Command Line Object Mapper. It's intended to make generating commands and escaping arguments easier for command line interaction. It's particularly useful when used with Fabric or subprocess.

  • Documentation
  • Clom on GitHub
  • Clom on Pypi

Installation

Install with pip or easy_install.

pip install clom

Usage Examples

Import:

>>> from clom import clom

Build a command:

>>> clom.echo("Don't test me")
"echo 'Don'\\''t test me'"

Augment with arguments:

>>> clom.ls.with_opts('-a', '-t', l=True).with_args('~/')
"ls -a -t -l '~/'"
>>> clom.curl('http://dev.host', X='POST', data='message=hello')
'curl -X POST --data=message=hello http://dev.host'

Use sub commands:

>>> clom.git.checkout('mybranch')
'git checkout mybranch'

Execute with ease:

>>> clom.seq(5).shell.all()
['1', '2', '3', '4', '5']

>>> clom.seq.shell('5').first()
'1'

Iterate over results:

>>> for i in clom.seq(3).shell():
...     print(i)
...
1
2
3

Handle errors:

>>> clom.touch('/not/a/thing').shell()      # doctest:+IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
  ...
CommandError: Error while executing "touch /not/a/thing" (1):
touch: cannot touch ‘/not/a/thing’: No such file or directory

Group commands:

>>> from clom import AND, OR
>>> OR(clom.vagrant.up, clom.echo('Vagrant up failed'))
"( vagrant up || echo 'Vagrant up failed' )"
>>> OR(clom.vagrant.up, clom.echo('Vagrant up failed')).shell()
<CommandResult return_code=0, stdout=18 bytes, stderr=... bytes>
>>> print(OR(clom.false, clom.echo('Vagrant up failed')).shell())
Vagrant up failed

Re-use commands:

>>> echo = clom.echo
>>> echo.one.two
'echo one two'
>>> echo.three.four.shell.all()
['three four']
>>> echo.foo.bar.shell.all()
['foo bar']

Background tasks:

>>> clom.VBoxHeadless.with_opts(startvm="Windows Base").background()
"nohup VBoxHeadless --startvm='Windows Base' &> /dev/null &"
>>> clom.VBoxHeadless.with_opts(startvm="Windows Base").background().shell()
<CommandResult return_code=0, stdout=0 bytes, stderr=0 bytes>

Works great with fabric:

>>> from fabric.api import run, local           # doctest: +SKIP
>>> local(clom.ls)                              # doctest: +SKIP
[localhost] local: ls
clom            clom.egg-info   docs            nohup.out       tests
''

Can even create fab commands:

>>> clom.fab.test('doctest', 'unit').deploy('dev')
'fab test:doctest,unit deploy:dev'
>>> clom.fab.with_opts('-a', hosts='dev.host').deploy.with_args('dev','test')
'fab -a --hosts=dev.host deploy:dev,test'

See more examples and the API in the Clom Documentation

Running Tests

Test are run using pytest:

pip install pytest
./runtests -v

About

The easiest way to run shell commands with Python. A python command line object mapper.

clom.rtfd.org/

Resources

Readme
MIT license
Activity

Stars

27 stars

Watchers

4 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.