From 0f2c04e70a0ffdd0892d6970cafbcd952d221db5 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Wed, 12 Dec 2012 20:15:48 -0300 Subject: Imported Upstream version 5 --- scripts/nikola | 74 +++++++++++++++++++++++++---------- scripts/nikola_check | 87 ----------------------------------------- scripts/nikola_import_wordpress | 8 ---- 3 files changed, 54 insertions(+), 115 deletions(-) delete mode 100644 scripts/nikola_check delete mode 100644 scripts/nikola_import_wordpress (limited to 'scripts') diff --git a/scripts/nikola b/scripts/nikola index 4b895d2..a20ac43 100755 --- a/scripts/nikola +++ b/scripts/nikola @@ -2,34 +2,68 @@ """Nikola main script.""" +from __future__ import print_function import os -import shutil import sys -import nikola +# LIBDIR trick start (marker for removal on platforms that don't need it) +libdir = '@LIBDIR@' -USAGE = """To create a new site in a folder, run "nikola init foldername [src]". +# Two cases: +if libdir != '@' 'LIBDIR' '@': + # Changed by our distutils hook, then use the given path. -The destination folder must not exist. + if not os.path.isabs(libdir): + libdir = os.path.join(os.path.dirname( + os.path.realpath(__file__)), libdir) + libdir = os.path.abspath(libdir) +else: + # Unchanged, running from checkout, + # use the parent directory, the nikola package ought be there. + libdir = os.path.join(os.path.dirname(__file__), "..") -If you pass the src argument, that folder will be used as a template for -the new site instead of Nikola's sample site. -""" +sys.path.insert(0, libdir) +if "PYTHONPATH" not in os.environ: + os.environ["PYTHONPATH"] = libdir +else: + os.environ["PYTHONPATH"] = os.environ["PYTHONPATH"] + ":" + libdir + +# LIBDIR trick end (marker for removal on platforms that don't need it) + +import nikola -def init(dst): - """Create a copy of demosite in the current folder.""" - if len(sys.argv) > 3: - src = sys.argv[3] - else: - src = os.path.join(os.path.dirname(nikola.__file__),'data','samplesite') - shutil.copytree(src, dst) - print "A new site with some sample data has been created at %s." % dst - print "See README.txt in that folder for more information." + +def print_help(site): + print("Usage: nikola command [options]") + print() + print("Available commands:") + print() + keys = sorted(site.commands.keys()) + for name in keys: + print("nikola %s: %s" % (name, site.commands[name].short_help)) + print() + print("For detailed help for a command, use nikola command --help") if __name__ == "__main__": - if len(sys.argv)>=3 and sys.argv[1] == "init": - print "Doing init" - init(sys.argv[2]) + + try: + sys.path.append('') + import conf + config = conf.__dict__ + except ImportError: + config = {} + + site = nikola.Nikola(**config) + + if len(sys.argv) < 2: + sys.argv[1:] = 'help' + cmd_name = sys.argv[1] + + if cmd_name in ("help", "--help", "-h"): + print_help(site) + elif cmd_name in site.commands: + site.commands[cmd_name].run(*sys.argv[2:]) else: - print USAGE + print("Unknown command: %s" % cmd_name) + print_help(site) diff --git a/scripts/nikola_check b/scripts/nikola_check deleted file mode 100644 index 797c29b..0000000 --- a/scripts/nikola_check +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python -import os -import sys -import urllib -from urlparse import urlparse - -import lxml.html - -existing_targets = set([]) - -def analize(task): - try: - filename = task.split(":")[-1] - d = lxml.html.fromstring(open(filename).read()) - for l in d.iterlinks(): - target = l[0].attrib[l[1]] - if target == "#": - continue - parsed = urlparse(target) - if parsed.scheme: - continue - if parsed.fragment: - target = target.split('#')[0] - 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 "===============================\n" - - except Exception as exc: - print "Error with:", filename, exc - -def scan_links(): - for task in os.popen('doit list --all', 'r').readlines(): - task = task.strip() - if task.split(':')[0] in ( - 'render_tags', - 'render_archive', - 'render_galleries', - 'render_indexes', - 'render_pages', - 'render_site') and '.html' in task: - analize(task) - -def scan_files(): - 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(): - task = task.strip() - if 'output' in task and ':' in task: - fname = task.split(':')[-1] - task_fnames.add(fname) - # And now check that there are no non-target files - for root, dirs, files in os.walk('output'): - for src_name in files: - fname = os.path.join(root, src_name) - real_fnames.add(fname) - - only_on_output = list(real_fnames - task_fnames) - if only_on_output: - only_on_output.sort() - print "\nFiles from unknown origins:\n" - for f in only_on_output: - print f - - only_on_input = list(task_fnames - real_fnames) - if only_on_input: - only_on_input.sort() - 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() diff --git a/scripts/nikola_import_wordpress b/scripts/nikola_import_wordpress deleted file mode 100644 index 015d6a0..0000000 --- a/scripts/nikola_import_wordpress +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env python - -import sys -from nikola import wordpress - -if __name__ == "__main__": - fname = sys.argv[-1] - wordpress.process(fname) -- cgit v1.2.3