def _set_bundler_state(name, label, module_name, group, state, user=True, sys_prefix=False, logger=None): """Set whether a bundler is enabled or disabled. Returns True if the final state is the one requested. Parameters ---------- name : string Unique name of the bundler label : string Human-readable label for the bundler menu item in the UI module_name : string Dotted module/package name containing the bundler group : string 'download' or 'deploy' indicating the parent menu containing the label state : bool The state in which to leave the extension user : bool [default: True] Whether to update the user's .jupyter/serverconfig directory sys_prefix : bool [default: False] Whether to update the sys.prefix, i.e. environment. Will override `user`. logger : Jupyter logger [optional] Logger instance to use """ user = False if sys_prefix else user config_dir = os.path.join( _get_config_dir(user=user, sys_prefix=sys_prefix), 'serverconfig') cm = BaseJSONConfigManager(config_dir=config_dir) if logger: logger.info("{} {} bundler {}...".format( "Enabling" if state else "Disabling", name, module_name)) if state: cm.update( BUNDLER_SECTION, { BUNDLER_SUBSECTION: { name: { "label": label, "module_name": module_name, "group": group } } }) else: cm.update(BUNDLER_SECTION, {BUNDLER_SUBSECTION: {name: None}}) return (cm.get(BUNDLER_SECTION).get(BUNDLER_SUBSECTION, {}).get(name) is not None) == state
def toggle_server_extension_python(import_name, enabled=None, parent=None, user=False, sys_prefix=True): """Toggle the boolean setting for a given server extension in a Jupyter config file. """ sys_prefix = False if user else sys_prefix config_dir = _get_config_dir(user=user, sys_prefix=sys_prefix) cm = BaseJSONConfigManager(parent=parent, config_dir=config_dir) cfg = cm.get("jupyter_server_config") server_extensions = cfg.setdefault("ServerApp", {}).setdefault("jpserver_extensions", {}) old_enabled = server_extensions.get(import_name, None) new_enabled = enabled if enabled is not None else not old_enabled server_extensions[import_name] = new_enabled cm.update("jupyter_server_config", cfg)
def set_password(args): password = args.password while not password: password1 = getpass("" if args.quiet else "Provide password: "******"" if args.quiet else "Repeat password: "******"Passwords do not match, try again") elif len(password1) < 4: print("Please provide at least 4 characters") else: password = password1 password_hash = passwd(password) cfg = BaseJSONConfigManager(config_dir=jupyter_config_dir()) cfg.update("jupyter_server_config", {"ServerApp": { "password": password_hash, }}) if not args.quiet: print("password stored in config dir: %s" % jupyter_config_dir())