def build(config_file=None, site_dir=None, num_threads=None, no_livereload=False, content=None, dump=False, clean=False, serve=False, host=None, port=None, template=None, **template_args): """ The main build command. """ if serve: clean = True site_dir = os.path.abspath(os.path.join(MooseDocs.TEMP_DIR, 'site')) # Clean/create site directory if clean and os.path.exists(site_dir): LOG.info('Cleaning build directory: %s', site_dir) shutil.rmtree(site_dir) # Create the "temp" directory if not os.path.exists(site_dir): os.makedirs(site_dir) # Create the markdown parser config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) # Create the builder object and build the pages builder = WebsiteBuilder(parser=parser, site_dir=site_dir, content=content) builder.init() if dump: print builder return None builder.build(num_threads=num_threads) # Serve if serve: if not no_livereload: server = livereload.Server( watcher=MooseDocsWatcher(builder, num_threads)) else: server = livereload.Server() server.serve(root=site_dir, host=host, port=port, restart_delay=0) return 0
def run_server(mode: Optional[str]='debug') -> None: """ Runs the server in either debug or prod mode :param mode: mode to run in :return: None """ if mode == 'debug': # DEBUG (livereload) MODE configure('testing') app.jinja_env.auto_reload = True app.debug = True server = livereload.Server(app.wsgi_app) server.watch('.', ignore=lambda x: ('log' in x or '.idea' in x)) server.serve( port=PORT, host=HOST ) elif mode == 'prod': # Pseduo Prod Mode pid = os.fork() if pid == 0: while True: try: time.sleep(1) except KeyboardInterrupt: os.kill(pid, signal.SIGINT) break else: os.system(f'gunicorn -b :{PORT} application:app')
def serve(config_file='moosedocs.yml', host='127.0.0.1', port='8000', num_threads=multiprocessing.cpu_count()): """ Create live server """ # Location of serve site tempdir = os.path.abspath( os.path.join(os.getenv('HOME'), '.local', 'share', 'moose', 'site')) # Clean the "temp" directory (if desired) if os.path.exists(tempdir): log.info('Cleaning build directory: {}'.format(tempdir)) shutil.rmtree(tempdir) # Create the "temp" directory if not os.path.exists(tempdir): os.makedirs(tempdir) # Perform the initial build log.info("Building documentation...") # Wrapper for building complete website def build_complete(): return build.build_site(config_file=config_file, site_dir=tempdir, num_threads=num_threads) config, parser, builder = build_complete() # Start the live server server = livereload.Server() # Watch markdown files for page in builder: server.watch(page.source(), page.build) # Watch support directories server.watch(os.path.join(os.getcwd(), 'media'), builder.copyFiles) server.watch(os.path.join(os.getcwd(), 'css'), builder.copyFiles) server.watch(os.path.join(os.getcwd(), 'js'), builder.copyFiles) server.watch(os.path.join(os.getcwd(), 'fonts'), builder.copyFiles) # Watch the files and directories that require complete rebuild moose_extension = MooseDocs.get_moose_markdown_extension(parser) if moose_extension: server.watch( os.path.join(os.getcwd(), moose_extension.getConfig('executable')), build_complete) server.watch(config['navigation'], build_complete) server.watch(config_file, build_complete) server.watch('templates') # Start the server server.serve(root=config['site_dir'], host=host, port=port, restart_delay=0)
def main(): logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s", datefmt="%Y-%m-%d %H:%M") parser = argparse.ArgumentParser( prog="build_docs", formatter_class=argparse.RawDescriptionHelpFormatter, usage=USAGE) parser.add_argument( '--preview', action='store_true', help="""starts a local server with live reload (updates triggered upon changes in the documentation files). this feature is intended to preview the documentation locally.""") args = parser.parse_args() # Initial processing of all files process_all_files() if args.preview: # Setup livereload watcher server = livereload.Server() exts_to_watch = MARKDOWN_EXTENSIONS + \ STATIC_ASSET_EXTENSIONS + \ HJSON_EXTENSIONS for src_pathname in get_doc_files(exts_to_watch): server.watch(str(src_pathname), process_all_files) server.serve(root=config['topdir'].joinpath(config['outdir']))
def main(options): """ Main function for the build command. Inputs: options[argparse options]: Complete options from argparse, see MooseDocs/main.py """ # Make sure "large_media" exists in MOOSE _init_large_media() # Create translator translator = common.load_config(options.config) translator.init(options.destination) # Dump page tree if options.dump: print translator.root # Clean if options.clean: shutil.rmtree(options.destination) # Perform build if options.files: for filename in options.files: node = translator.root.findall(filename)[0] node.build() else: translator.execute(options.num_threads) if options.serve: watcher = MooseDocsWatcher(translator, options) server = livereload.Server(watcher=watcher) server.serve(root=options.destination, port=options.port)
def presentation(config_file=None, md_file=None, serve=None, port=None, host=None, template=None, **template_args): """ MOOSE markdown presentation blaster. """ # The markdown file is provided via the command line, thus it is provided relative to the # current working directory. The internals of MooseDocs are setup to always work from the # repository root directory (i.e., MooseDocs.ROOT_DIR), thus the path of this file must be # converted to be relative to MooseDocs.ROOT_DIR. md_file = os.path.relpath(os.path.abspath(md_file), MooseDocs.ROOT_DIR) # Create the markdown parser config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseMarkdown(config) # Build the html builder = PresentationBuilder(md_file=md_file, parser=parser) builder.init() builder.build(num_threads=1) if serve: server = livereload.Server() server.watch(os.path.join(MooseDocs.ROOT_DIR, md_file), lambda: builder.build(num_threads=1)) server.serve(root=builder.rootDirectory(), host=host, port=port, restart_delay=0) return 0
def main(common_styles): server = livereload.Server() paths_to_watch = [ "./**/*.tt", "./*.tt", "./*.xml", "./Makefile", "./css/*", "./demos/*.scenario", "./images/*", "./js/*", "./scripts/*", "./site-styles/*", "./site-styles/**/*", "./site-styles/**/**/*", ] if common_styles is not None: paths_to_watch.append(common_styles) for path in paths_to_watch: server.watch(path, lambda: os.system("make")) os.system("make") server.serve(root="./", port=os.getenv("PORT", 8000))
def run(self, **kwargs): """Bring the server online, with live reload.""" server = livereload.Server(self.app) server.watch(self.path) self.host = kwargs.get('host', 'localhost') self.port = kwargs.get('port', 8080) server.serve(**kwargs)
def presentation(config_file=None, md_file=None, serve=None, port=None, host=None, template=None, **template_args): """ MOOSE markdown presentation blaster. """ # Load the YAML configuration file config = MooseDocs.load_config(config_file, template=template, template_args=template_args) parser = MooseDocs.MooseMarkdown(extensions=config.keys(), extension_configs=config) site_dir, _ = os.path.splitext(md_file) if not os.path.isdir(site_dir): os.mkdir(site_dir) root = PresentationBuilder(name='', markdown=md_file, parser=parser, site_dir=site_dir) root.build() if serve: server = livereload.Server() server.watch(md_file, root.build) server.serve(root=site_dir, host=host, port=port, restart_delay=0) return None
def __init__(self, builder: Builder, port: int): assert builder.name == "html" self.host = "127.0.0.1" self.port = port self.server = livereload.Server() self.server.root = builder.fs.root self.server.default_filename = "index.html" self.loop: Optional[IOLoop] = None
def watch(ctx): server = livereload.Server(watcher=GlobWatcher()) server.watch(path('./assets/img/'), lambda: collectstatic(ctx)) server.watch(assets('js/**'), lambda: collectstatic(ctx)) server.watch(assets('sass/**'), lambda: [styles(ctx), collectstatic(ctx)]) #server.watch(assets('map/**'), lambda: [vue(ctx, 'map', True), collectstatic(ctx)]) server.watch(path('./dist/lib/'), lambda: collectstatic(ctx)) server.serve()
def watch(): raml() server = livereload.Server() server.watch('_data/**/*', convert_templates) server.watch('templates/**/*', convert_templates) server.watch('apis/*', build_api_docs) server.watch('examples/*.json', convert_templates) server.serve()
def liveserver(debug=True): """ Runs a live reloading server which watches non-python code as well. """ import livereload app.debug = debug server = livereload.Server(app.wsgi_app) server.watch('app/') server.serve()
def _run(self, build_func, root, port, host): watcher = _RecursiveGlobWatcher if sys.version_info >= (3, 5) else None server = livereload.Server(watcher=watcher) for pattern in self._spy_on: server.watch(pattern, build_func) build_func() # Do an initial build. server.serve(root=root, port=port, open_url_delay=2, restart_delay=0.3, host=host)
def runserver(reload): """Shortcut to ``flask run``""" if reload: import livereload server = livereload.Server(app.wsgi_app) server.watch(".", ignore=lambda x: ("log" in x)) server.serve(port=os.environ.get("PORT", "9999"), host=os.environ.get("HOST", "localhost")) return app.run()
def live(port=8000): """Using livereload, run a local server that updates the browser""" build() server = livereload.Server() def live_build_ignore(s): return False server.watch('content/', build, ignore=live_build_ignore) server.watch('hyde/', build, ignore=live_build_ignore) server.serve(root=DEPLOY_PATH, liveport=35729, port=port)
def live_build(port=8080): local('make clean') # 1 local('make html') # 2 os.chdir('output') # 3 server = livereload.Server() # 4 server.watch('../content/*.md', # 5 livereload.shell('pelican -s ../pelicanconf.py -o ../output')) # 6 server.watch('../pelican-octopress-theme/', # 7 livereload.shell('pelican -s ../pelicanconf.py -o ../output')) # 8 server.watch('*.html') # 9 server.watch('*.css') # 10 server.serve(liveport=35729, port=port) # 11
def serve_output_dir(): """ Starts a webserver that serves the output folder. It serves and blocks until SIGINT is sent The webserver is also triggering a browser-refresh when the content of the output folder changes """ server = livereload.Server() server.watch(OUT_DIR) server.serve(root=OUT_DIR, port=WEBSERVER_LISTEN_PORT, host=WEBSERVER_LISTEN_HOST)
def serve_livereload(): local('make clean') local('make html') os.chdir('output') server = livereload.Server() server.watch('../content/*.rst', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('../naffy/', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('*.html') server.watch('*.css') server.serve(liveport=35729, port=PORT)
def start(self, port=8000, host="127.0.0.1", livereload=False): if livereload: live_server = lreload.Server(self.app) live_server.watch(self.baseDir) live_server.serve(port=port, host=host) else: with simple_server.make_server( host, port, self.app, server_class=ThreadingWSGIServer) as httpd: print("Listening on http://{}:{}".format( host, port)) # livereload prints its own httpd.serve_forever()
def serve(rconf_file, port, force): """ Watch input markdown files for change and regenerates target files. """ if not rconf_file.endswith('.rconf'): rconf_file += '.rconf' def _get_from_rel(f): """Returns path given relatively to rconf file.""" return os.path.join(os.path.dirname(rconf_file), f) try: rconf_model = _load_rconf(rconf_file) def do_build(report_files=False): """Callback triggered when file change is detected.""" _internal_build(rconf_file, force, port=port, report_files=report_files) watch_files = set() watch_files.add(rconf_file) # Add template defined on the rconf model level to the # list of watched files. template_file = _get_param(rconf_model, "template") if template_file: watch_files.add(_get_from_rel(template_file)) # Add all input files to the list of watched files together # with rule-level defined template if any. for rule in rconf_model.rules: watch_files.update( _find_files(rule.input_file, parent=rconf_file, strip_parent=False)) watch_files.add(_get_from_rel(_get_param(rule, "template"))) server = livereload.Server() for f in watch_files: server.watch(f, do_build) # Build if necessary do_build(report_files=True) # Start server server.serve(port=port, root=os.path.dirname(rconf_file)) except RComposeException as e: click.echo(e)
def main(options): """ Main function for the build command. Inputs: options[argparse options]: Complete options from argparse, see MooseDocs/main.py """ # Make sure "large_media" exists in MOOSE _init_large_media() # Create translator translator, _ = common.load_config(options.config) if options.destination: translator.update(destination=mooseutils.eval_path(options.destination)) translator.init() # Replace "home" with local server if options.serve: home = 'http://127.0.0.1:{}'.format(options.port) translator.renderer.update(home=home) elif options.home: translator.renderer.update(home=options.home) # Dump page tree if options.dump: print translator.root # Clean when --files is NOT used or when --clean is used with --files. if ((options.files == []) or (options.files != [] and options.clean)) \ and os.path.exists(translator['destination']): log = logging.getLogger('MooseDocs.build') log.info("Cleaning destination %s", translator['destination']) shutil.rmtree(translator['destination']) # Perform check if options.check: check(translator) # Perform build if options.files: for filename in options.files: node = translator.root.findall(filename)[0] node.build() else: translator.execute(options.num_threads) if options.serve: watcher = MooseDocsWatcher(translator, options) server = livereload.Server(watcher=watcher) server.serve(root=translator['destination'], host=options.host, port=options.port)
def _run(self, build_func, source_dir, html_dir, port, host): server = livereload.Server(watcher=get_recursive_watcher()) watch_patterns = self._watch_patterns + [ f'{source_dir}/conf.py', f'{source_dir}/_static/*.css', f'{source_dir}/_templates/*.html', f'{source_dir}/*.rst', f'{source_dir}/**/*.rst', ] for pattern in watch_patterns: server.watch(pattern, build_func) build_func() # Do an initial build. server.serve(root=html_dir, host=host, port=port, restart_delay=0.2)
def run_livereload(self, port=8080): """ Create a live reload server :param additional_files: list of file patterns, relative to the project's root :return: """ self.app.debug = True self.app.jinja_env.globals['livereload'] = True self.app.jinja_env.auto_reload = True self.create_folder_structure() server = livereload.Server(self.app.wsgi_app) for f in self.config['livereload_watch_files']: server.watch(utils.abs_path(f % self.config)) server.serve(port=port, host='0.0.0.0')
def main(): """ Run a hot reloading development server on port 5001 """ app = create_app(config.DevConfig) def sass(): return compile_css(app) sass() # Run dev server server = lr.Server(app.wsgi_app) server.watch('website/static/scss/**/*.scss', func=sass) server.watch('website') server.serve(port=5001)
def dev(port=8000): local(_makePelican()) local(_makeTheme()) os.chdir(OUTPUT) server = livereload.Server() server.watch('../content/*', _makePelican()) server.watch('../content/pages/*', _makePelican()) server.watch('../content/articles/*', _makePelican()) server.watch('../themes/combo/templates/*', _makePelican()) server.watch('../themes/combo/static/less/*', _makeTheme()) server.watch('../themes/combo/static/*.css', _makePelican()) server.watch('*.html') server.watch('*.css') server.serve(liveport=35729, port=port, debug=True)
def _live_build(mode, port=8585): local('make clean') if mode == 'prod': local('make publish') conf = 'publishconf' elif mode == 'dev': local('make html') conf = 'pelicanconf' else: raise ValueError(f"Invalid conf: {conf}") os.chdir('output') server = livereload.Server() server.watch('../content/*.rst', livereload.shell(f'pelican -s ../{conf}.py -o ../output')) server.watch('*.html') server.watch('*.css') server.serve(liveport=35729, host='0.0.0.0', port=port)
def serve(config_file='moosedocs.yml', host='127.0.0.1', port='8000'): """ Create live server """ # Location of serve site tempdir = os.path.abspath(os.path.join(os.getenv('HOME'), '.local', 'share', 'moose', 'site')) # Clean the "temp" directory (if desired) if os.path.exists(tempdir): log.info('Cleaning build directory: {}'.format(tempdir)) shutil.rmtree(tempdir) # Create the "temp" directory if not os.path.exists(tempdir): os.makedirs(tempdir) # Perform the initial build log.info("Building documentation...") # Wrapper for building complete website def build_complete(): return build.build(config_file=config_file, site_dir=tempdir) config, parser, builder = build_complete() # Start the live server server = livereload.Server() # Watch markdown files for page in builder: server.watch(page.filename, page.build) # Watch support directories server.watch(os.path.join(os.getcwd(), 'media'), builder.copyFiles) server.watch(os.path.join(os.getcwd(), 'css'), builder.copyFiles) server.watch(os.path.join(os.getcwd(), 'js'), builder.copyFiles) server.watch(os.path.join(os.getcwd(), 'fonts'), builder.copyFiles) # Watch the pages file server.watch(config['pages'], build_complete) # Start the server server.serve(root=config['site_dir'], host=host, port=port, restart_delay=0)
def live_build(port=8000): local('make clean') local('make html') os.chdir('output') server = livereload.Server() server.watch('../content/*.rst', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('../', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('../theme/', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('../theme/templates/', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('../theme/static/', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('../theme/static/css/', livereload.shell('pelican -s ../pelicanconf.py -o ../output')) server.watch('*.html') server.watch('*.css') server.serve(liveport=35729, port=port)
def _livereload(host, port, config, builder, site_dir): """ Mimics the mkdocs.commands.serve._livereload function. @TODO: When the mkdocs plugin system allows for custom Watcher this should be removed. """ # We are importing here for anyone that has issues with livereload. Even if # this fails, the --no-livereload alternative should still work. from livereload import Server watcher = MooseDocsWatcher() server = livereload.Server(None, watcher) # Watch the documentation files, the config file and the theme files. server.watch(config['docs_dir'], builder) server.watch(config['config_file_path'], builder) for d in config['theme_dir']: server.watch(d, builder) server.serve(root=site_dir, host=host, port=int(port), restart_delay=0)