diff options
| author | 2014-02-28 08:49:38 -0300 | |
|---|---|---|
| committer | 2014-02-28 08:49:38 -0300 | |
| commit | 2828399ba5cbb14502b023d4de1ba02f13dd5055 (patch) | |
| tree | 38012b6bacaa508ca56fb6f4ba87b912bb54b8c9 /nikola/plugins/command/auto.py | |
| parent | ca94afc07df55cb7fc6fe3b4f3011877b7881195 (diff) | |
Imported Upstream version 6.3.0upstream/6.3.0
Diffstat (limited to 'nikola/plugins/command/auto.py')
| -rw-r--r-- | nikola/plugins/command/auto.py | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/nikola/plugins/command/auto.py b/nikola/plugins/command/auto.py index cb726d9..01116d1 100644 --- a/nikola/plugins/command/auto.py +++ b/nikola/plugins/command/auto.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -26,30 +26,13 @@ from __future__ import print_function, unicode_literals -import codecs -import json import os import subprocess +import webbrowser from nikola.plugin_categories import Command from nikola.utils import req_missing -GUARDFILE = """#!/usr/bin/env python -# -*- coding: utf-8 -*- -from livereload.task import Task -import json -import subprocess - -def f(): - import subprocess - subprocess.call(("nikola", "build")) - -fdata = json.loads('''{0}''') - -for watch in fdata: - Task.add(watch, f) -""" - class Auto(Command): """Start debugging console.""" @@ -76,9 +59,9 @@ class Auto(Command): def _execute(self, options, args): """Start the watcher.""" try: - from livereload.server import start + from livereload import Server except ImportError: - req_missing(['livereload'], 'use the "auto" command') + req_missing(['livereload>=2.0.0'], 'use the "auto" command') return # Run an initial build so we are uptodate @@ -86,18 +69,18 @@ class Auto(Command): port = options and options.get('port') - # Create a Guardfile - with codecs.open("Guardfile", "wb+", "utf8") as guardfile: - l = ["conf.py", "themes", "templates", self.site.config['GALLERY_PATH']] - for item in self.site.config['post_pages']: - l.append(os.path.dirname(item[0])) - for item in self.site.config['FILES_FOLDERS']: - l.append(os.path.dirname(item)) - data = GUARDFILE.format(json.dumps(l)) - guardfile.write(data) + server = Server() + server.watch('conf.py') + server.watch('themes/') + server.watch('templates/') + server.watch(self.site.config['GALLERY_PATH']) + for item in self.site.config['post_pages']: + server.watch(os.path.dirname(item[0])) + for item in self.site.config['FILES_FOLDERS']: + server.watch(os.path.dirname(item)) out_folder = self.site.config['OUTPUT_FOLDER'] + if options and options.get('browser'): + webbrowser.open('http://localhost:{0}'.format(port)) - os.chmod("Guardfile", 0o755) - - start(port, out_folder, options and options.get('browser')) + server.serve(port, out_folder) |
