diff options
Diffstat (limited to 'nikola/plugins/command')
| -rw-r--r-- | nikola/plugins/command/__init__.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/auto.py | 49 | ||||
| -rw-r--r-- | nikola/plugins/command/bootswatch_theme.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/check.py | 53 | ||||
| -rw-r--r-- | nikola/plugins/command/console.plugin | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/console.py | 32 | ||||
| -rw-r--r-- | nikola/plugins/command/deploy.py | 15 | ||||
| -rw-r--r-- | nikola/plugins/command/import_blogger.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/import_feed.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/import_wordpress.py | 4 | ||||
| -rw-r--r-- | nikola/plugins/command/init.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/install_plugin.py | 12 | ||||
| -rw-r--r-- | nikola/plugins/command/install_theme.py | 45 | ||||
| -rw-r--r-- | nikola/plugins/command/mincss.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/new_post.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/orphans.plugin | 10 | ||||
| -rw-r--r-- | nikola/plugins/command/orphans.py | 45 | ||||
| -rw-r--r-- | nikola/plugins/command/planetoid/__init__.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/serve.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/command/version.py | 4 |
20 files changed, 178 insertions, 111 deletions
diff --git a/nikola/plugins/command/__init__.py b/nikola/plugins/command/__init__.py index 9be4d63..6ad8bac 100644 --- a/nikola/plugins/command/__init__.py +++ b/nikola/plugins/command/__init__.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 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) diff --git a/nikola/plugins/command/bootswatch_theme.py b/nikola/plugins/command/bootswatch_theme.py index eb27f94..94f37f2 100644 --- a/nikola/plugins/command/bootswatch_theme.py +++ b/nikola/plugins/command/bootswatch_theme.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 diff --git a/nikola/plugins/command/check.py b/nikola/plugins/command/check.py index 5c7e49a..a7e8c13 100644 --- a/nikola/plugins/command/check.py +++ b/nikola/plugins/command/check.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 @@ -40,6 +40,29 @@ from nikola.plugin_categories import Command from nikola.utils import get_logger +def real_scan_files(site): + task_fnames = set([]) + real_fnames = set([]) + output_folder = site.config['OUTPUT_FOLDER'] + # First check that all targets are generated in the right places + for task in os.popen('nikola list --all', 'r').readlines(): + task = task.strip() + if output_folder in task and ':' in task: + fname = task.split(':', 1)[-1] + task_fnames.add(fname) + # And now check that there are no non-target files + for root, dirs, files in os.walk(output_folder): + for src_name in files: + fname = os.path.join(root, src_name) + real_fnames.add(fname) + + only_on_output = list(real_fnames - task_fnames) + + only_on_input = list(task_fnames - real_fnames) + + return (only_on_output, only_on_input) + + class CommandCheck(Command): """Check the generated site.""" @@ -63,7 +86,7 @@ class CommandCheck(Command): 'long': 'check-files', 'type': bool, 'default': False, - 'help': 'Check for unknown files', + 'help': 'Check for unknown (orphaned and not generated) files', }, { 'name': 'clean', @@ -154,7 +177,7 @@ class CommandCheck(Command): failure = False self.logger.notice("Checking Files:") self.logger.notice("===============\n") - only_on_output, only_on_input = self.real_scan_files() + only_on_output, only_on_input = real_scan_files(self.site) # Ignore folders only_on_output = [p for p in only_on_output if not os.path.isdir(p)] @@ -162,7 +185,7 @@ class CommandCheck(Command): if only_on_output: only_on_output.sort() - self.logger.warn("Files from unknown origins:") + self.logger.warn("Files from unknown origins (orphans):") for f in only_on_output: self.logger.warn(f) failure = True @@ -180,25 +203,3 @@ class CommandCheck(Command): for f in only_on_output: os.unlink(f) return True - - def real_scan_files(self): - task_fnames = set([]) - real_fnames = set([]) - output_folder = self.site.config['OUTPUT_FOLDER'] - # First check that all targets are generated in the right places - for task in os.popen('nikola list --all', 'r').readlines(): - task = task.strip() - if output_folder in task and ':' in task: - fname = task.split(':', 1)[-1] - task_fnames.add(fname) - # And now check that there are no non-target files - for root, dirs, files in os.walk(output_folder): - for src_name in files: - fname = os.path.join(root, src_name) - real_fnames.add(fname) - - only_on_output = list(real_fnames - task_fnames) - - only_on_input = list(task_fnames - real_fnames) - - return (only_on_output, only_on_input) diff --git a/nikola/plugins/command/console.plugin b/nikola/plugins/command/console.plugin index a2be9ca..2eeedae 100644 --- a/nikola/plugins/command/console.plugin +++ b/nikola/plugins/command/console.plugin @@ -3,7 +3,7 @@ Name = console Module = console [Documentation] -Author = Roberto Alsina +Author = Chris Warrick, Roberto Alsina Version = 0.1 Website = http://getnikola.com Description = Start a debugging python console diff --git a/nikola/plugins/command/console.py b/nikola/plugins/command/console.py index fe17dfc..e66b650 100644 --- a/nikola/plugins/command/console.py +++ b/nikola/plugins/command/console.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Chris Warrick, Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -39,8 +39,21 @@ class Console(Command): """Start debugging console.""" name = "console" shells = ['ipython', 'bpython', 'plain'] - doc_purpose = "Start an interactive Python (IPython->bpython->plain) console with access to your site and configuration" + doc_purpose = "start an interactive Python console with access to your site" + doc_description = """\ +Order of resolution: IPython → bpython [deprecated] → plain Python interpreter +The site engine is accessible as `SITE`, and the config as `conf`.""" header = "Nikola v" + __version__ + " -- {0} Console (conf = configuration, SITE = site engine)" + cmd_options = [ + { + 'name': 'plain', + 'short': 'p', + 'long': 'plain', + 'type': bool, + 'default': False, + 'help': 'Force the plain Python console', + } + ] def ipython(self): """IPython shell.""" @@ -102,9 +115,12 @@ class Console(Command): def _execute(self, options, args): """Start the console.""" - for shell in self.shells: - try: - return getattr(self, shell)() - except ImportError: - pass - raise ImportError + if options['plain']: + self.plain() + else: + for shell in self.shells: + try: + return getattr(self, shell)() + except ImportError: + pass + raise ImportError diff --git a/nikola/plugins/command/deploy.py b/nikola/plugins/command/deploy.py index efb909d..eb5787e 100644 --- a/nikola/plugins/command/deploy.py +++ b/nikola/plugins/command/deploy.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 @@ -85,18 +85,17 @@ class Deploy(Command): sys.exit(e.returncode) self.logger.notice("Successful deployment") - if self.site.config['TIMEZONE'] is not None: - tzinfo = pytz.timezone(self.site.config['TIMEZONE']) - else: - tzinfo = pytz.UTC + tzinfo = pytz.timezone(self.site.config['TIMEZONE']) try: with open(timestamp_path, 'rb') as inf: last_deploy = literal_eval(inf.read().strip()) - # this might ignore DST - last_deploy = last_deploy.replace(tzinfo=tzinfo) + if tzinfo: + last_deploy = last_deploy.replace(tzinfo=tzinfo) clean = False except Exception: - last_deploy = datetime(1970, 1, 1).replace(tzinfo=tzinfo) + last_deploy = datetime(1970, 1, 1) + if tzinfo: + last_deploy = last_deploy.replace(tzinfo=tzinfo) clean = True new_deploy = datetime.now() diff --git a/nikola/plugins/command/import_blogger.py b/nikola/plugins/command/import_blogger.py index 53618b4..ea12b4a 100644 --- a/nikola/plugins/command/import_blogger.py +++ b/nikola/plugins/command/import_blogger.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 diff --git a/nikola/plugins/command/import_feed.py b/nikola/plugins/command/import_feed.py index b25d9ec..70a5cd5 100644 --- a/nikola/plugins/command/import_feed.py +++ b/nikola/plugins/command/import_feed.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 diff --git a/nikola/plugins/command/import_wordpress.py b/nikola/plugins/command/import_wordpress.py index 4f32198..0c9915a 100644 --- a/nikola/plugins/command/import_wordpress.py +++ b/nikola/plugins/command/import_wordpress.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 @@ -145,7 +145,7 @@ class CommandImportWordpress(Command, ImportMixin): rendered_template = re.sub('# REDIRECTIONS = ', 'REDIRECTIONS = ', rendered_template) if self.timezone: - rendered_template = re.sub('# TIMEZONE = \'Europe/Zurich\'', + rendered_template = re.sub('# TIMEZONE = \'UTC\'', 'TIMEZONE = \'' + self.timezone + '\'', rendered_template) self.write_configuration(self.get_configuration_output_path(), diff --git a/nikola/plugins/command/init.py b/nikola/plugins/command/init.py index 1873ec4..96caad8 100644 --- a/nikola/plugins/command/init.py +++ b/nikola/plugins/command/init.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 diff --git a/nikola/plugins/command/install_plugin.py b/nikola/plugins/command/install_plugin.py index fdbd0b7..1d6584d 100644 --- a/nikola/plugins/command/install_plugin.py +++ b/nikola/plugins/command/install_plugin.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 @@ -27,6 +27,7 @@ from __future__ import print_function import codecs import os +import sys import json import shutil import subprocess @@ -145,7 +146,6 @@ class CommandInstallPlugin(Command): shutil.copytree(plugin_path, dest_path) reqpath = os.path.join(dest_path, 'requirements.txt') - print(reqpath) if os.path.exists(reqpath): LOGGER.notice('This plugin has Python dependencies.') LOGGER.notice('Installing dependencies with pip...') @@ -180,6 +180,10 @@ class CommandInstallPlugin(Command): LOGGER.notice('This plugin has a sample config file.') print('Contents of the conf.py.sample file:\n') with codecs.open(confpypath, 'rb', 'utf-8') as fh: - print(indent(pygments.highlight( - fh.read(), PythonLexer(), TerminalFormatter()), 4 * ' ')) + if sys.platform == 'win32': + print(indent(pygments.highlight( + fh.read(), PythonLexer(), TerminalFormatter()), + 4 * ' ')) + else: + print(indent(fh.read(), 4 * ' ')) return True diff --git a/nikola/plugins/command/install_theme.py b/nikola/plugins/command/install_theme.py index a9d835a..569397b 100644 --- a/nikola/plugins/command/install_theme.py +++ b/nikola/plugins/command/install_theme.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,9 +26,10 @@ from __future__ import print_function import os +import sys +import codecs import json import shutil -import codecs from io import BytesIO import pygments @@ -116,18 +117,22 @@ class CommandInstallTheme(Command): print(theme) return True else: - self.do_install(name, data) - # See if the theme's parent is available. If not, install it - while True: - parent_name = utils.get_parent_theme_name(name) - if parent_name is None: - break - try: - utils.get_theme_path(parent_name) - break - except: # Not available - self.do_install(parent_name, data) - name = parent_name + # `name` may be modified by the while loop. + origname = name + installstatus = self.do_install(name, data) + # See if the theme's parent is available. If not, install it + while True: + parent_name = utils.get_parent_theme_name(name) + if parent_name is None: + break + try: + utils.get_theme_path(parent_name) + break + except: # Not available + self.do_install(parent_name, data) + name = parent_name + if installstatus: + LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(origname)) def do_install(self, name, data): if name in data: @@ -155,9 +160,13 @@ class CommandInstallTheme(Command): shutil.copytree(theme_path, dest_path) confpypath = os.path.join(dest_path, 'conf.py.sample') if os.path.exists(confpypath): - LOGGER.notice('This plugin has a sample config file.') + LOGGER.notice('This plugin has a sample config file. Integrate it with yours in order to make this theme work!') print('Contents of the conf.py.sample file:\n') with codecs.open(confpypath, 'rb', 'utf-8') as fh: - print(indent(pygments.highlight( - fh.read(), PythonLexer(), TerminalFormatter()), 4 * ' ')) - return True + if sys.platform == 'win32': + print(indent(pygments.highlight( + fh.read(), PythonLexer(), TerminalFormatter()), + 4 * ' ')) + else: + print(indent(fh.read(), 4 * ' ')) + return True diff --git a/nikola/plugins/command/mincss.py b/nikola/plugins/command/mincss.py index 5c9a7cb..0193458 100644 --- a/nikola/plugins/command/mincss.py +++ b/nikola/plugins/command/mincss.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 diff --git a/nikola/plugins/command/new_post.py b/nikola/plugins/command/new_post.py index ea0f3de..a5c551d 100644 --- a/nikola/plugins/command/new_post.py +++ b/nikola/plugins/command/new_post.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 diff --git a/nikola/plugins/command/orphans.plugin b/nikola/plugins/command/orphans.plugin new file mode 100644 index 0000000..408578b --- /dev/null +++ b/nikola/plugins/command/orphans.plugin @@ -0,0 +1,10 @@ +[Core] +Name = orphans +Module = orphans + +[Documentation] +Author = Roberto Alsina, Chris Warrick +Version = 0.1 +Website = http://getnikola.com +Description = List all orphans + diff --git a/nikola/plugins/command/orphans.py b/nikola/plugins/command/orphans.py new file mode 100644 index 0000000..ff114b4 --- /dev/null +++ b/nikola/plugins/command/orphans.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# Copyright © 2012-2014 Roberto Alsina, Chris Warrick and others. + +# Permission is hereby granted, free of charge, to any +# person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the +# Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the +# Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice +# shall be included in all copies or substantial portions of +# the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +from __future__ import print_function +import os + +from nikola.plugin_categories import Command +from nikola.plugins.command.check import real_scan_files + + +class CommandOrphans(Command): + name = "orphans" + doc_purpose = "list all orphans" + doc_description = """\ +List all orphans, i.e. all files that are in the output directory, +but are not generated by Nikola. + +Output contains filenames only (it is passable to `xargs rm` or the like).""" + + def _execute(self, options, args): + orphans = real_scan_files(self.site)[0] + print('\n'.join([p for p in orphans if not os.path.isdir(p)])) diff --git a/nikola/plugins/command/planetoid/__init__.py b/nikola/plugins/command/planetoid/__init__.py index 369862b..ff5dd13 100644 --- a/nikola/plugins/command/planetoid/__init__.py +++ b/nikola/plugins/command/planetoid/__init__.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 diff --git a/nikola/plugins/command/serve.py b/nikola/plugins/command/serve.py index 07403d4..2dd15c1 100644 --- a/nikola/plugins/command/serve.py +++ b/nikola/plugins/command/serve.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 diff --git a/nikola/plugins/command/version.py b/nikola/plugins/command/version.py index 65896e9..9b42423 100644 --- a/nikola/plugins/command/version.py +++ b/nikola/plugins/command/version.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 @@ -41,4 +41,4 @@ class CommandVersion(Command): def _execute(self, options={}, args=None): """Print the version number.""" - print("Nikola version " + __version__) + print("Nikola v" + __version__) |
