aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2012-12-12 20:15:48 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2012-12-12 20:15:48 -0300
commit0f2c04e70a0ffdd0892d6970cafbcd952d221db5 (patch)
treed36f7747c4b9cb5c5e00cae5b137d22214b1c7be /scripts
parentca1f5a392261a7c6b82b5ac1015427605909d8c9 (diff)
Imported Upstream version 5upstream/5
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/nikola74
-rw-r--r--scripts/nikola_check87
-rw-r--r--scripts/nikola_import_wordpress8
3 files changed, 54 insertions, 115 deletions
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)