def export_revertSoftware(self): """Revert the last installed version of software to the previous one""" oldLink = os.path.join(gComponentInstaller.instancePath, "old") oldPath = os.readlink(oldLink) proLink = os.path.join(gComponentInstaller.instancePath, "pro") os.remove(proLink) mkLink(oldPath, proLink) return S_OK(oldPath)
def export_revertSoftware( self ): """ Revert the last installed version of software to the previous one """ oldLink = os.path.join( gComponentInstaller.instancePath, 'old' ) oldPath = os.readlink( oldLink ) proLink = os.path.join( gComponentInstaller.instancePath, 'pro' ) os.remove( proLink ) mkLink( oldPath, proLink ) return S_OK( oldPath )
def _updateSoftwarePy3(self, version, rootPath_, diracOSVersion): if rootPath_: return S_ERROR( "rootPath argument is not supported for Python 3 installations" ) # Validate and normalise the requested version primaryExtension = None if "==" in version: primaryExtension, version = version.split("==") elif six.PY2: return S_ERROR( "The extension must be specified like DIRAC==vX.Y.Z if installing " "a Python 3 version from an existing Python 2 installation.") try: version = Version(version) except InvalidVersion: self.log.exception("Invalid version passed", version) return S_ERROR("Invalid version passed %r" % version) isPrerelease = version.is_prerelease version = "v%s" % version # Find what to install otherExtensions = [] for extension in extensionsByPriority(): if primaryExtension is None and getExtensionMetadata( extension).get("primary_extension", False): primaryExtension = extension else: otherExtensions.append(extension) self.log.info( "Installing Python 3 based", "%s %s with DIRACOS %s" % (primaryExtension, version, diracOSVersion or "2")) self.log.info("Will also install", repr(otherExtensions)) # Install DIRACOS installer_url = "https://github.com/DIRACGrid/DIRACOS2/releases/" if diracOSVersion: installer_url += "download/%s/latest/download/DIRACOS-Linux-%s.sh" % ( version, platform.machine()) else: installer_url += "latest/download/DIRACOS-Linux-%s.sh" % platform.machine( ) self.log.info("Downloading DIRACOS2 installer from", installer_url) with tempfile.NamedTemporaryFile(suffix=".sh", mode="wb") as installer: with requests.get(installer_url, stream=True) as r: if not r.ok: return S_ERROR("Failed to download %s" % installer_url) for chunk in r.iter_content(chunk_size=1024**2): installer.write(chunk) installer.flush() self.log.info("Downloaded DIRACOS installer to", installer.name) if six.PY2: newProPrefix = os.path.dirname( os.path.realpath(os.path.join(rootPath, "bashrc"))) else: newProPrefix = rootPath newProPrefix = os.path.join( newProPrefix, "versions", "%s-%s" % (version, datetime.utcnow().strftime("%s")), ) installPrefix = os.path.join( newProPrefix, "%s-%s" % (platform.system(), platform.machine())) self.log.info("Running DIRACOS installer for prefix", installPrefix) r = subprocess.run( # pylint: disable=no-member ["bash", installer.name, "-p", installPrefix], stderr=subprocess.PIPE, universal_newlines=True, check=False, timeout=600, ) if r.returncode != 0: stderr = [ x for x in r.stderr.split("\n") if not x.startswith("Extracting : ") ] self.log.error("Installing DIRACOS2 failed with returncode", "%s and stdout: %s" % (r.returncode, stderr)) return S_ERROR("Failed to install DIRACOS2 %s" % stderr) # Install DIRAC cmd = ["%s/bin/pip" % installPrefix, "install", "--no-color", "-v"] if isPrerelease: cmd += ["--pre"] cmd += ["%s[server]==%s" % (primaryExtension, version)] cmd += ["%s[server]" % e for e in otherExtensions] r = subprocess.run( # pylint: disable=no-member cmd, stderr=subprocess.PIPE, universal_newlines=True, check=False, timeout=600, ) if r.returncode != 0: self.log.error("Installing DIRACOS2 failed with returncode", "%s and stdout: %s" % (r.returncode, r.stderr)) return S_ERROR("Failed to install DIRACOS2 with message %s" % r.stderr) # Update the pro link oldLink = os.path.join(gComponentInstaller.instancePath, "old") proLink = os.path.join(gComponentInstaller.instancePath, "pro") if os.path.exists(oldLink): os.remove(oldLink) os.rename(proLink, oldLink) mkLink(newProPrefix, proLink) return S_OK()