diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2015-05-06 10:17:30 -0400 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2015-05-06 10:17:56 -0400 |
commit | ca2e90a94031fdbba31bf4bda87b51a87e97eb7c (patch) | |
tree | fb7475ce51ddc4d8807900553d52eff682fe4f9e /demoapp | |
parent | 79a8791e7fefdcbe62f264bf905ac09a1958e753 (diff) | |
download | cliff-master.tar.gz |
Diffstat (limited to 'demoapp')
-rw-r--r-- | demoapp/README.rst | 64 | ||||
-rw-r--r-- | demoapp/cliffdemo/__init__.py | 0 | ||||
-rw-r--r-- | demoapp/cliffdemo/encoding.py | 23 | ||||
-rw-r--r-- | demoapp/cliffdemo/list.py | 18 | ||||
-rw-r--r-- | demoapp/cliffdemo/main.py | 37 | ||||
-rw-r--r-- | demoapp/cliffdemo/show.py | 31 | ||||
-rw-r--r-- | demoapp/cliffdemo/simple.py | 24 | ||||
-rw-r--r-- | demoapp/setup.py | 67 |
8 files changed, 0 insertions, 264 deletions
diff --git a/demoapp/README.rst b/demoapp/README.rst deleted file mode 100644 index 24ca9b6..0000000 --- a/demoapp/README.rst +++ /dev/null @@ -1,64 +0,0 @@ -================= - Running demoapp -================= - -Setup ------ - -First, you need to create a virtual environment and activate it. - -:: - - $ pip install virtualenv - $ virtualenv .venv - $ . .venv/bin/activate - (.venv)$ - -Next, install ``cliff`` in the environment. - -:: - - (.venv)$ python setup.py install - -Now, install the demo application into the virtual environment. - -:: - - (.venv)$ cd demoapp - (.venv)$ python setup.py install - -Usage ------ - -With cliff and the demo setup up, you can now play with it. - -To see a list of commands available, run:: - - (.venv)$ cliffdemo --help - -One of the available commands is "simple" and running it - -:: - - (.venv)$ cliffdemo simple - -produces the following - -:: - - sending greeting - hi! - - -To see help for an individual command, include the command name on the -command line:: - - (.venv)$ cliffdemo files --help - -Cleaning Up ------------ - -Finally, when done, deactivate your virtual environment:: - - (.venv)$ deactivate - $ diff --git a/demoapp/cliffdemo/__init__.py b/demoapp/cliffdemo/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/demoapp/cliffdemo/__init__.py +++ /dev/null diff --git a/demoapp/cliffdemo/encoding.py b/demoapp/cliffdemo/encoding.py deleted file mode 100644 index 6c6c751..0000000 --- a/demoapp/cliffdemo/encoding.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- encoding: utf-8 -*- - -import logging - -from cliff.lister import Lister - - -class Encoding(Lister): - """Show some unicode text - """ - - log = logging.getLogger(__name__) - - def take_action(self, parsed_args): - messages = [ - u'pi: π', - u'GB18030:鼀丅㐀ٸཌྷᠧꌢ€', - ] - return ( - ('UTF-8', 'Unicode'), - [(repr(t.encode('utf-8')), t) - for t in messages], - ) diff --git a/demoapp/cliffdemo/list.py b/demoapp/cliffdemo/list.py deleted file mode 100644 index 3dcee4a..0000000 --- a/demoapp/cliffdemo/list.py +++ /dev/null @@ -1,18 +0,0 @@ -import logging -import os - -from cliff.lister import Lister - - -class Files(Lister): - """Show a list of files in the current directory. - - The file name and size are printed by default. - """ - - log = logging.getLogger(__name__) - - def take_action(self, parsed_args): - return (('Name', 'Size'), - ((n, os.stat(n).st_size) for n in os.listdir('.')) - ) diff --git a/demoapp/cliffdemo/main.py b/demoapp/cliffdemo/main.py deleted file mode 100644 index 85807c8..0000000 --- a/demoapp/cliffdemo/main.py +++ /dev/null @@ -1,37 +0,0 @@ -import logging -import sys - -from cliff.app import App -from cliff.commandmanager import CommandManager - - -class DemoApp(App): - - log = logging.getLogger(__name__) - - def __init__(self): - super(DemoApp, self).__init__( - description='cliff demo app', - version='0.1', - command_manager=CommandManager('cliff.demo'), - ) - - def initialize_app(self, argv): - self.log.debug('initialize_app') - - def prepare_to_run_command(self, cmd): - self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__) - - def clean_up(self, cmd, result, err): - self.log.debug('clean_up %s', cmd.__class__.__name__) - if err: - self.log.debug('got an error: %s', err) - - -def main(argv=sys.argv[1:]): - myapp = DemoApp() - return myapp.run(argv) - - -if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) diff --git a/demoapp/cliffdemo/show.py b/demoapp/cliffdemo/show.py deleted file mode 100644 index 9351148..0000000 --- a/demoapp/cliffdemo/show.py +++ /dev/null @@ -1,31 +0,0 @@ -import logging -import os - -from cliff.show import ShowOne - - -class File(ShowOne): - "Show details about a file" - - log = logging.getLogger(__name__) - - def get_parser(self, prog_name): - parser = super(File, self).get_parser(prog_name) - parser.add_argument('filename', nargs='?', default='.') - return parser - - def take_action(self, parsed_args): - stat_data = os.stat(parsed_args.filename) - columns = ('Name', - 'Size', - 'UID', - 'GID', - 'Modified Time', - ) - data = (parsed_args.filename, - stat_data.st_size, - stat_data.st_uid, - stat_data.st_gid, - stat_data.st_mtime, - ) - return (columns, data) diff --git a/demoapp/cliffdemo/simple.py b/demoapp/cliffdemo/simple.py deleted file mode 100644 index 3800514..0000000 --- a/demoapp/cliffdemo/simple.py +++ /dev/null @@ -1,24 +0,0 @@ -import logging - -from cliff.command import Command - - -class Simple(Command): - "A simple command that prints a message." - - log = logging.getLogger(__name__) - - def take_action(self, parsed_args): - self.log.info('sending greeting') - self.log.debug('debugging') - self.app.stdout.write('hi!\n') - - -class Error(Command): - "Always raises an error" - - log = logging.getLogger(__name__) - - def take_action(self, parsed_args): - self.log.info('causing error') - raise RuntimeError('this is the expected exception') diff --git a/demoapp/setup.py b/demoapp/setup.py deleted file mode 100644 index 4bef32e..0000000 --- a/demoapp/setup.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python - -PROJECT = 'cliffdemo' - -# Change docs/sphinx/conf.py too! -VERSION = '0.1' - -from setuptools import setup, find_packages - -try: - long_description = open('README.rst', 'rt').read() -except IOError: - long_description = '' - -setup( - name=PROJECT, - version=VERSION, - - description='Demo app for cliff', - long_description=long_description, - - author='Doug Hellmann', - author_email='doug.hellmann@gmail.com', - - url='https://github.com/dreamhost/cliff', - download_url='https://github.com/dreamhost/cliff/tarball/master', - - classifiers=['Development Status :: 3 - Alpha', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Intended Audience :: Developers', - 'Environment :: Console', - ], - - platforms=['Any'], - - scripts=[], - - provides=[], - install_requires=['cliff'], - - namespace_packages=[], - packages=find_packages(), - include_package_data=True, - - entry_points={ - 'console_scripts': [ - 'cliffdemo = cliffdemo.main:main' - ], - 'cliff.demo': [ - 'simple = cliffdemo.simple:Simple', - 'two_part = cliffdemo.simple:Simple', - 'error = cliffdemo.simple:Error', - 'list files = cliffdemo.list:Files', - 'files = cliffdemo.list:Files', - 'file = cliffdemo.show:File', - 'show file = cliffdemo.show:File', - 'unicode = cliffdemo.encoding:Encoding', - ], - }, - - zip_safe=False, -) |