Klaus Demo ~jonashaag/klaus / 6c0449e
last enhancements to README and quickstart successor bin/klaus posativ 10 years ago
4 changed file(s) with 16 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
3838
3939 git clone https://github.com/jonashaag/klaus
4040 cd klaus
41 git submodule update --init
4241 pip install -r requirements.txt
4342
4443
4544 Usage
4645 -----
47 Using the ``quickstart.py`` script
46 Using the ``klaus`` script
4847 ..................................
48
4949 ::
5050
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 [...]]
5353
5454 Example::
5555
56 tools/quickstart.py 127.0.0.1 8080 ../klaus ../nano ../bjoern
56 $ klaus ../klaus ../bjoern
5757
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.
6160
6261 .. _wsgiref: http://docs.python.org/library/wsgiref.html
6362 .. _bjoern: https://github.com/jonashaag/bjoern
6463
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).
6967
7068 UWSGI example::
7169
1212 usage = "usage: %prog [options] dir [dirs]"
1313
1414 options = [
15 make_option("-i", default="127.0.0.1", dest="interface",
16 help="bind to host/address (default: 127.0.0.1)"),
1517 make_option("-p", "--port", type=int, default=8080, dest="port",
16 help="webserver port"),
18 help="webserver port (default: 8080)"),
1719 make_option("-r", "--use-reloader", action="store_true", dest="reloader",
1820 help=SUPPRESS_HELP, default=False),
1921 ]
2123 parser = OptionParser(option_list=options, usage=usage, epilog="klaus, a simple Git viewer")
2224 (options, args) = parser.parse_args()
2325
24 if len(args) == 1:
26 if len(args) == 0:
2527 parser.print_usage()
2628 exit(2)
2729
3032 exit(1)
3133
3234 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 werkzeug
01 jinja2
12 pygments
23 dulwich
+0
-48
tools/quickstart.py less more
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()