示例#1
0
def main():
    enable_pretty_logging()
    command = 'help'
    if len(sys.argv) > 1:
        command = sys.argv[1]

    if command in documentation:
        args = docopt(documentation[command])
    else:
        args = docopt(
            documentation['help'],
            version='Felix Felicis v%s' % liquidluck.__version__
        )

    if command == 'create':
        creator.create(args['--settings'] or 'settings.py')
    elif command == 'build':
        arg_settings = args['--settings'] or 'settings.py'
        if not os.path.exists(arg_settings):
            answer = raw_input(
                "Can't find your setting files, "
                "would you like to create one?(Y/n) "
            )
            if answer.lower() == 'n':
                return
            creator.create(arg_settings)
        else:
            g.detail_logging = args['--verbose']
            generator.build(arg_settings)
    elif command == 'server':
        arg_settings = args['--settings'] or 'settings.py'
        arg_port = int(args['--port'] or 8000)
        if not os.path.exists(arg_settings):
            print('setting file not found')
            server.config(arg_port)
            server.start_server()
        else:
            generator.load_settings(arg_settings)
        if settings.permalink.endswith('.html'):
            permalink = 'html'
        elif settings.permalink.endswith('/'):
            permalink = 'slash'
        else:
            permalink = 'clean'
        server.config(arg_port, g.output_directory, permalink)
        server.start_server()
    elif command == 'search':
        arg_theme = args['<theme>'] or None
        arg_clean = args['--clean']
        arg_force = args['--force']
        theme.search(arg_theme, arg_clean, arg_force)
    elif command == 'install':
        arg_theme = args['<theme>'] or None
        theme.install(arg_theme)
    elif command == 'webhook':
        arg_settings = args['--settings'] or 'settings.py'
        arg_port = int(args['--port'] or 9000)
        action = (args['start'] and 'start') or (args['stop'] and 'stop') \
                or (args['restart'] and 'restart')
        webhook.webhook(arg_port, action, arg_settings)
示例#2
0
def run_parser(args):
    if args.subparser == 'version':
        import liquidluck
        print("Felix Felicis Version: %s" % liquidluck.__version__)
        return

    if args.subparser == 'document':
        import webbrowser
        webbrowser.open('http://liquidluck.readthedocs.org')
        return

    if args.subparser == 'search':
        theme.search(args.theme, args.clean)
        return

    if args.subparser == 'install':
        theme.install(args.theme)
        return

    if args.subparser == 'webhook':
        webhook.webhook(args.port, args.daemon, args.settings)
        return

    if args.subparser == 'server':
        if not os.path.exists(args.settings):
            print('setting file not found')
            g.output_directory = os.path.abspath('.')
        else:
            generator.load_settings(args.settings)
        if settings.permalink.endswith('.html'):
            permalink = 'html'
        elif settings.permalink.endswith('/'):
            permalink = 'slash'
        else:
            permalink = 'clean'
        server.config(args.port, g.output_directory, permalink)
        server.start_server()
        return

    if args.subparser == 'create':
        creator.create(args.settings)
        return

    if not os.path.exists(args.settings):
        answer = raw_input(
            "Can't find your setting files, "
            "would you like to create one?(Y/n) "
        )
        if answer.lower() == 'n':
            return
        creator.create(args.settings)
        return

    g.detail_logging = args.verbose
    enable_pretty_logging()
    generator.build(args.settings)
示例#3
0
def main():
    command = "help"
    if len(sys.argv) > 1:
        command = sys.argv[1]

    if command in documentation:
        args = docopt(documentation[command])
    else:
        args = docopt(documentation["help"], version="Felix Felicis v%s" % liquidluck.__version__)

    if command == "create":
        creator.create(args["--settings"] or "settings.py")
    elif command == "build":
        arg_settings = args["--settings"] or "settings.py"
        if not os.path.exists(arg_settings):
            answer = raw_input("Can't find your setting files, " "would you like to create one?(Y/n) ")
            if answer.lower() == "n":
                return
            creator.create(arg_settings)
        else:
            g.detail_logging = args["--verbose"]
            enable_pretty_logging()
            generator.build(arg_settings)
    elif command == "server":
        arg_settings = args["--settings"] or "settings.py"
        arg_port = int(args["--port"] or 8000)
        if not os.path.exists(arg_settings):
            print("setting file not found")
            g.output_directory = os.path.abspath(".")
        else:
            generator.load_settings(arg_settings)
        if settings.permalink.endswith(".html"):
            permalink = "html"
        elif settings.permalink.endswith("/"):
            permalink = "slash"
        else:
            permalink = "clean"
        server.config(arg_port, g.output_directory, permalink)
        server.start_server()
    elif command == "search":
        arg_theme = args["<theme>"] or None
        arg_clean = args["--clean"]
        theme.search(arg_theme, arg_clean)
    elif command == "install":
        arg_theme = args["<theme>"] or None
        theme.install(arg_theme)
    elif command == "webhook":
        arg_settings = args["--settings"] or "settings.py"
        arg_port = int(args["--port"] or 9000)
        action = (args["start"] and "start") or (args["stop"] and "stop") or (args["restart"] and "restart")
        webhook.webhook(arg_port, action, arg_settings)