示例#1
0
文件: engine.py 项目: luckypoem/wok
    def __init__(self, output_lvl=1):
        """
        Set up CLI options, logging levels, and start everything off.
        Afterwards, run a dev server if asked to.
        """

        # CLI options
        # -----------
        parser = OptionParser(version='%prog v{0}'.format(wok.version))

        # Add option to to run the development server after generating pages
        devserver_grp = OptionGroup(
            parser, "Development server",
            "Runs a small development server after site generation. "
            "--address and --port will be ignored if --server is absent.")
        devserver_grp.add_option(
            '--server',
            action='store_true',
            dest='runserver',
            help="run a development server after generating the site")
        devserver_grp.add_option(
            '--address',
            action='store',
            dest='address',
            help="specify ADDRESS on which to run development server")
        devserver_grp.add_option(
            '--port',
            action='store',
            dest='port',
            type='int',
            help="specify PORT on which to run development server")
        parser.add_option_group(devserver_grp)

        # Options for noisiness level and logging
        logging_grp = OptionGroup(
            parser, "Logging",
            "By default, log messages will be sent to standard out, "
            "and report only errors and warnings.")
        parser.set_defaults(loglevel=logging.WARNING)
        logging_grp.add_option('-q',
                               '--quiet',
                               action='store_const',
                               const=logging.ERROR,
                               dest='loglevel',
                               help="be completely quiet, log nothing")
        logging_grp.add_option('--warnings',
                               action='store_const',
                               const=logging.WARNING,
                               dest='loglevel',
                               help="log warnings in addition to errors")
        logging_grp.add_option('-v',
                               '--verbose',
                               action='store_const',
                               const=logging.INFO,
                               dest='loglevel',
                               help="log ALL the things!")
        logging_grp.add_option(
            '--debug',
            action='store_const',
            const=logging.DEBUG,
            dest='loglevel',
            help="log debugging info in addition to warnings and errors")
        logging_grp.add_option(
            '--log',
            '-l',
            dest='logfile',
            help="log to the specified LOGFILE instead of standard out")
        parser.add_option_group(logging_grp)

        cli_options, args = parser.parse_args()

        # Set up logging
        # --------------
        logging_options = {
            'format': '%(levelname)s: %(message)s',
            'level': cli_options.loglevel,
        }
        if cli_options.logfile:
            logging_options['filename'] = cli_options.logfile
        else:
            logging_options['stream'] = sys.stdout

        logging.basicConfig(**logging_options)

        # Action!
        # -------
        self.generate_site()

        # Dev server
        # ----------
        if cli_options.runserver:
            ''' Run the dev server if the user said to, and watch the specified
            directories for changes. The server will regenerate the entire wok
            site if changes are found after every request.
            '''
            output_dir = os.path.join(self.options['output_dir'])
            host = '' if cli_options.address is None else cli_options.address
            port = 8000 if cli_options.port is None else cli_options.port
            server = dev_server(serv_dir=output_dir,
                                host=host,
                                port=port,
                                dir_mon=True,
                                watch_dirs=[
                                    self.options['media_dir'],
                                    self.options['template_dir'],
                                    self.options['content_dir']
                                ],
                                change_handler=self.generate_site)
            server.run()
