def test_can_get_nuget_path(self):
     nuget_cmd = NugetDependency.GetNugetCmd()
     nuget_cmd += ["locals", "global-packages", "-list"]
     ret = RunCmd(nuget_cmd[0],
                  ' '.join(nuget_cmd[1:]),
                  outstream=sys.stdout)
     self.assertEqual(ret, 0)  # make sure we have a zero return code
    def Push(self, nuPackage, apikey):
        if (not os.path.isfile(nuPackage)):
            raise Exception("Invalid file path for NuPkg file")
        logging.debug("Pushing %s file to server %s" %
                      (nuPackage, self.ConfigData["server_url"]))

        cmd = NugetDependency.GetNugetCmd()
        cmd += ["push", nuPackage]
        cmd += ["-Verbosity", "detailed"]
        # cmd += ["-NonInteractive"]
        cmd += ["-Source", self.ConfigData["server_url"]]
        cmd += ["-ApiKey", apikey]
        output_buffer = StringIO()
        ret = RunCmd(cmd[0], " ".join(cmd[1:]), outstream=output_buffer)

        if (ret != 0):
            # Rewind the buffer and capture the contents.
            output_buffer.seek(0)
            output_contents = output_buffer.read()

            # Check for the API message.
            if "API key is invalid".lower() in output_contents.lower():
                logging.critical(
                    "API key is invalid. Please use --ApiKey to provide a valid key."
                )

            # Generic error.
            logging.error("Failed on nuget commend.  RC = 0x%x" % ret)

        return ret
    def Pack(self, version, OutputDirectory, ContentDir, RelNotesText=None):
        self.NewVersion = version

        # content must be absolute path in nuspec otherwise it is assumed
        # relative to nuspec file.
        cdir = os.path.abspath(ContentDir)

        # make nuspec file
        xmlstring = self._MakeNuspecXml(cdir, RelNotesText)
        nuspec = os.path.join(OutputDirectory, self.Name + ".nuspec")
        self.TempFileToDelete.append(nuspec)
        f = open(nuspec, "wb")
        f.write(xmlstring)
        f.close()

        # run nuget
        cmd = NugetDependency.GetNugetCmd()
        cmd += ["pack", nuspec]
        cmd += ["-OutputDirectory", '"' + OutputDirectory + '"']
        cmd += ["-Verbosity", "detailed"]
        # cmd += ["-NonInteractive"]
        ret = RunCmd(cmd[0], " ".join(cmd[1:]))

        if (ret != 0):
            logging.error("Failed on nuget commend.  RC = 0x%x" % ret)
            return ret

        self.NuPackageFile = os.path.join(
            OutputDirectory, self._GetNuPkgFileName(self.NewVersion))
        self.TempFileToDelete.append(self.NuPackageFile)
        return ret
 def _DownloadNugetPackageVersion(self,
                                  package_name: str,
                                  version: str,
                                  destination: os.PathLike,
                                  source=None):
     cmd = NugetDependency.GetNugetCmd()
     cmd += ["install", package_name]
     if source is not None:
         cmd += ["-Source", source]
     cmd += ["-ExcludeVersion"]
     cmd += ["-Version", version]
     cmd += ["-Verbosity", "detailed"]
     cmd += ["-OutputDirectory", '"' + destination + '"']
     ret = RunCmd(cmd[0], " ".join(cmd[1:]))
     if ret != 0:
         return False
     else:
         return True
def _GetLatestNugetVersion(package_name, source=None):
    cmd = NugetDependency.GetNugetCmd()
    cmd += ["list"]
    cmd += [package_name]
    if source is not None:
        cmd += ["-Source", source]
    return_buffer = StringIO()
    if (RunCmd(cmd[0], " ".join(cmd[1:]), outstream=return_buffer) == 0):
        # Seek to the beginning of the output buffer and capture the output.
        return_buffer.seek(0)
        return_string = return_buffer.readlines()
        return_buffer.close()
        for line in return_string:
            line = line.strip()
            if line.startswith(package_name):
                return line.replace(package_name, "").strip()
    else:
        return "0.0.0.0"