当前位置: 首页>>代码示例>>Python>>正文


Python ConfigManager.get方法代码示例

本文整理汇总了Python中notebook.services.config.ConfigManager.get方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.get方法的具体用法?Python ConfigManager.get怎么用?Python ConfigManager.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在notebook.services.config.ConfigManager的用法示例。


在下文中一共展示了ConfigManager.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
def install(enable=False, **kwargs):
    """Install the nbpresent nbextension assets and optionally enables the
       nbextension and server extension for every run.

    Parameters
    ----------
    enable: bool
        Enable the extension on every notebook launch
    **kwargs: keyword arguments
        Other keyword arguments passed to the install_nbextension command
    """
    from notebook.nbextensions import install_nbextension
    from notebook.services.config import ConfigManager

    directory = join(dirname(abspath(__file__)), "static", "nbpresent")

    kwargs = {k: v for k, v in kwargs.items() if not (v is None)}

    kwargs["destination"] = "nbpresent"
    install_nbextension(directory, **kwargs)

    if enable:
        path = jupyter_config_dir()
        if "prefix" in kwargs:
            path = join(kwargs["prefix"], "etc", "jupyter")
            if not exists(path):
                print("Making directory", path)
                os.makedirs(path)

        cm = ConfigManager(config_dir=path)
        print("Enabling nbpresent server component in", cm.config_dir)
        cfg = cm.get("jupyter_notebook_config")
        print("Existing config...")
        pprint(cfg)
        server_extensions = cfg.setdefault("NotebookApp", {}).setdefault("server_extensions", [])
        if "nbpresent" not in server_extensions:
            cfg["NotebookApp"]["server_extensions"] += ["nbpresent"]

        cm.update("jupyter_notebook_config", cfg)
        print("New config...")
        pprint(cm.get("jupyter_notebook_config"))

        _jupyter_config_dir = jupyter_config_dir()
        # try:
        #     subprocess.call(["conda", "info", "--root"])
        #     print("conda detected")
        #     _jupyter_config_dir = ENV_CONFIG_PATH[0]
        # except OSError:
        #     print("conda not detected")

        cm = ConfigManager(config_dir=join(_jupyter_config_dir, "nbconfig"))
        print("Enabling nbpresent nbextension at notebook launch in", cm.config_dir)

        if not exists(cm.config_dir):
            print("Making directory", cm.config_dir)
            os.makedirs(cm.config_dir)

        cm.update("notebook", {"load_extensions": {"nbpresent/nbpresent.min": True}})
开发者ID:bollwyvl,项目名称:nbpresent,代码行数:60,代码来源:install.py

示例2: install

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
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"))
开发者ID:fdeheeger,项目名称:nb_config_manager,代码行数:57,代码来源:install.py

示例3: setup_info

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
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))
开发者ID:01-,项目名称:hide_code,代码行数:28,代码来源:hide_code.py

示例4: __init__

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
    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))
开发者ID:codegenerator-tools,项目名称:jupyter_contrib_nbextensions,代码行数:31,代码来源:collapsible_headings.py

示例5: disable_nbextension

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
 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}})
开发者ID:nwhitehead,项目名称:notebook,代码行数:10,代码来源:nbextensions.py

示例6: get_bundler

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
 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]
开发者ID:bucweat,项目名称:contentmanagement,代码行数:11,代码来源:bundler.py

示例7: enable_server_extension

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
    def enable_server_extension(self, extension):
        '''Enables the server side extension in the user config.'''
        server_cm = ConfigManager(config_dir=jupyter_config_dir())
        
        makedirs(server_cm.config_dir)

        cfg = server_cm.get('jupyter_notebook_config')
        server_extensions = (
            cfg.setdefault('NotebookApp', {})
            .setdefault('server_extensions', [])
        )
        if extension not in server_extensions:
            cfg['NotebookApp']['server_extensions'] += [extension]
        server_cm.update('jupyter_notebook_config', cfg)
