Permalink
Browse files

converted check into a command, fixed some gallery target details or …

…check
  • Loading branch information...
1 parent fa3b341 commit 78fc19264984d8d9b1af79b9d321c767af7abe9e @ralsina committed Sep 14, 2012
Showing with 40 additions and 18 deletions.
  1. +37 −15 scripts/nikola_check → nikola/plugins/command_check.py
  2. +2 −2 nikola/plugins/task_render_galleries.py
  3. +1 −1 setup.py
@@ -1,13 +1,38 @@
-#!/usr/bin/env python
+from optparse import OptionParser
import os
import sys
import urllib
from urlparse import urlparse
import lxml.html
+from nikola.plugin_categories import Command
+
+
+class CommandCheck(Command):
+ """Check the generated site."""
+
+ name = "check"
+
+ def run(self, *args):
+ """Check the generated site."""
+ parser = OptionParser(usage="nikola %s [options]" % self.name)
+ parser.add_option('-l', '--check-links', dest='links',
+ action='store_true',
+ help='Check for dangling links.')
+ parser.add_option('-f', '--check-files', dest='files',
+ action='store_true',
+ help='Check for unknown files.')
+
+ (options, args) = parser.parse_args(list(args))
+ if options.links:
+ scan_links()
+ if options.files:
+ scan_files()
+
existing_targets = set([])
+
def analize(task):
try:
filename = task.split(":")[-1]
@@ -21,22 +46,27 @@ def analize(task):
continue
if parsed.fragment:
target = target.split('#')[0]
- target_filename = os.path.abspath(os.path.join(os.path.dirname(filename), urllib.unquote(target)))
+ target_filename = os.path.abspath(
+ os.path.join(os.path.dirname(filename),
+ urllib.unquote(target)))
if target_filename not in existing_targets:
if os.path.exists(target_filename):
existing_targets.add(target_filename)
else:
print "In %s broken link: " % filename, target
if '--find-sources' in sys.argv:
print "Possible sources:"
- print os.popen('doit list --deps %s' % task, 'r').read()
+ print os.popen(
+ 'nikola build list --deps %s' % task, 'r').read()
print "===============================\n"
except Exception as exc:
print "Error with:", filename, exc
+
def scan_links():
- for task in os.popen('doit list --all', 'r').readlines():
+ print "Checking Links:\n===============\n"
+ for task in os.popen('nikola build list --all', 'r').readlines():
task = task.strip()
if task.split(':')[0] in (
'render_tags',
@@ -47,11 +77,13 @@ def scan_links():
'render_site') and '.html' in task:
analize(task)
+
def scan_files():
+ print "Checking Files:\n===============\n"
task_fnames = set([])
real_fnames = set([])
# First check that all targets are generated in the right places
- for task in os.popen('doit list --all', 'r').readlines():
+ for task in os.popen('nikola build list --all', 'r').readlines():
task = task.strip()
if 'output' in task and ':' in task:
fname = task.split(':')[-1]
@@ -75,13 +107,3 @@ def scan_files():
print "\nFiles not generated:\n"
for f in only_on_input:
print f
-
-
-if __name__ == '__main__':
- if '--help' in sys.argv or len(sys.argv) == 1:
- print "Usage: nikola_check [--check-links [--find-sources]] [--check-files]"
- sys.exit()
- elif '--check-links' in sys.argv:
- scan_links()
- elif '--check-files' in sys.argv:
- scan_files()
@@ -251,7 +251,7 @@ def add_gallery_path(index):
compile_html = self.site.get_compiler(index_path)
yield {
'basename': 'render_galleries',
- 'name': index_dst_path.encode('utf-8'),
+ 'name': output_name.encode('utf-8'),
'file_dep': [index_path],
'targets': [index_dst_path],
'actions': [(compile_html,
@@ -276,7 +276,7 @@ def render_gallery(output_name, context, index_dst_path):
'basename': 'render_galleries',
'name': gallery_path,
'file_dep': file_dep,
- 'targets': [output_name],
+ 'targets': [gallery_name],
'actions': [(render_gallery,
(output_name, context, index_dst_path))],
'clean': True,
View
@@ -118,7 +118,7 @@ def find_package_data(
author_email='ralsina@netmanagers.com.ar',
url='http://nikola.ralsina.com.ar/',
packages=['nikola'],
- scripts=['scripts/nikola', 'scripts/nikola_check'],
+ scripts=['scripts/nikola'],
install_requires=dependencies,
package_data=find_package_data(),
data_files=[('share/doc/nikola', [

0 comments on commit 78fc192

Please sign in to comment.