本文整理汇总了Python中livereload.Server方法的典型用法代码示例。如果您正苦于以下问题:Python livereload.Server方法的具体用法?Python livereload.Server怎么用?Python livereload.Server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类livereload
的用法示例。
在下文中一共展示了livereload.Server方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: livereload
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def livereload(ctx):
"""Automatically reload browser tab upon file modification."""
from livereload import Server
server = Server()
# Watch the base settings file
server.watch(CONFIG['settings_base'], lambda: build(ctx))
# Watch content source files
content_file_extensions = ['.md', '.rst']
for extension in content_file_extensions:
content_blob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
server.watch(content_blob, lambda: build(ctx))
# Watch the theme's templates and static assets
theme_path = SETTINGS['THEME']
server.watch('{}/templates/*.html'.format(theme_path), lambda: build(ctx))
static_file_extensions = ['.css', '.js']
for extension in static_file_extensions:
static_file = '{0}/static/**/*{1}'.format(theme_path, extension)
server.watch(static_file, lambda: build(ctx))
# Serve output path on configured port
server.serve(port=CONFIG['port'], root=CONFIG['deploy_path'])
####################################################################################################
示例2: on_serve
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def on_serve(self, server: Server, config: Config, builder: Callable = None, **kwargs) -> Server:
"""
Hook for the [`on_serve` event](https://www.mkdocs.org/user-guide/plugins/#on_serve).
In this hook, we add the directories specified in the plugin's configuration to the list of directories
watched by `mkdocs`. Whenever a change occurs in one of these directories, the documentation is built again
and the site reloaded.
"""
if builder is None:
# The builder parameter was added in mkdocs v1.1.1.
# See issue https://github.com/mkdocs/mkdocs/issues/1952.
builder = list(server.watcher._tasks.values())[0]["func"]
for element in self.config["watch"]:
log.debug(f"mkdocstrings.plugin: Adding directory '{element}' to watcher")
server.watch(element, builder)
return server
示例3: handle
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def handle(self, *args, **options):
m = re.match(naiveip_re, options['addrport'])
if m is None:
raise CommandError('"%s" is not a valid port number '
'or address:port pair.' % options['addrport'])
addr, _ipv4, _ipv6, _fqdn, port = m.groups()
if not port.isdigit():
raise CommandError("%r is not a valid port number." % port)
if addr:
if _ipv6:
raise CommandError('IPv6 addresses are currently not supported.')
application = get_internal_wsgi_application()
server = Server(application)
for file in os.listdir('.'):
if file[0] != '.' and file[:2] != '__' and os.path.isdir(file):
server.watch(file)
server.serve(host=addr, port=port, liveport=options['liveport'])
示例4: start_livereload
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def start_livereload(self):
from livereload import Server
server = Server()
for path in settings.STATICFILES_DIRS:
server.watch(path)
for path in settings.TEMPLATES[0]["DIRS"]:
server.watch(path)
server.serve(port=settings.LIVERELOAD_PORT)
示例5: live
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def live():
"""Run livereload server"""
from livereload import Server
server = Server(app)
map(server.watch, glob2.glob("application/pages/**/*.*")) # pages
map(server.watch, glob2.glob("application/macros/**/*.html")) # macros
map(server.watch, glob2.glob("application/static/**/*.*")) # public assets
server.serve(port=PORT)
示例6: _livereload
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def _livereload(host, port, config, builder, site_dir):
# We are importing here for anyone that has issues with livereload. Even if
# this fails, the --no-livereload alternative should still work.
_init_asyncio_patch()
from livereload import Server
import livereload.handlers
class LiveReloadServer(Server):
def get_web_handlers(self, script):
handlers = super().get_web_handlers(script)
# replace livereload handler
return [(handlers[0][0], _get_handler(site_dir, livereload.handlers.StaticFileHandler), handlers[0][2],)]
server = LiveReloadServer()
# 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'].dirs:
server.watch(d, builder)
# Run `serve` plugin events.
server = config['plugins'].run_event('serve', server, config=config, builder=builder)
server.serve(root=site_dir, host=host, port=port, restart_delay=0)
示例7: serve
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def serve(host, port, debug, livereload, test):
"""Start the web server."""
pymongo_config = dict(
MONGO_HOST=current_app.config.get("MONGO_HOST", "localhost"),
MONGO_PORT=current_app.config.get("MONGO_PORT", 27017),
MONGO_DBNAME=current_app.config.get("MONGO_DBNAME", "scout"),
MONGO_USERNAME=current_app.config.get("MONGO_USERNAME", None),
MONGO_PASSWORD=current_app.config.get("MONGO_PASSWORD", None),
)
valid_connection = check_connection(
host=pymongo_config["MONGO_HOST"],
port=pymongo_config["MONGO_PORT"],
username=pymongo_config["MONGO_USERNAME"],
password=pymongo_config["MONGO_PASSWORD"],
authdb=current_app.config.get("MONGO_DBNAME", "scout"),
)
LOG.info("Test if mongod is running")
if not valid_connection:
LOG.warning("Connection could not be established")
LOG.info("Is mongod running?")
raise click.Abort()
if test:
LOG.info("Connection could be established")
return
if livereload:
server = Server(current_app.wsgi_app)
server.serve(host=host, port=port, debug=debug)
else:
return run_simple(
hostname=host,
port=port,
application=current_app,
use_reloader=False,
use_debugger=debug,
)
示例8: main
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def main():
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
(options, args) = parse_options()
port = options.port
assets_path = options.path
file_prefix = options.prefix
host_address = options.host_address
csv.register_dialect('custom_delimiter', delimiter=options.delimiter)
card_renderer = CardRenderer(assets_path, file_prefix)
observer = Observer()
observer.schedule(LoggingEventHandler(), assets_path, recursive=True)
observer.schedule(RenderingEventHandler(card_renderer), assets_path, recursive=True)
card_renderer.render_cards()
observer.start()
server = Server()
server.watch(card_renderer.all_cards_rendered_path)
server.serve(root=assets_path, port=port, host=host_address)
observer.stop()
observer.join()
示例9: _livereload
# 需要导入模块: import livereload [as 别名]
# 或者: from livereload import Server [as 别名]
def _livereload(host, port, config, builder, site_dir):
# We are importing here for anyone that has issues with livereload. Even if
# this fails, the --no-livereload alternative should still work.
_init_asyncio_patch()
from livereload import Server
import livereload.handlers
class LiveReloadServer(Server):
def get_web_handlers(self, script):
handlers = super().get_web_handlers(script)
# replace livereload handler
return [(handlers[0][0], _get_handler(site_dir, livereload.handlers.StaticFileHandler), handlers[0][2],)]
server = LiveReloadServer()
# 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'].dirs:
server.watch(d, builder)
# Run `serve` plugin events.
server = config['plugins'].run_event('serve', server, config=config)
server.serve(root=site_dir, host=host, port=port, restart_delay=0)