开发者ID:jupyter-incubator,项目名称:contentmanagement,代码行数:16,代码来源:extensionapp.py

示例8: __init__

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
    def __init__(self, *args, **kwargs):
        super(ExporterCollapsibleHeadings, self).__init__(*args, **kwargs)

        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())

        self.inliner_resources['css'].append("""
/* no local copies of fontawesome fonts from basic templates, so get them from cdn */
@font-face {
    font-family: 'FontAwesome';
    src: url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.eot');
    src: url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.eot?#iefix') format('embedded-opentype'),
         url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.woff') format('woff'),
         url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf') format('truetype'),
         url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/fonts/fontawesome-webfont.svg#fontawesomeregular') format('svg');
    font-weight: normal;
    font-style: normal;
}
""")  # noqa: E501

        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("""
require([
    'jquery',
    'nbextensions/collapsible_headings/main'
], function (
    $,
    nbext
) {
    nbext.set_collapsible_headings_options(%s);
    $(document).ready(function () {
        nbext.refresh_all_headings();
    });
});
""" % json.dumps(collapsible_headings_options))
开发者ID:joequant,项目名称:IPython-notebook-extensions,代码行数:46,代码来源:collapsible_headings.py

示例9: disable_server_extension

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
    def disable_server_extension(self, extension):
        '''Disables the server side extension in the user config.'''
        server_cm = ConfigManager(config_dir=jupyter_config_dir())
        
        makedirs(server_cm.config_dir)

        cfg = server_cm.get('jupyter_notebook_config')
        if ('NotebookApp' in cfg and
            'server_extensions' in cfg['NotebookApp'] and
            extension in cfg['NotebookApp']['server_extensions']):
            cfg['NotebookApp']['server_extensions'].remove(extension)

        server_cm.update('jupyter_notebook_config', cfg)

        server_extensions = (
            cfg.setdefault('NotebookApp', {})
            .setdefault('server_extensions', [])
        )
        if extension in server_extensions:
            cfg['NotebookApp']['server_extensions'].remove(extension)
        server_cm.update('jupyter_notebook_config', cfg)
开发者ID:jupyter-incubator,项目名称:contentmanagement,代码行数:23,代码来源:extensionapp.py

示例10: install_extension

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
def install_extension():
    # Import inside run() so if the user doesn't have jupyter notebook yet, we grab that dependency,
    # then run this code which imports it.
    from notebook.nbextensions import install_nbextension
    from notebook.services.config import ConfigManager
    from jupyter_core.paths import jupyter_config_dir

    # Install JavaScript extension
    install_nbextension(os.path.join(EXT_DIR, "extensions", "spark.js"), overwrite=True, user=True)

    # Activate the JS extensions on the notebook
    js_cm = ConfigManager()
    js_cm.update('notebook', {"load_extensions": {'spark': True}})

    # Activate the Python server extension
    server_cm = ConfigManager(config_dir=jupyter_config_dir())
    cfg = server_cm.get('jupyter_notebook_config')
    server_extensions = cfg.setdefault('NotebookApp', {}).setdefault('server_extensions', [])
    if "jupyter-spark.spark" not in server_extensions:
        cfg['NotebookApp']['server_extensions'] += ['jupyter-spark.spark']
        server_cm.update('jupyter_notebook_config', cfg)
开发者ID:jolayz,项目名称:jupyter-spark,代码行数:23,代码来源:setup.py

示例11: get_bundler

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
 def get_bundler(self, bundler_id):
     """
     Get bundler metadata from config given a bundler ID.
     
     Parameters
     ----------
     bundler_id: str
         Unique bundler ID within the notebook/bundlerextensions config section
     
     Returns
     -------
     dict
         Bundler metadata with label, group, and module_name attributes
     
     
     Raises
     ------
     KeyError
         If the bundler ID is unknown
     """
     cm = ConfigManager()
     return cm.get('notebook').get('bundlerextensions', {})[bundler_id]
开发者ID:BarnetteME1,项目名称:DnD-stuff,代码行数:24,代码来源:handlers.py

