From 6c0449ebada82cf973bc8a3bbba3d2ebe969602c Mon Sep 17 00:00:00 2001 From: posativ <info@posativ.org> Date: Sat, 21 Apr 2012 23:56:23 +0200 Subject: [PATCH] last enhancements to README and quickstart successor bin/klaus --- README.rst | 22 ++++++++++----------- bin/klaus | 8 +++++--- requirements.txt | 1 + tools/quickstart.py | 48 --------------------------------------------- 4 files changed, 16 insertions(+), 63 deletions(-) delete mode 100755 tools/quickstart.py diff --git a/README.rst b/README.rst index 8915dc8..7bddf8b 100644 --- a/README.rst +++ b/README.rst @@ -39,34 +39,32 @@ Installation git clone https://github.com/jonashaag/klaus cd klaus - git submodule update --init pip install -r requirements.txt Usage ----- -Using the ``quickstart.py`` script +Using the ``klaus`` script .................................. + :: - tools/quickstart --help - tools/quickstart.py <host> <port> /path/to/repo1 [../path/to/repo2 [...]] + $ klaus --help + $ klaus -i <host> -p <port> /path/to/repo1 [../path/to/repo2 [...]] Example:: - tools/quickstart.py 127.0.0.1 8080 ../klaus ../nano ../bjoern + $ klaus ../klaus ../bjoern -This will make klaus serve the *klaus*, *nano* and *bjoern* repos at -``127.0.0.1:8080`` using Python's built-in wsgiref_ server (or, if installed, -the bjoern_ server). +This will make klaus serve the *klaus* and *bjoern* repos at +``127.0.0.1:8080`` using werkzeug's builtin run_simple server. .. _wsgiref: http://docs.python.org/library/wsgiref.html .. _bjoern: https://github.com/jonashaag/bjoern -Using a real server -................... -The ``klaus.py`` module contains a WSGI ``application`` object. The repo list -is read from the ``KLAUS_REPOS`` environment variable (space-separated paths). +Using a real server ................... The ``klaus/__init__.py`` module +contains a WSGI ``make_app`` function which returns the app. The repo list is +read from the ``KLAUS_REPOS`` environment variable (space-separated paths). UWSGI example:: diff --git a/bin/klaus b/bin/klaus index 4056b57..4c16b1e 100755 --- a/bin/klaus +++ b/bin/klaus @@ -13,8 +13,10 @@ if __name__ == '__main__': usage = "usage: %prog [options] dir [dirs]" options = [ + make_option("-i", default="127.0.0.1", dest="interface", + help="bind to host/address (default: 127.0.0.1)"), make_option("-p", "--port", type=int, default=8080, dest="port", - help="webserver port"), + help="webserver port (default: 8080)"), make_option("-r", "--use-reloader", action="store_true", dest="reloader", help=SUPPRESS_HELP, default=False), ] @@ -22,7 +24,7 @@ if __name__ == '__main__': parser = OptionParser(option_list=options, usage=usage, epilog="klaus, a simple Git viewer") (options, args) = parser.parse_args() - if len(args) == 1: + if len(args) == 0: parser.print_usage() exit(2) @@ -31,4 +33,4 @@ if __name__ == '__main__': exit(1) app = make_app(args) - run_simple('127.0.0.1', options.port, app, use_reloader=options.reloader) + run_simple(options.interface, options.port, app, use_reloader=options.reloader) diff --git a/requirements.txt b/requirements.txt index be3fead..e126221 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +werkzeug jinja2 pygments dulwich diff --git a/tools/quickstart.py b/tools/quickstart.py deleted file mode 100755 index 2915ac0..0000000 --- a/tools/quickstart.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python2 -# coding: utf-8 -import sys, os -import argparse - -try: - import nano -except ImportError: - sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'nano')) - try: - import nano - except ImportError: - raise ImportError( - "Could not find a copy of nano (https://github.com/jonashaag/nano). " - "Use 'git submodule update --init' to initialize the nano submodule " - "or copy the 'nano.py' into the klaus root directory by hand." - ) - -try: - from bjoern import run -except ImportError: - from wsgiref.simple_server import make_server - def run(app, host, port): - make_server(host, port, app).serve_forever() - -def valid_directory(path): - if not os.path.exists(path): - raise argparse.ArgumentTypeError('%r: No such directory' % path) - return path - -def main(): - parser = argparse.ArgumentParser(epilog='Gemüse kaufen!') - parser.add_argument('host', help='(without http://)') - parser.add_argument('port', type=int) - parser.add_argument('--display-host', dest='custom_host') - parser.add_argument('repo', nargs='+', type=valid_directory, - help='repository directories to serve') - args = parser.parse_args() - sys.argv = ['this is a hack'] + args.repo - - from klaus import app - if args.custom_host: - app.custom_host = args.custom_host - - run(app, args.host, args.port) - -if __name__ == '__main__': - main() -- GitLab