Example #1
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__)

    arg_settings = args.get('--settings') or generator.find_settings()
    arg_verbose = args.get('--verbose')
    if arg_verbose:
        enable_pretty_logging('debug')
    else:
        enable_pretty_logging('info')
    arg_port = args.get('--port') or '8000'

    arg_theme = args.get('<theme>') or None
    arg_clean = args.get('--clean')
    arg_force = args.get('--force')
    arg_global = args.get('--global')

    if command == 'init':
        generator.create_settings(arg_settings)
    elif command == 'build':
        if not arg_settings:
            answer = raw_input("Can't find your setting files, "
                               "would you like to create one?(Y/n) ")
            if answer.lower() == 'n':
                return
            generator.create_settings(arg_settings)
        else:
            generator.build(arg_settings)
    elif command == 'server':
        if arg_settings and os.path.exists(arg_settings):
            generator.load_settings(arg_settings)
        else:
            print('setting file not found')
            server.config(arg_port)
            server.start_server()

        permalink = settings.config.get('permalink')
        if permalink.endswith('.html'):
            _type = 'html'
        elif permalink.endswith('/'):
            _type = 'slash'
        else:
            _type = 'clean'
        server.config(arg_port, g.output_directory, _type)
        server.start_server()
    elif command == 'search':
        theme.search(arg_theme, arg_clean, arg_force)
    elif command == 'install':
        theme.install(arg_theme, arg_global)
    elif command == 'webhook':
        action = (args['start'] and 'start') or (args['stop'] and 'stop') \
                or (args['restart'] and 'restart')
        webhook.webhook(arg_port, action, arg_settings)
Example #2
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)
Example #3
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)
Example #4
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)
Example #5
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__
        )

    arg_settings = args.get('--settings') or generator.find_settings()
    arg_verbose = args.get('--verbose')
    if arg_verbose:
        enable_pretty_logging('debug')
    else:
        enable_pretty_logging('info')
    arg_port = args.get('--port') or '8000'

    arg_theme = args.get('<theme>') or None
    arg_clean = args.get('--clean')
    arg_force = args.get('--force')
    arg_global = args.get('--global')

    if command == 'init':
        generator.create_settings(arg_settings)
    elif command == 'build':
        if not arg_settings:
            answer = raw_input(
                "Can't find your setting files, "
                "would you like to create one?(Y/n) "
            )
            if answer.lower() == 'n':
                return
            generator.create_settings(arg_settings)
        else:
            generator.build(arg_settings)
    elif command == 'server':
        arg_debug = args.get('--debug')
        if arg_debug:
            print('debug mode on')
        if arg_settings and os.path.exists(arg_settings):
            generator.load_settings(arg_settings)
        else:
            print('setting file not found')
            server.config(arg_port)
            server.start_server(arg_debug)

        permalink = settings.config.get('permalink')
        if permalink.endswith('.html'):
            _type = 'html'
        elif permalink.endswith('/'):
            _type = 'slash'
        else:
            _type = 'clean'
        server.config(arg_port, g.output_directory, _type)
        server.start_server(arg_debug)
    elif command == 'search':
        theme.search(arg_theme, arg_clean, arg_force)
    elif command == 'install':
        theme.install(arg_theme, arg_global)
    elif command == 'webhook':
        action = (args['start'] and 'start') or (args['stop'] and 'stop') \
                or (args['restart'] and 'restart')
        webhook.webhook(arg_port, action, arg_settings)