def __install_perforce(self, config): """ install perforce binary """ if not system.is_64_bit(): self.logger.warn( "Perforce formula is only designed for 64 bit systems! Not install executables..." ) return False version = config.get('version', 'r13.2') key = 'osx' if system.is_osx() else 'linux' perforce_packages = package_dict[version][key] d = self.directory.install_directory(self.feature_name) if not os.path.exists(d): os.makedirs(d) self.logger.info("Downloading p4 executable...") with open(os.path.join(d, "p4"), 'wb+') as fh: fh.write( lib.cleaned_request('get', url_prefix + perforce_packages['p4']).content) self.directory.symlink_to_bin("p4", os.path.join(d, "p4")) self.p4_command = os.path.join(d, "p4") self.logger.info("Installing p4v...") if system.is_osx(): return self.__install_p4v_osx(url_prefix + perforce_packages['p4v']) else: return self.__install_p4v_linux(url_prefix + perforce_packages['p4v'])
def __get_package_manager(self): """ Installs and verifies package manager """ package_manager = "" args = "" sudo_required = True if system.is_osx(): package_manager = "brew" sudo_required = False args = " install" elif system.is_debian(): package_manager = "apt-get" args = " -y install" elif system.is_fedora(): package_manager = "yum" args = " install" elif system.is_arch(): package_manager = "pacman" args = " --noconfirm -S" if lib.which(package_manager) is None: self.logger.warn( "Package manager %s not installed! Packages will not be installed." % package_manager) self.package_manager = None self.package_manager = package_manager self.sudo_required = sudo_required self.args = args
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 _finalize(self): """ command to run at the end of sprinter's run """ self.logger.info("Finalizing...") self.write_manifest() if self.directory.rewrite_config: # always ensure .rc is written (sourcing .env) self.directory.add_to_rc("") # prepend brew for global installs if system.is_osx() and self.main_manifest.is_affirmative("config", "use_global_packagemanagers"): self.directory.add_to_env('__sprinter_prepend_path "%s" PATH' % "/usr/local/bin") self.directory.add_to_env('__sprinter_prepend_path "%s" PATH' % self.directory.bin_path()) self.directory.add_to_env('__sprinter_prepend_path "%s" LIBRARY_PATH' % self.directory.lib_path()) self.directory.add_to_env('__sprinter_prepend_path "%s" C_INCLUDE_PATH' % self.directory.include_path()) self.injections.commit() self.global_injections.commit() if not os.path.exists(os.path.join(self.root, ".global")): self.logger.debug("Global directory doesn't exist! creating...") os.makedirs(os.path.join(self.root, ".global")) self.logger.debug("Writing shell util file...") with open(self.shell_util_path, "w+") as fh: fh.write(shell_utils_template) if self.error_occured: raise SprinterException("Error occured!") if self.message_success(): self.logger.info(self.message_success()) self.logger.info("NOTE: Please remember to open new shells/terminals to use the modified environment")
def __install(self, config): remove_common_prefix = (config.has('remove_common_prefix') and config.is_affirmative('remove_common_prefix')) destination = config.get( 'target', self.directory.install_directory(self.feature_name)) url_type = config.get('type', config.get('url')) try: if url_type.endswith("tar.gz") or url_type.endswith( "tar.bz2") or url_type.endswith("tar"): lib.extract_targz(config.get('url'), destination, remove_common_prefix=remove_common_prefix) elif config.get('type', config.get('url')).endswith("zip"): lib.extract_zip(config.get('url'), destination, remove_common_prefix=remove_common_prefix) elif config.get('type', config.get('url')).endswith("dmg"): if not system.is_osx(): self.logger.warn( "Non OSX based distributions can not install a dmg!") else: lib.extract_dmg(config.get('url'), destination, remove_common_prefix=remove_common_prefix) except ExtractException: self.logger.warn("Unable to extract file for feature %s" % self.feature_name)
def __get_package_manager(self): """ Installs and verifies package manager """ package_manager = "" args = "" sudo_required = True if system.is_osx(): package_manager = "brew" sudo_required = False args = " install" elif system.is_debian(): package_manager = "apt-get" args = " -y install" elif system.is_fedora(): package_manager = "yum" args = " install" elif system.is_arch(): package_manager = "pacman" args = " --noconfirm -S" if lib.which(package_manager) is None: self.logger.warn("Package manager %s not installed! Packages will not be installed." % package_manager) self.package_manager = None self.package_manager = package_manager self.sudo_required = sudo_required self.args = args
def _system_info(self): """ return info about the system """ manifest = self.target or self.source return { 'version': manifest.get('version'), 'os': 'darwin' if system.is_osx() else 'linux', 'architecture': 'x64' if system.is_64_bit() else 'x86' }
def _configure_env_source_rc(config): """ Configures wether to have .env source .rc """ config.set('global', 'env_source_rc', False) if system.is_osx(): logger.info("On OSX, login shells are default, which only source sprinter's 'env' configuration.") logger.info("I.E. environment variables would be sourced, but not shell functions " + "or terminal status lines.") logger.info("The typical solution to get around this is to source your rc file (.bashrc, .zshrc) " + "from your login shell.") env_source_rc = lib.prompt("would you like sprinter to source the rc file too?", default="yes", boolean=True) config.set('global', 'env_source_rc', env_source_rc)
def __install_perforce(self, config): """ install perforce binary """ if not system.is_64_bit(): self.logger.warn("Perforce formula is only designed for 64 bit systems! Not install executables...") return False version = config.get('version', 'r13.2') key = 'osx' if system.is_osx() else 'linux' perforce_packages = package_dict[version][key] d = self.directory.install_directory(self.feature_name) if not os.path.exists(d): os.makedirs(d) self.logger.info("Downloading p4 executable...") with open(os.path.join(d, "p4"), 'wb+') as fh: fh.write(lib.cleaned_request('get', url_prefix + perforce_packages['p4']).content) self.directory.symlink_to_bin("p4", os.path.join(d, "p4")) self.p4_command = os.path.join(d, "p4") self.logger.info("Installing p4v...") if system.is_osx(): return self.__install_p4v_osx(url_prefix + perforce_packages['p4v']) else: return self.__install_p4v_linux(url_prefix + perforce_packages['p4v'])
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 install_sandboxes(self): if self.target: if system.is_osx(): if not self.target.is_affirmative('config', 'use_global_packagemanagers'): self._install_sandbox('brew', brew.install_brew) elif lib.which('brew') is None: install_brew = lib.prompt( "Looks like you don't have brew, " + "which is sprinter's package manager of choice for OSX.\n" "Would you like sprinter to install brew for you?", default="yes", boolean=True) if install_brew: lib.call("sudo mkdir -p /usr/local/", stdout=None, output_log_level=logging.DEBUG) lib.call("sudo chown -R %s /usr/local/" % getpass.getuser(), output_log_level=logging.DEBUG, stdout=None) brew.install_brew('/usr/local')
def _finalize(self): """ command to run at the end of sprinter's run """ self.logger.info("Finalizing...") self.write_manifest() if self.directory.rewrite_config: # always ensure .rc is written (sourcing .env) self.directory.add_to_rc('') # prepend brew for global installs if system.is_osx() and self.main_manifest.is_affirmative( 'config', 'use_global_packagemanagers'): self.directory.add_to_env('__sprinter_prepend_path "%s" PATH' % '/usr/local/bin') self.directory.add_to_env('__sprinter_prepend_path "%s" PATH' % self.directory.bin_path()) self.directory.add_to_env( '__sprinter_prepend_path "%s" LIBRARY_PATH' % self.directory.lib_path()) self.directory.add_to_env( '__sprinter_prepend_path "%s" C_INCLUDE_PATH' % self.directory.include_path()) self.injections.commit() self.global_injections.commit() if not os.path.exists(os.path.join(self.root, ".global")): self.logger.debug("Global directory doesn't exist! creating...") os.makedirs(os.path.join(self.root, ".global")) self.logger.debug("Writing global config...") self.global_config.write(open(self.global_config_path, 'w+')) self.logger.debug("Writing shell util file...") with open(self.shell_util_path, 'w+') as fh: fh.write(shell_utils_template) if self.error_occured: raise SprinterException("Error occured!") if self.message_success(): self.logger.info(self.message_success()) self.logger.info( "NOTE: Please remember to open new shells/terminals to use the modified environment" )
def __install(self, config): remove_common_prefix = (config.has('remove_common_prefix') and config.is_affirmative('remove_common_prefix')) url_type = config.get('type', config.get('url')) try: if url_type.endswith("tar.gz") or url_type.endswith("tar.bz2") or url_type.endswith("tar"): lib.extract_targz(config.get('url'), self._get_destination(), remove_common_prefix=remove_common_prefix) elif config.get('type', config.get('url')).endswith("zip"): lib.extract_zip(config.get('url'), self._get_destination(), remove_common_prefix=remove_common_prefix) elif config.get('type', config.get('url')).endswith("dmg"): if not system.is_osx(): self.logger.warn("Non OSX based distributions can not install a dmg!") else: lib.extract_dmg(config.get('url'), self._get_destination(), remove_common_prefix=remove_common_prefix) except ExtractException: self.logger.warn("Unable to extract file for feature %s" % self.feature_name)
def install_sandboxes(self): if self.target: if system.is_osx(): if not self.target.is_affirmative( 'config', 'use_global_packagemanagers'): self._install_sandbox('brew', brew.install_brew) elif lib.which('brew') is None: install_brew = lib.prompt( "Looks like you don't have brew, " + "which is sprinter's package manager of choice for OSX.\n" "Would you like sprinter to install brew for you?", default="yes", boolean=True) if install_brew: lib.call("sudo mkdir -p /usr/local/", stdout=None, output_log_level=logging.DEBUG) lib.call("sudo chown -R %s /usr/local/" % getpass.getuser(), output_log_level=logging.DEBUG, stdout=None) brew.install_brew('/usr/local')