本文整理汇总了Python中notebook.services.config.ConfigManager类的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager类的具体用法?Python ConfigManager怎么用?Python ConfigManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_info
def setup_info():
server_cm = ConfigManager(config_dir=j_path.jupyter_config_dir())
cfg = server_cm.get('jupyter_notebook_config')
server_extensions = (cfg.setdefault('NotebookApp', {})
.setdefault('server_extensions', [])
)
extension = 'hide_code.hide_code'
if extension not in server_extensions:
ext = 'Not loaded'
else:
ext = 'Loaded'
files = []
for (dirpath, dirnames, filenames) in os.walk(path.join(Utils.get_site_package_dir(), 'hide_code')):
files.extend(filenames)
break
custom_js = ''
with open(path.join(Utils.get_site_package_dir(), 'notebook','static','custom','custom.js'), 'r') as f:
for line in iter(f):
if not line.startswith(' *') and not line.startswith('/'):
custom_js = custom_js + line + ' '
return ("Installation dir: {0}\nConfiguration dir: {1}\nExport handler extensions: {2}\nHide Code files: {3}\nCustom JS contents: {4}"
.format(Utils.get_site_package_dir(), j_path.jupyter_config_dir(), ext, files, custom_js))
示例2: install
def install(user=False, symlink=False, overwrite=False, enable=False,
**kwargs):
"""Install the nbpresent nbextension.
Parameters
----------
user: bool
Install for current user instead of system-wide.
symlink: bool
Symlink instead of copy (for development).
overwrite: bool
Overwrite previously-installed files for this extension
enable: bool
Enable the extension on every notebook launch
**kwargs: keyword arguments
Other keyword arguments passed to the install_nbextension command
"""
print("Installing nbpresent nbextension...")
directory = join(dirname(abspath(__file__)), 'static', 'nbpresent')
install_nbextension(directory, destination='nbpresent',
symlink=symlink, user=user, overwrite=overwrite,
**kwargs)
if enable:
print("Enabling nbpresent at every notebook launch...")
cm = ConfigManager()
cm.update('notebook',
{"load_extensions": {"nbpresent/nbpresent.min": True}})
示例3: install_server_extension
def install_server_extension(enable=True):
"""Register ipyparallel clusters tab as a notebook server extension
Toggle with enable=True/False.
"""
# server-side
server = BaseJSONConfigManager(config_dir=jupyter_config_dir())
server_cfg = server.get('jupyter_notebook_config')
app_cfg = server_cfg.get('NotebookApp', {})
server_extensions = app_cfg.get('server_extensions', [])
server_ext = 'ipyparallel.nbextension'
server_changed = False
if enable and server_ext not in server_extensions:
server_extensions.append(server_ext)
server_changed = True
elif (not enable) and server_ext in server_extensions:
server_extensions.remove(server_ext)
server_changed = True
if server_changed:
server.update('jupyter_notebook_config', {
'NotebookApp': {
'server_extensions': server_extensions,
}
})
# frontend config (*way* easier because it's a dict)
frontend = FrontendConfigManager()
frontend.update('tree', {
'load_extensions': {
'ipyparallel/main': enable or None,
}
})
示例4: start
def start(self):
self.log.info("Activating jupyter_dashboards_bundlers JS notebook extensions")
cm = ConfigManager(parent=self, config=self.config)
cm.update('notebook', {
'jupyter_cms_bundlers': {
'dashboards_local_deploy': {
'label': 'Local Dashboard',
'module_name': 'dashboards_bundlers.local_deploy',
'group': 'deploy'
},
'dashboards_php_download': {
'label': 'PHP Dashboard bundle (.zip)',
'module_name': 'dashboards_bundlers.php_download',
'group': 'download'
},
'dashboards_server_upload': {
'label': 'Dashboard on Jupyter Dashboards Server',
'module_name': 'dashboards_bundlers.server_upload',
'group': 'deploy'
},
'dashboards_server_download': {
'label': 'Jupyter Dashboards Server bundle (.zip)',
'module_name': 'dashboards_bundlers.server_download',
'group': 'download'
}
}
})
self.log.info("Done.")
示例5: _install_extension_nb41
def _install_extension_nb41(enable=True):
"""deprecated, pre-4.2 implementation of installing notebook extension"""
# server-side
server = BaseJSONConfigManager(config_dir=jupyter_config_dir())
server_cfg = server.get('jupyter_notebook_config')
app_cfg = server_cfg.get('NotebookApp', {})
server_extensions = app_cfg.get('server_extensions', [])
server_ext = 'ipyparallel.nbextension'
server_changed = False
if enable and server_ext not in server_extensions:
server_extensions.append(server_ext)
server_changed = True
elif (not enable) and server_ext in server_extensions:
server_extensions.remove(server_ext)
server_changed = True
if server_changed:
server.update('jupyter_notebook_config', {
'NotebookApp': {
'server_extensions': server_extensions,
}
})
# frontend config (*way* easier because it's a dict)
frontend = FrontendConfigManager()
frontend.update('tree', {
'load_extensions': {
'ipyparallel/main': enable or None,
}
})
示例6: __init__
def __init__(self, *args, **kwargs):
super(ExporterCollapsibleHeadings, self).__init__(*args, **kwargs)
self.inliner_resources['css'].append("""
/* no local copies of fontawesome fonts in basic templates, so use cdn */
@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css)
""") # noqa: E501
ch_dir = os.path.join(
os.path.dirname(contrib_init), 'nbextensions',
'collapsible_headings')
with open(os.path.join(ch_dir, 'main.css'), 'r') as f:
self.inliner_resources['css'].append(f.read())
with open(os.path.join(ch_dir, 'main.js'), 'r') as f:
self.inliner_resources['js'].append(f.read())
cm = ConfigManager()
collapsible_headings_options = cm.get('notebook').get(
'collapsible_headings', {})
self.inliner_resources['js'].append("""
$(document).ready(function () {
require(['nbextensions/collapsible_headings/main'], function (ch) {
ch.set_collapsible_headings_options(%s);
ch.refresh_all_headings();
});
});
""" % json.dumps(collapsible_headings_options))
示例7: install
def install(user=False, symlink=False, quiet=False, enable=False):
"""Install the widget nbextension and optionally enable it.
Parameters
----------
user: bool
Install for current user instead of system-wide.
symlink: bool
Symlink instead of copy (for development).
enable: bool
Enable the extension after installing it.
quiet: bool
Suppress print statements about progress.
"""
if not quiet:
print("Installing nbextension ...")
staticdir = pjoin(dirname(abspath(__file__)), "static")
install_nbextension(staticdir, destination="widgets", user=user, symlink=symlink)
if enable:
if not quiet:
print("Enabling the extension ...")
cm = ConfigManager()
cm.update("notebook", {"load_extensions": {"widgets/extension": True}})
if not quiet:
print("Done.")
示例8: install
def install(config_dir, use_symlink=False, enable=True):
# Install the livereveal code.
install_nbextension(livereveal_dir, symlink=use_symlink,
overwrite=use_symlink, user=True)
if enable:
cm = ConfigManager(config_dir=config_dir)
cm.update('notebook', {"load_extensions": {"livereveal/main": True}})
示例9: disable_nbextension
def disable_nbextension(self, name):
# Local import to avoid circular import issue on Py 2
from notebook.services.config import ConfigManager
cm = ConfigManager(parent=self, config=self.config)
if name not in cm.get(self.section).get('load_extensions', {}):
sys.exit('{} is not enabled in section {}'.format(name, self.section))
# We're using a dict as a set - updating with None removes the key
cm.update(self.section, {"load_extensions": {name: None}})
示例10: disable_bundler
def disable_bundler(self):
'''Disables the notebook bundler extension.'''
cm = ConfigManager(parent=self, config=self.config)
cm.update('notebook', {
'jupyter_cms_bundlers': {
'notebook_associations_download': None
}
})
示例11: start
def start(self):
self.log.info("Deactivating jupyter_kernel_gateway_bundlers notebook extension")
cm = ConfigManager(parent=self, config=self.config)
cm.update('notebook', {
'jupyter_cms_bundlers': {
'microservice_dockerfile_download' : None
}
})
self.log.info("Done.")
示例12: get_bundler
def get_bundler(self, bundler_id):
'''
:param bundler_id: Unique ID within the notebook/jupyter_cms_bundlers
config section.
:returns: Dict of bundler metadata with keys label, group, module_name
:raises KeyError: If the bundler is not registered
'''
cm = ConfigManager()
return cm.get('notebook').get('jupyter_cms_bundlers', {})[bundler_id]
示例13: config_configManager
def config_configManager():
print("Update ConfigManager")
from notebook.services.config import ConfigManager
cm = ConfigManager()
cm.update('livereveal', {
'theme': 'serif',
'start_slideshow_at': 'selected',
'width': 1680,
'height': 768,
})
示例14: __init__
def __init__(self, name, **kwargs):
self.name = name
self.prefix = kwargs.get('prefix', None)
self.kwargs = kwargs
if self.prefix is None:
self.path = jupyter_config_dir()
else:
self.path = join(self.prefix, "etc", "jupyter")
self.cm = ConfigManager(config_dir=join(self.path, 'nbconfig'))
self.cm_server = ConfigManager(config_dir=self.path)
示例15: install
def install(enable=False, disable=False, prefix=None):
"""Install the nb_config_manager config piece.
Parameters
----------
enable: bool
Enable the nb_config_manager on every notebook launch
disable: bool
Disable nb_config_manager on every notebook launch
"""
from notebook.services.config import ConfigManager
if enable:
if prefix is not None:
path = join(prefix, "etc", "jupyter")
if not exists(path):
print("Making directory", path)
os.makedirs(path)
else:
path = jupyter_config_dir()
cm = ConfigManager(config_dir=path)
print("Enabling nb_config_manager in", cm.config_dir)
cfg = cm.get("jupyter_notebook_config")
print("Existing config...")
pprint(cfg)
notebook_app = cfg.setdefault("NotebookApp", {})
if "config_manager_class" not in notebook_app:
cfg["NotebookApp"]["config_manager_class"] = "nb_config_manager.EnvironmentConfigManager"
cm.update("jupyter_notebook_config", cfg)
print("New config...")
pprint(cm.get("jupyter_notebook_config"))
if disable:
if prefix is not None:
path = join(prefix, "etc", "jupyter")
else:
path = jupyter_config_dir()
cm = ConfigManager(config_dir=path)
print("Disabling nb_config_manager in", cm.config_dir)
cfg = cm.get("jupyter_notebook_config")
print("Existing config...")
pprint(cfg)
config_manager = cfg["NotebookApp"]["config_manager_class"]
if "nb_config_manager.EnvironmentConfigManager" == config_manager:
cfg["NotebookApp"].pop("config_manager_class")
cm.set("jupyter_notebook_config", cfg)
print("New config...")
pprint(cm.get("jupyter_notebook_config"))