Skip to main content

The small framework for sub commands.

Project description

jumon is a small framework for sub commands.

The jumon is a small framework for implementing the sub command. You can be implemented sub commands, as the hierarchial structure of the sub modules in the packages. It finds importable sub module from the arguments passed, Runs main function in the importable sub module with arguments.

You can be displayed the hierarchial structure of the sub commands with tree command etc, because it be implementing sub commands as the hierarchial structure of the sub module. It will be easy to see where sub command has been implemented.

Please consider to use jumon, if you are trying to implement the sub commands.

Installing

Use setup.py in the source code root directory:

$ python setup.py install

by pip (from PyPI)

$ pip install jumon

How to use

This is a description of how to use the jumon. Let create a package called “testcmd”, and sub package called “testcmd.command”.

$ mkdir testcmd
$ touch testcmd/__init__.py
$ mkdir testcmd/command

Let implementing sub commands in “testcmd.command” subordinate.

First, create top level command.:

$ touch testcmd/command/__init__.py

testcmd/command/__init__.py:

import jumon

def main():
    jumon.entry(__name__)

Under this package is the search range of sub commands.

Next, create sub command.:

$ touch testcmd/command/aaa.py

testcmd/command/aaa.py:

def main(argv):
    print 'OK'
    return 0

This commamd is printed string “OK”, and end with exit code 0.

You can be implemented sub command of sub command.:

$ mkdir testcmd/command/bbb
$ touch testcmd/command/bbb/__init__.py
$ touch testcmd/command/bbb/ccc.py

testcmd/command/bbb/__init__.py:

def main(argv):
    print 'bbb'
    return 1

testcmd/command/bbb/ccc.py:

def main(argv):
    print 'ccc'
    return 2

I implemented sub commands, called “bbb” and “bbb ccc”. This commamd “bbb” is printed string “bbb”, and end with exit code 1. This commamd “bbb ccc” is printed string “ccc”, and end with exit code 2.

Next, install “testcmd”.:

$ cp testcmd $SITE_PACKAGES -R

Last, create command.:

$ touch test.py

test.py:

#! /usr/bin/env python
import testcmd.command

def main():
    testcmd.command.main()

if __name__ == '__main__':
    main()

Add permission:

$ chmod 755 test.py

Run, displayed usage.:

$ ./test.py
Usage: test.py [options]

test.py: error: Command Not Found:

Run sub command “aaa”.:

$ ./test.py aaa
OK
$ echo $?
0

Run sub command “bbb”.:

$ ./test.py bbb
bbb
$ echo $?
1

Run sub command “bbb ccc”.:

$ ./test.py bbb ccc
ccc
$ echo $?
2

Do you want to created command with setup.py?

setup.py:

#-*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
    name='testcmd',
    version='1',
    license='BSD',
    author='TakesxiSximada',
    author_email='takesxi.sximada@gmail.com',
    packages=find_packages(),
    entry_points = """\
    [console_scripts]
    testcmd = testcmd.command:main
    """
)

This is important:

entry_points = """\
[console_scripts]
testcmd = testcmd.command:main
"""

Do you want to transparenting the undefined options?

You can use jumon.TransparentOptionParser() class.

>>> import jumon
>>> parser = jumon.TransparentOptionParser()
>>> opts, args = parser.parse_args(['-f', '-n', '1'])
>>> args
['-f', '-n', '1']

Requirements

  • Python 2.6 or laterr (not supprt 3.x)

License

Apache License 2.0

Project details


Download files

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

Source Distribution

jumon-1.1.4.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file jumon-1.1.4.tar.gz.

File metadata

  • Download URL: jumon-1.1.4.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jumon-1.1.4.tar.gz
Algorithm Hash digest
SHA256 09b5772c949c7b69bc954575ee9006da88a11b635cd49acad0c766714e2451d2
MD5 e2e4d7bd922dc63a035b024dc71ef35a
BLAKE2b-256 8d566dc3988907755276db463ff3badc6498e57b7e82ee0b4988f05db16428aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page