示例12: ConfigManager

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
import tornado
from tornado import web
import json
import io
import re
import logging
import random
import string
from server.db import ipy_mongodb_steps as db


logger = logging.getLogger()

from notebook.services.config import ConfigManager
cm = ConfigManager()
nb = cm.get('notebook')


class Encoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, ObjectId):
            return str(obj)
        else:
            return obj

'''
    /distprojects:
        post:
            description: Create new Step

        put:
开发者ID:Feldman-Michael,项目名称:masterthesis,代码行数:33,代码来源:ipy_service_steps.py

示例13: install

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
def install(nb_path=None, server_config=True, DEBUG=False):
	install_path = None
	print('Starting hide_code.js install...')
	current_dir = path.abspath(path.dirname(__file__))
	config_dirs = j_path.jupyter_config_path()
	site_packages_path = Utils.get_site_package_dir()

	# check for config directory with a "custom" folder
	# TODO update this logic to check if custom.js file exists
	for dir in config_dirs:
		custom_dir = path.join(dir, "custom")
		if path.isdir(custom_dir):
			install_path = custom_dir
			break

	# last ditch effort in case jupyter config directories don't contain custom/custom.js		
	if install_path == None:	
		print("No config directories contain \"custom\" folder. Trying site-packages...")	
		install_path = path.join(site_packages_path, "notebook", "static", "custom")
	

	if nb_path != None:
		install_path = nb_path
		print("Using argument supplied path: " + install_path)

	if DEBUG:
		print(install_path)

	# copy js into static/custom directory in Jupyter/iPython directory
	if path.isdir(install_path):
		shutil.copyfile(path.join(current_dir, "hide_code.js"), path.join(install_path, "hide_code.js"))
		print('Copying hide_code.js to ' + install_path) 

		# add require to end of custom.js to auto-load on notebook startup
		print("Attempting to configure custom.js to auto-load hide_code.js...")
		try:
			with open(path.join(current_dir, "auto-load.txt")) as auto:
				auto_load_txt = auto.read();
				auto_loaded = False

				# check if auto-load.txt is already in custom.js
				with open(path.join(install_path, "custom.js"), 'r') as customJS:
					if auto_load_txt in customJS.read():
						auto_loaded = True
						print("Custom.js already configured to auto-load hide_code.js.")


				if not auto_loaded:  # append auto load require to end of custom.js
					with open(path.join(install_path, "custom.js"), 'a') as customJS:
						customJS.write(auto_load_txt)
						print("Configured custom.js to auto-load hide_code.js.")
		except:
			print("Custom.js not in custom directory.")
	else:
		print('Unable to install into ' + install_path)
		print('Directory doesn\'t exist.')
		print('Make sure Jupyter is installed.')

	if server_config:
		print("Attempting to configure auto-loading for hide_code export handlers.")
		try:
			# Activate the Python server extension
			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:
				cfg['NotebookApp']['server_extensions'] += [extension]
				server_cm.update('jupyter_notebook_config', cfg)
				print('Configured jupyter to auto-load hide_code export handlers.')
			else:
				print("Jupyter already configured to auto-load export handlers.")
		except:
			print('Unable to install server extension.') 
开发者ID:01-,项目名称:hide_code,代码行数:78,代码来源:hide_code.py

示例14: _migrate_require_paths

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
def _migrate_require_paths(logger=None):
    """Migrate require paths from old to new values."""
    if logger:
        logger.info('- Migrating require paths from old to new locations')

    mappings = {
        'notebook': [
            ('config/config_menu/main',
             'nbextensions_configurator/config_menu/main'),
        ] + [(req, req.split('/', 1)[1]) for req in [
            'codemirrormode/skill/skill',
            'publishing/gist_it/main',
            'publishing/printview/main',
            'styling/table_beautifier/main',
            'styling/zenmode/main',
            'usability/autosavetime/main',
            'usability/autoscroll/main',
            'usability/chrome-clipboard/main',
            'usability/code_font_size/code_font_size',
            'usability/codefolding/main',
            'usability/collapsible_headings/main',
            'usability/comment-uncomment/main',
            'usability/datestamper/main',
            'usability/dragdrop/main',
            'usability/equation-numbering/main',
            'usability/execute_time/ExecuteTime',
            'usability/exercise/main',
            'usability/exercise2/main',
            'usability/freeze/main',
            'usability/help_panel/help_panel',
            'usability/hide_input/main',
            'usability/hide_input_all/main',
            'usability/highlighter/highlighter',
            'usability/hinterland/hinterland',
            'usability/init_cell/main',
            'usability/keyboard_shortcut_editor/main',
            'usability/latex_envs/latex_envs',
            'usability/limit_output/main',
            'usability/move_selected_cells/main',
            'usability/navigation-hotkeys/main',
            'usability/notify/notify',
            'usability/python-markdown/main',
            'usability/qtconsole/qtconsole',
            'usability/rubberband/main',
            'usability/ruler/main',
            'usability/runtools/main',
            'usability/scratchpad/main',
            'usability/search-replace/main',
            'usability/skip-traceback/main',
            'usability/spellchecker/main',
            'usability/splitcell/splitcell',
            'usability/toc2/main',
            'usability/toggle_all_line_numbers/main',
        ]],
        'tree': [
            ('usability/tree-filter/index', 'tree-filter/index'),
        ]
    }

    fecm = FrontendConfigManager()
    for section in mappings:
        conf = fecm.get(section)
        load_extensions = conf.get('load_extensions', {})
        for old, new in mappings[section]:
            status = load_extensions.pop(old, None)
            if status is not None:
                if logger:
                    logger.debug('--  Migrating {!r} -> {!r}'.format(old, new))
                load_extensions[new] = status
        fecm.set(section, conf)
开发者ID:flying-sheep,项目名称:jupyter_contrib_nbextensions,代码行数:72,代码来源:migrate.py

示例15: install

# 需要导入模块: from notebook.services.config import ConfigManager [as 别名]
# 或者: from notebook.services.config.ConfigManager import get [as 别名]
def install(enable=False, **kwargs):
    """Install the nbpresent nbextension assets and optionally enables the
       nbextension and server extension for every run.

    Parameters
    ----------
    enable: bool
        Enable the extension on every notebook launch
    **kwargs: keyword arguments
        Other keyword arguments passed to the install_nbextension command
    """
    from notebook.nbextensions import install_nbextension
    from notebook.services.config import ConfigManager

    directory = join(abspath(dirname(__file__)), 'static', 'nbpresent')

    kwargs = {k: v for k, v in kwargs.items() if not (v is None)}

    kwargs["destination"] = "nbpresent"
    install_nbextension(directory, **kwargs)

    if enable:
        if "prefix" in kwargs:
            path = join(kwargs["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 nbpresent server component in", cm.config_dir)
        cfg = cm.get("jupyter_notebook_config")
        print("Existing config...")
        pprint(cfg)
        server_extensions = (
            cfg.setdefault("NotebookApp", {})
            .setdefault("server_extensions", [])
        )
        if "nbpresent" not in server_extensions:
            cfg["NotebookApp"]["server_extensions"] += ["nbpresent"]

        cm.update("jupyter_notebook_config", cfg)
        print("New config...")
        pprint(cm.get("jupyter_notebook_config"))

        cm = ConfigManager(config_dir=join(path, "nbconfig"))
        print(
            "Enabling nbpresent nbextension at notebook launch in",
            cm.config_dir
        )

        if not exists(cm.config_dir):
            print("Making directory", cm.config_dir)
            os.makedirs(cm.config_dir)

        cm.update(
            "notebook", {
                "load_extensions": {
                    "nbpresent/js/nbpresent.min": True
                },
            }
        )
开发者ID:scollis,项目名称:nbpresent,代码行数:65,代码来源:install.py


注:本文中的notebook.services.config.ConfigManager.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。