Eclectic Media Git klaus / 4350ec0
add option to auto-launch browser on server Add command-line argument --browser (shortened to -b) which will auto-launch a web-browser pointing to the Klaus server via the Python webbrowser module. Note that we do things in the wrong order in that we launch the browser and *then* start the server. In the absence of a cleaner way of getting a function to run after server setup this approach actually works in practice. If this doesn't Just Work for someone we can think again about more complex options. Rich Wareham 5 years ago
1 changed file(s) with 11 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
33 import sys
44 import os
55 import argparse
6 from webbrowser import open as open_url
67
78 from dulwich.errors import NotGitRepository
89 from dulwich.repo import Repo
2728 parser.add_argument('--host', help="default: 127.0.0.1", default='127.0.0.1')
2829 parser.add_argument('--port', help="default: 8080", default=8080, type=int)
2930 parser.add_argument('--site-name', help="site name showed in header. default: your hostname")
31 parser.add_argument('-b', '--browser', help="launch a browser on server start",
32 action='store_true', default=False)
3033
3134 parser.add_argument('repos', help='repositories to serve',
3235 metavar='DIR', nargs='*', type=git_repository)
5962 args.htdigest
6063 )
6164
65 if args.browser:
66 # Open a web browser onto the server URL. Technically we're jumping the
67 # gun a little here since the server is not running but there's not a
68 # clean way to run a function after the server has started without
69 # losing the simplicity of the code. In the Real World (TM) it'll take
70 # longer for the browser to start than it will for use to start
71 # serving.
72 open_url('http://%s:%s' % (args.host, args.port))
6273 app.run(args.host, args.port, args.debug)
6374
6475