示例#2
0
文件: engine.py 项目: jneves/wok
    def __init__(self, output_lvl=1):
        """
        Set up CLI options, logging levels, and start everything off.
        Afterwards, run a dev server if asked to.
        """

        # CLI options
        # -----------
        parser = OptionParser(version='%prog v{0}'.format(wok.version))

        # Add option to initialize an new project
        init_grp = OptionGroup(parser, "Initialize project",
                "Creates a config file and the required directories. ")
        init_grp.add_option('--init', action='store_true',
                dest='initproject',
                help="create a confg file before generating the site")
        init_grp.add_option('--site_title',
                dest='site_title',
                help="configures the site title to the given value")
        parser.add_option_group(init_grp)

        # Add option to to run the development server after generating pages
        devserver_grp = OptionGroup(parser, "Development server",
                "Runs a small development server after site generation. "
                "--address and --port will be ignored if --server is absent.")
        devserver_grp.add_option('--server', action='store_true',
                dest='runserver',
                help="run a development server after generating the site")
        devserver_grp.add_option('--address', action='store', dest='address',
                help="specify ADDRESS on which to run development server")
        devserver_grp.add_option('--port', action='store', dest='port',
                type='int',
                help="specify PORT on which to run development server")
        parser.add_option_group(devserver_grp)

        # Options for noisiness level and logging
        logging_grp = OptionGroup(parser, "Logging",
                "By default, log messages will be sent to standard out, "
                "and report only errors and warnings.")
        parser.set_defaults(loglevel=logging.WARNING)
        logging_grp.add_option('-q', '--quiet', action='store_const',
                const=logging.ERROR, dest='loglevel',
                help="be completely quiet, log nothing")
        logging_grp.add_option('--warnings', action='store_const',
                const=logging.WARNING, dest='loglevel',
                help="log warnings in addition to errors")
        logging_grp.add_option('-v', '--verbose', action='store_const',
                const=logging.INFO, dest='loglevel',
                help="log ALL the things!")
        logging_grp.add_option('--debug', action='store_const',
                const=logging.DEBUG, dest='loglevel',
                help="log debugging info in addition to warnings and errors")
        logging_grp.add_option('--log', '-l', dest='logfile',
                help="log to the specified LOGFILE instead of standard out")
        parser.add_option_group(logging_grp)

        cli_options, args = parser.parse_args()

        # Set up logging
        # --------------
        logging_options = {
            'format': '%(levelname)s: %(message)s',
            'level': cli_options.loglevel,
        }
        if cli_options.logfile:
            logging_options['filename'] = cli_options.logfile
        else:
            logging_options['stream'] = sys.stdout

        logging.basicConfig(**logging_options)

        # Init project
        # ------------

        if cli_options.initproject:
            ''' Create the config file and the required directories if the user said to.
            '''
            orig_dir = os.getcwd()
            os.chdir(self.SITE_ROOT)

            # create config

            options = Engine.default_options.copy()

            # read old config if present
            if os.path.isfile('config'):
                with open('config') as f:
                    yaml_config = yaml.load(f)

                if yaml_config:
                    options.update(yaml_config)

            if cli_options.site_title:
                options['site_title'] = cli_options.site_title

            # save new config
            with open('config', 'w') as f:
                    yaml.dump(options, f)

            # create required dirs

            required_dirs = [options['content_dir'], options['template_dir']]
            for required_dir in required_dirs:
                if not os.path.isdir(required_dir):
                    os.mkdir(required_dir)

            os.chdir(orig_dir)

        # Action!
        # -------
        self.generate_site()

        # Dev server
        # ----------
        if cli_options.runserver:
            ''' Run the dev server if the user said to, and watch the specified
            directories for changes. The server will regenerate the entire wok
            site if changes are found after every request.
            '''
            output_dir = os.path.join(self.options['server_root'])
            host = '' if cli_options.address is None else cli_options.address
            port = 8000 if cli_options.port is None else cli_options.port
            server = dev_server(serv_dir=output_dir, host=host, port=port,
                dir_mon=True,
                watch_dirs=[
                    self.options['media_dir'],
                    self.options['template_dir'],
                    self.options['content_dir']
                ],
                change_handler=self.generate_site)
            server.run()
示例#3
0
文件: engine.py 项目: ngokevin/wok
    def __init__(self, output_lvl=1):
        """
        Set up CLI options, logging levels, and start everything off.
        Afterwards, run a dev server if asked to.
        """

        # CLI options
        # -----------
        parser = OptionParser(version='%prog v{0}'.format(wok.version))

        # Add option to to run the development server after generating pages
        devserver_grp = OptionGroup(parser, "Development server",
                "Runs a small development server after site generation. "
                "--address and --port will be ignored if --server is absent.")
        devserver_grp.add_option('--server', action='store_true',
                dest='runserver',
                help="run a development server after generating the site")
        devserver_grp.add_option('--address', action='store', dest='address',
                help="specify ADDRESS on which to run development server")
        devserver_grp.add_option('--port', action='store', dest='port',
                type='int',
                help="specify PORT on which to run development server")
        parser.add_option_group(devserver_grp)

        # Options for noisiness level and logging
        logging_grp = OptionGroup(parser, "Logging",
                "By default, log messages will be sent to standard out, "
                "and report only errors and warnings.")
        parser.set_defaults(loglevel=logging.WARNING)
        logging_grp.add_option('-q', '--quiet', action='store_const',
                const=logging.ERROR, dest='loglevel',
                help="be completely quiet, log nothing")
        logging_grp.add_option('--warnings', action='store_const',
                const=logging.WARNING, dest='loglevel',
                help="log warnings in addition to errors")
        logging_grp.add_option('-v', '--verbose', action='store_const',
                const=logging.INFO, dest='loglevel',
                help="log ALL the things!")
        logging_grp.add_option('--debug', action='store_const',
                const=logging.DEBUG, dest='loglevel',
                help="log debugging info in addition to warnings and errors")
        logging_grp.add_option('--log', '-l', dest='logfile',
                help="log to the specified LOGFILE instead of standard out")
        parser.add_option_group(logging_grp)

        cli_options, args = parser.parse_args()

        # Set up logging
        # --------------
        logging_options = {
            'format': '%(levelname)s: %(message)s',
            'level': cli_options.loglevel,
        }
        if cli_options.logfile:
            logging_options['filename'] = cli_options.logfile
        else:
            logging_options['stream'] = sys.stdout

        logging.basicConfig(**logging_options)

        # Action!
        # -------
        self.generate_site()

        # Dev server
        # ----------
        if cli_options.runserver:
            ''' Run the dev server if the user said to, and watch the specified
            directories for changes. The server will regenerate the entire wok
            site if changes are found after every request.
            '''
            output_dir = os.path.join(self.options['output_dir'])
            host = '' if cli_options.address is None else cli_options.address
            port = 8000 if cli_options.port is None else cli_options.port
            server = dev_server(serv_dir=output_dir, host=host, port=port,
                dir_mon=True,
                watch_dirs=[
                    self.options['media_dir'],
                    self.options['template_dir'],
                    self.options['content_dir']
                ],
                change_handler=self.generate_site)
            server.run()
