last enhancements to README and quickstart successor bin/klaus
posativ
10 years ago
38 | 38 | |
39 | 39 | git clone https://github.com/jonashaag/klaus |
40 | 40 | cd klaus |
41 | git submodule update --init | |
42 | 41 | pip install -r requirements.txt |
43 | 42 | |
44 | 43 | |
45 | 44 | Usage |
46 | 45 | ----- |
47 | Using the ``quickstart.py`` script | |
46 | Using the ``klaus`` script | |
48 | 47 | .................................. |
48 | ||
49 | 49 | :: |
50 | 50 | |
51 | tools/quickstart --help | |
52 | tools/quickstart.py <host> <port> /path/to/repo1 [../path/to/repo2 [...]] | |
51 | $ klaus --help | |
52 | $ klaus -i <host> -p <port> /path/to/repo1 [../path/to/repo2 [...]] | |
53 | 53 | |
54 | 54 | Example:: |
55 | 55 | |
56 | tools/quickstart.py 127.0.0.1 8080 ../klaus ../nano ../bjoern | |
56 | $ klaus ../klaus ../bjoern | |
57 | 57 | |
58 | This will make klaus serve the *klaus*, *nano* and *bjoern* repos at | |
59 | ``127.0.0.1:8080`` using Python's built-in wsgiref_ server (or, if installed, | |
60 | the bjoern_ server). | |
58 | This will make klaus serve the *klaus* and *bjoern* repos at | |
59 | ``127.0.0.1:8080`` using werkzeug's builtin run_simple server. | |
61 | 60 | |
62 | 61 | .. _wsgiref: http://docs.python.org/library/wsgiref.html |
63 | 62 | .. _bjoern: https://github.com/jonashaag/bjoern |
64 | 63 | |
65 | Using a real server | |
66 | ................... | |
67 | The ``klaus.py`` module contains a WSGI ``application`` object. The repo list | |
68 | is read from the ``KLAUS_REPOS`` environment variable (space-separated paths). | |
64 | Using a real server ................... The ``klaus/__init__.py`` module | |
65 | contains a WSGI ``make_app`` function which returns the app. The repo list is | |
66 | read from the ``KLAUS_REPOS`` environment variable (space-separated paths). | |
69 | 67 | |
70 | 68 | UWSGI example:: |
71 | 69 |
12 | 12 | usage = "usage: %prog [options] dir [dirs]" |
13 | 13 | |
14 | 14 | options = [ |
15 | make_option("-i", default="127.0.0.1", dest="interface", | |
16 | help="bind to host/address (default: 127.0.0.1)"), | |
15 | 17 | make_option("-p", "--port", type=int, default=8080, dest="port", |
16 | help="webserver port"), | |
18 | help="webserver port (default: 8080)"), | |
17 | 19 | make_option("-r", "--use-reloader", action="store_true", dest="reloader", |
18 | 20 | help=SUPPRESS_HELP, default=False), |
19 | 21 | ] |
21 | 23 | parser = OptionParser(option_list=options, usage=usage, epilog="klaus, a simple Git viewer") |
22 | 24 | (options, args) = parser.parse_args() |
23 | 25 | |
24 | if len(args) == 1: | |
26 | if len(args) == 0: | |
25 | 27 | parser.print_usage() |
26 | 28 | exit(2) |
27 | 29 | |
30 | 32 | exit(1) |
31 | 33 | |
32 | 34 | app = make_app(args) |
33 | run_simple('127.0.0.1', options.port, app, use_reloader=options.reloader) | |
35 | run_simple(options.interface, options.port, app, use_reloader=options.reloader) |
0 | #!/usr/bin/env python2 | |
1 | # coding: utf-8 | |
2 | import sys, os | |
3 | import argparse | |
4 | ||
5 | try: | |
6 | import nano | |
7 | except ImportError: | |
8 | sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'nano')) | |
9 | try: | |
10 | import nano | |
11 | except ImportError: | |
12 | raise ImportError( | |
13 | "Could not find a copy of nano (https://github.com/jonashaag/nano). " | |
14 | "Use 'git submodule update --init' to initialize the nano submodule " | |
15 | "or copy the 'nano.py' into the klaus root directory by hand." | |
16 | ) | |
17 | ||
18 | try: | |
19 | from bjoern import run | |
20 | except ImportError: | |
21 | from wsgiref.simple_server import make_server | |
22 | def run(app, host, port): | |
23 | make_server(host, port, app).serve_forever() | |
24 | ||
25 | def valid_directory(path): | |
26 | if not os.path.exists(path): | |
27 | raise argparse.ArgumentTypeError('%r: No such directory' % path) | |
28 | return path | |
29 | ||
30 | def main(): | |
31 | parser = argparse.ArgumentParser(epilog='Gemüse kaufen!') | |
32 | parser.add_argument('host', help='(without http://)') | |
33 | parser.add_argument('port', type=int) | |
34 | parser.add_argument('--display-host', dest='custom_host') | |
35 | parser.add_argument('repo', nargs='+', type=valid_directory, | |
36 | help='repository directories to serve') | |
37 | args = parser.parse_args() | |
38 | sys.argv = ['this is a hack'] + args.repo | |
39 | ||
40 | from klaus import app | |
41 | if args.custom_host: | |
42 | app.custom_host = args.custom_host | |
43 | ||
44 | run(app, args.host, args.port) | |
45 | ||
46 | if __name__ == '__main__': | |
47 | main() |