public function getInstalledPackageDetails($hostDetails, $packageName)
{
// what are we doing?
$log = usingLog()->startAction("get details for package '{$packageName}' installed in host '{$hostDetails->hostId}'");
// get the details
$command = "sudo yum list installed {$packageName}";
$result = $this->runCommand($hostDetails, $command);
// any luck?
if ($result->didCommandFail()) {
$log->endAction("could not get details ... package not installed?");
return new BaseObject();
}
// study the output
$parts = explode("\n", $result->output);
$parts = FilterForMatchingString::against($parts, $packageName);
$parts = FilterColumns::from($parts, "0-2", ' ');
if (!isset($parts[0])) {
$log->endAction("could not get details ... package not installed?");
return new BaseObject();
}
$parts = explode(' ', $result->output);
if (count($parts) < 3) {
$log->endAction("could not get details ... package not installed?");
return new BaseObject();
}
if (strtolower($parts[0]) == 'error:') {
$log->endAction("could not get details ... package not installed?");
return new BaseObject();
}
// we have some information to return
$return = new BaseObject();
$return->name = $parts[0];
$return->version = $parts[1];
$return->repo = $parts[2];
// all done
$log->endAction();
return $return;
}