示例#4
0
文件: engine.py 项目: moreati/wok
    def __init__(self, output_lvl=1):
        """
        Set up CLI options, logging levels, and start everything off.
        Afterwards, run a dev server if asked to.
        """

        # CLI options
        # -----------
        parser = OptionParser(version='%prog v{0}'.format(wok.version))

        # Add option to initialize an new project
        init_grp = OptionGroup(
            parser, "Initialize project",
            "Creates a config file and the required directories. ")
        init_grp.add_option(
            '--init',
            action='store_true',
            dest='initproject',
            help="create a confg file before generating the site")
        init_grp.add_option(
            '--site_title',
            dest='site_title',
            help="configures the site title to the given value")
        parser.add_option_group(init_grp)

        # Add option to to run the development server after generating pages
        devserver_grp = OptionGroup(
            parser, "Development server",
            "Runs a small development server after site generation. "
            "--address and --port will be ignored if --server is absent.")
        devserver_grp.add_option(
            '--server',
            action='store_true',
            dest='runserver',
            help="run a development server after generating the site")
        devserver_grp.add_option(
            '--address',
            action='store',
            dest='address',
            help="specify ADDRESS on which to run development server")
        devserver_grp.add_option(
            '--port',
            action='store',
            dest='port',
            type='int',
            help="specify PORT on which to run development server")
        parser.add_option_group(devserver_grp)

        # Options for noisiness level and logging
        logging_grp = OptionGroup(
            parser, "Logging",
            "By default, log messages will be sent to standard out, "
            "and report only errors and warnings.")
        parser.set_defaults(loglevel=logging.WARNING)
        logging_grp.add_option('-q',
                               '--quiet',
                               action='store_const',
                               const=logging.ERROR,
                               dest='loglevel',
                               help="be completely quiet, log nothing")
        logging_grp.add_option('--warnings',
                               action='store_const',
                               const=logging.WARNING,
                               dest='loglevel',
                               help="log warnings in addition to errors")
        logging_grp.add_option('-v',
                               '--verbose',
                               action='store_const',
                               const=logging.INFO,
                               dest='loglevel',
                               help="log ALL the things!")
        logging_grp.add_option(
            '--debug',
            action='store_const',
            const=logging.DEBUG,
            dest='loglevel',
            help="log debugging info in addition to warnings and errors")
        logging_grp.add_option(
            '--log',
            '-l',
            dest='logfile',
            help="log to the specified LOGFILE instead of standard out")
        parser.add_option_group(logging_grp)

        cli_options, args = parser.parse_args()

        # Set up logging
        # --------------
        logging_options = {
            'format': '%(levelname)s: %(message)s',
            'level': cli_options.loglevel,
        }
        if cli_options.logfile:
            logging_options['filename'] = cli_options.logfile
        else:
            logging_options['stream'] = sys.stdout

        logging.basicConfig(**logging_options)

        # Init project
        # ------------

        if cli_options.initproject:
            ''' Create the config file and the required directories if the user said to.
            '''
            orig_dir = os.getcwd()
            os.chdir(self.SITE_ROOT)

            # create config

            options = Engine.default_options.copy()

            # read old config if present
            if os.path.isfile('config'):
                with open('config') as f:
                    yaml_config = yaml.load(f)

                if yaml_config:
                    options.update(yaml_config)

            if cli_options.site_title:
                options['site_title'] = cli_options.site_title

            # save new config
            with open('config', 'w') as f:
                yaml.dump(options, f)

            # create required dirs

            required_dirs = [options['content_dir'], options['template_dir']]
            for required_dir in required_dirs:
                if not os.path.isdir(required_dir):
                    os.mkdir(required_dir)

            os.chdir(orig_dir)

        # Action!
        # -------
        self.generate_site()

        # Dev server
        # ----------
        if cli_options.runserver:
            ''' Run the dev server if the user said to, and watch the specified
            directories for changes. The server will regenerate the entire wok
            site if changes are found after every request.
            '''
            output_dir = os.path.join(self.options['server_root'])
            host = '' if cli_options.address is None else cli_options.address
            port = 8000 if cli_options.port is None else cli_options.port
            server = dev_server(serv_dir=output_dir,
                                host=host,
                                port=port,
                                dir_mon=True,
                                watch_dirs=[
                                    self.options['media_dir'],
                                    self.options['template_dir'],
                                    self.options['content_dir']
                                ],
                                change_handler=self.generate_site)
            server.run()