summaryrefslogtreecommitdiffstats
path: root/scripts/nikola
blob: 2143e9ef9df4ad8b0583cdfe900281016f32878c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python

"""Nikola main script."""

from __future__ import print_function
import os
import sys

# LIBDIR trick start (marker for removal on platforms that don't need it)
libdir = '@LIBDIR@'

# Two cases:
if libdir != '@' 'LIBDIR' '@':
    # Changed by our distutils hook, then use the given path.

    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__), "..")

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 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__":

    try:
        sys.path.append('')
        import conf
        config = conf.__dict__
    except ImportError:
        config = {}

    site = nikola.Nikola(**config)

    if len(sys.argv) < 2:
        sys.argv.append('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("Unknown command: %s" % cmd_name)
        print_help(site)