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 __install_file(self, config): source = config.get('source') if source.startswith("http"): if config.has('username') and config.has('password'): source_content = self.lib.authenticated_get( config.get('username'), config.get('password'), source).decode("utf-8") else: source_content = lib.cleaned_request('get', source).text else: source_content = open(os.path.expanduser(source)).read() # replace {key} type markers in the template source if config.has('replacement_keys'): replacements = {} for key in config.get('replacement_keys').split(','): key = key.strip() if config.has(key): replacements[key] = config.get(key) try: source_content = string.Formatter().vformat( source_content, (), defaultdict(str, **replacements)) except Exception as e: error_message = "Failed trying to format template! error: {err}".format( err=e.message) if config.is_affirmative('fail_on_error', False): raise e else: self.logger.error(error_message) target_file = os.path.expanduser(config.get('target')) parent_directory = os.path.dirname(target_file) if not os.path.exists(parent_directory): os.makedirs(parent_directory) # backup the template, if it is configured for it and if it has changed if os.path.isfile(target_file) and config.has('backup'): target_content = open(target_file).read() if target_content != source_content: backup_target_base = "{path}.{ext}".format( path=target_file, ext=config.get('backup')) backup_target = backup_target_base i = 1 while os.path.isfile(backup_target): backup_target = "{path}-{i}".format( path=backup_target_base, i=i) i += 1 self.logger.info("Backing up template target to %s..." % backup_target) os.rename(target_file, backup_target) with open(target_file, 'w+') as fh: fh.write(source_content)
def _load_manifest_from_url(manifest, url, verify_certificate=True, username=None, password=None): """ load a url body into a manifest """ try: if username and password: manifest_file_handler = StringIO(lib.authenticated_get(username, password, url, verify=verify_certificate).decode("utf-8")) else: manifest_file_handler = StringIO(lib.cleaned_request('get', url).text) manifest.readfp(manifest_file_handler) except requests.exceptions.RequestException: logger.debug("", exc_info=True) error_message = sys.exc_info()[1] raise ManifestException("There was an error retrieving {0}!\n {1}".format(url, str(error_message)))
def __install_file(self, config): source = config.get('source') if source.startswith("http"): if config.has('username') and config.has('password'): source_content = self.lib.authenticated_get(config.get('username'), config.get('password'), source).decode("utf-8") else: source_content = lib.cleaned_request('get', source).text else: source_content = open(os.path.expanduser(source)).read() # replace {key} type markers in the template source if config.has('replacement_keys'): replacements = {} for key in config.get('replacement_keys').split(','): key = key.strip() if config.has(key): replacements[key] = config.get(key) try: source_content = string.Formatter().vformat( source_content, (), defaultdict(str, **replacements)) except Exception as e: error_message = "Failed trying to format template! error: {err}".format(err=e.message) if config.is_affirmative('fail_on_error', False): raise e else: self.logger.error(error_message) target_file = os.path.expanduser(config.get('target')) parent_directory = os.path.dirname(target_file) if not os.path.exists(parent_directory): os.makedirs(parent_directory) # backup the template, if it is configured for it and if it has changed if os.path.isfile(target_file) and config.has('backup'): target_content = open(target_file).read() if target_content != source_content: backup_target_base = "{path}.{ext}".format(path=target_file, ext=config.get('backup')) backup_target = backup_target_base i = 1 while os.path.isfile(backup_target): backup_target = "{path}-{i}".format(path=backup_target_base, i=i) i += 1 self.logger.info("Backing up template target to %s..." % backup_target) os.rename(target_file, backup_target) with open(target_file, 'w+') as fh: fh.write(source_content)
def __install_file(self, config): source = config.get('source') if source.startswith("http"): if config.has('username') and config.has('password'): source_content = self.lib.authenticated_get( config.get('username'), config.get('password'), source).decode("utf-8") else: source_content = lib.cleaned_request('get', source).text else: source_content = open(os.path.expanduser(source)).read() target_file = os.path.expanduser(config.get('target')) parent_directory = os.path.dirname(target_file) if not os.path.exists(parent_directory): os.makedirs(parent_directory) with open(target_file, 'w+') as fh: fh.write(source_content)
def __install_file(self, config): source = config.get('source') if source.startswith("http"): if config.has('username') and config.has('password'): source_content = self.lib.authenticated_get(config.get('username'), config.get('password'), source).decode("utf-8") else: source_content = lib.cleaned_request('get', source).text else: source_content = open(os.path.expanduser(source)).read() target_file = os.path.expanduser(config.get('target')) parent_directory = os.path.dirname(target_file) if not os.path.exists(parent_directory): os.makedirs(parent_directory) with open(target_file, 'w+') as fh: fh.write(source_content)
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 _load_manifest_from_url(manifest, url, verify_certificate=True, username=None, password=None): """ load a url body into a manifest """ try: if username and password: manifest_file_handler = StringIO( lib.authenticated_get( username, password, url, verify=verify_certificate).decode("utf-8")) else: manifest_file_handler = StringIO( lib.cleaned_request('get', url).text) manifest.readfp(manifest_file_handler) except requests.exceptions.RequestException: logger.debug("", exc_info=True) error_message = sys.exc_info()[1] raise ManifestException( "There was an error retrieving {0}!\n {1}".format( url, str(error_message)))
def __load_manifest(self, raw_manifest, username=None, password=None, verify_certificate=True): manifest = configparser.RawConfigParser() manifest.add_section('config') try: if isinstance(raw_manifest, string_types): if raw_manifest.startswith("http"): # raw_manifest is a url try: if username and password: manifest_file_handler = StringIO(lib.authenticated_get(username, password, raw_manifest, verify=verify_certificate).decode("utf-8")) else: manifest_file_handler = StringIO(lib.cleaned_request('get', raw_manifest).text) manifest.readfp(manifest_file_handler) except requests.exceptions.RequestException: self.logger.debug("", exc_info=True) error_message = sys.exc_info()[1] raise ManifestException("There was an error retrieving {0}!\n {1}".format(raw_manifest, str(error_message))) else: # raw_manifest is a filepath if not os.path.exists(os.path.expanduser(raw_manifest)): raise ManifestException("Manifest does not exist at %s!" % raw_manifest) manifest.read(raw_manifest) if not manifest.has_option('config', 'source'): manifest.set('config', 'source', str(raw_manifest)) elif raw_manifest.__class__ == configparser.RawConfigParser: return raw_manifest else: manifest.readfp(raw_manifest) except configparser.Error: self.logger.debug("", exc_info=True) error_message = sys.exc_info()[1] raise ManifestException("Unable to parse manifest!: {0}".format(error_message)) return manifest
def download_bootstrap(self): """ Install buildout to the path provided """ bootstrap_path = os.path.join(self.root_path, "bootstrap.py") with open(bootstrap_path, 'w+') as fh: fh.write(lib.cleaned_request('get', BOOTSTRAP_URL, verify=False).content)