Skip to content
Permalink
Browse files
IPv6 in nikola auto + nikola serve fixes (#1682)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 4, 2015
1 parent 27b1cf4 commit 2ca8124e1e28d38c9384a1cfc7f2d17d87dfe92d
Showing with 38 additions and 8 deletions.
  1. +1 −0 CHANGES.txt
  2. +30 −7 nikola/plugins/command/auto.py
  3. +7 −1 nikola/plugins/command/serve.py
@@ -4,6 +4,7 @@ New in master
Features
--------

* Allow IPv6 in `nikola auto` (Issue #1682)
* Allow IPv6 in `nikola serve` (Issue #1682)
* Set default new site URL to https://example.com/
* Plugins can manipulate task dependencies (Issue #1679)
@@ -38,6 +38,22 @@ class CommandAuto(Command):
name = "auto"
doc_purpose = "automatically detect site changes, rebuild and optionally refresh a browser"
cmd_options = [
{
'name': 'port',
'short': 'p',
'long': 'port',
'default': 8000,
'type': int,
'help': 'Port nummber (default: 8000)',
},
{
'name': 'address',
'short': 'a',
'long': 'address',
'type': str,
'default': '',
'help': 'Address to bind (default: 0.0.0.0 – all local IPv4 interfaces)',
},
{
'name': 'browser',
'short': 'b',
@@ -46,12 +62,12 @@ class CommandAuto(Command):
'default': False,
},
{
'name': 'port',
'short': 'p',
'long': 'port',
'default': 8000,
'type': int,
'help': 'Port nummber (default: 8000)',
'name': 'ipv6',
'short': '6',
'long': 'ipv6',
'default': False,
'type': bool,
'help': 'Use IPv6',
},
]

@@ -93,4 +109,11 @@ def _execute(self, options, args):
else:
browser = False

server.serve(port=port, host=None, root=out_folder, debug=True, open_url=browser)
if options['ipv6']:
dhost = '::'
else:
dhost = None

host = options['address'].strip('[').strip(']') or dhost

server.serve(port=port, host=host, root=out_folder, debug=True, open_url=browser)
@@ -97,18 +97,24 @@ def _execute(self, options, args):
os.chdir(out_dir)
if '[' in options['address']:
options['address'] = options['address'].strip('[').strip(']')
ipv6 = True
OurHTTP = IPv6Server
elif options['ipv6']:
ipv6 = True
OurHTTP = IPv6Server
else:
ipv6 = False
OurHTTP = HTTPServer

httpd = OurHTTP((options['address'], options['port']),
OurHTTPRequestHandler)
sa = httpd.socket.getsockname()
self.logger.info("Serving HTTP on {0} port {1}...".format(*sa))
if options['browser']:
server_url = "http://{0}:{1}/".format(*sa)
if ipv6:
server_url = "http://[{0}]:{1}/".format(*sa)
else:
server_url = "http://{0}:{1}/".format(*sa)
self.logger.info("Opening {0} in the default web browser...".format(server_url))
webbrowser.open(server_url)
try:

0 comments on commit 2ca8124

Please sign in to comment.