diff options
| author | 2012-12-12 20:15:48 -0300 | |
|---|---|---|
| committer | 2012-12-12 20:15:48 -0300 | |
| commit | 0f2c04e70a0ffdd0892d6970cafbcd952d221db5 (patch) | |
| tree | d36f7747c4b9cb5c5e00cae5b137d22214b1c7be /scripts/nikola | |
| parent | ca1f5a392261a7c6b82b5ac1015427605909d8c9 (diff) | |
Imported Upstream version 5upstream/5
Diffstat (limited to 'scripts/nikola')
| -rwxr-xr-x | scripts/nikola | 74 |
1 files changed, 54 insertions, 20 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) |
