def inject_environment_config(self): if not self.do_inject_environment_config: return for shell in SHELL_CONFIG: if shell == 'gui': if system.is_debian(): self._inject_config_source(".env", SHELL_CONFIG['gui']['debian']) else: if (self.global_config.has_option('shell', shell) and lib.is_affirmative(self.global_config.get('shell', shell))): rc_file, rc_path = self._inject_config_source(".rc", SHELL_CONFIG[shell]['rc']) env_file, env_path = self._inject_config_source(".env", SHELL_CONFIG[shell]['env']) # If an rc file is sourced by an env file, we should alert the user. if (self.phase is PHASE.INSTALL and self.injections.in_noninjected_file(env_path, rc_file) and self.global_injections.in_noninjected_file(env_path, rc_file)): self.logger.info("You appear to be sourcing %s from inside %s." % (rc_file, env_file)) self.logger.info("Please ensure it is wrapped in a #SPRINTER_OVERRIDES block " + "to avoid repetitious operations!") full_rc_path = os.path.expanduser(os.path.join("~", rc_file)) full_env_path = os.path.expanduser(os.path.join("~", env_file)) if lib.is_affirmative(self.global_config.get('global', 'env_source_rc')): self.global_injections.inject( full_env_path, source_template % (full_rc_path, full_rc_path)) else: self.global_injections.inject(full_env_path, '') if system.is_osx() and not self.injections.in_noninjected_file(env_path, rc_file): if self.phase is PHASE.INSTALL: self.logger.info("On OSX, login shell are the default, which only source config files")
def inject_environment_config(self): if not self.do_inject_environment_config: return for shell in SHELL_CONFIG: if shell == 'gui': if system.is_debian(): self._inject_config_source(".gui", SHELL_CONFIG['gui']['debian']) else: if (self.global_config.has_option('shell', shell) and lib.is_affirmative( self.global_config.get('shell', shell))): rc_file, rc_path = self._inject_config_source( ".rc", SHELL_CONFIG[shell]['rc']) env_file, env_path = self._inject_config_source( ".env", SHELL_CONFIG[shell]['env']) # If an rc file is sourced by an env file, we should alert the user. if (self.phase is PHASE.INSTALL and self.injections.in_noninjected_file( env_path, rc_file) and self.global_injections.in_noninjected_file( env_path, rc_file)): self.logger.info( "You appear to be sourcing %s from inside %s." % (rc_file, env_file)) self.logger.info( "Please ensure it is wrapped in a #SPRINTER_OVERRIDES block " + "to avoid repetitious operations!") full_rc_path = os.path.expanduser( os.path.join("~", rc_file)) full_env_path = os.path.expanduser( os.path.join("~", env_file)) if lib.is_affirmative( self.global_config.get('global', 'env_source_rc')): self.global_injections.inject( full_env_path, source_template % (full_rc_path, full_rc_path)) else: self.global_injections.inject(full_env_path, '') if system.is_osx( ) and not self.injections.in_noninjected_file( env_path, rc_file): if self.phase is PHASE.INSTALL: self.logger.info( "On OSX, login shell are the default, which only source config files" )
def is_affirmative(self, section, option): """ Return true if the section option combo exists and it is set to a truthy value. """ return self.has_option(section, option) and \ lib.is_affirmative(self.get(section, option))
def test_is_affirmative(self): """ the is_affirmative command should return true if a value is truthy """ assert lib.is_affirmative("yes") assert lib.is_affirmative("t") assert lib.is_affirmative("y") assert lib.is_affirmative("True") assert not lib.is_affirmative("False") assert not lib.is_affirmative("gibberish") assert not lib.is_affirmative("coto") assert not lib.is_affirmative("eslaf")
def __str__(self): """ Return the string value, defaulting to default values """ str_value = '' if self.value is not EMPTY and self.value is not None: str_value = self.value elif self.default is not EMPTY: str_value = self.default if self.in_type == 'file' or self.in_type == 'path': return os.path.expanduser(str_value) elif self.is_bool(): bool_value = None if self.in_type == 'bool' or self.in_type == 'y_n': bool_value = lib.is_affirmative(str_value) elif self.in_type == 'yes_no': bool_value = str_value.lower() == 'yes' out_type = self.in_type if self.out_type is None else self.out_type return bool_to_str[out_type][bool_value] else: return str_value
def is_affirmative(self, param, default=None): return lib.is_affirmative(self.get(param, default=default))