diff options
author | Steve Dibb <beandog@gentoo.org> | 2010-02-08 16:43:46 +0000 |
---|---|---|
committer | Steve Dibb <beandog@gentoo.org> | 2010-02-08 16:43:46 +0000 |
commit | 0463f6ae48ad24c32f5252d5f370aec4f36e4cfd (patch) | |
tree | 1900ec5c066c4be29f124e58e1cf871a1f00b6b6 | |
parent | Use new classes (diff) | |
download | znurt-org-backend-0463f6ae48ad24c32f5252d5f370aec4f36e4cfd.tar.gz znurt-org-backend-0463f6ae48ad24c32f5252d5f370aec4f36e4cfd.tar.bz2 znurt-org-backend-0463f6ae48ad24c32f5252d5f370aec4f36e4cfd.zip |
Don't extend PortageCategory anymore
git-svn-id: file:///var/svn/portage@82 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
-rw-r--r-- | class.portage.package.php | 204 |
1 files changed, 147 insertions, 57 deletions
diff --git a/class.portage.package.php b/class.portage.package.php index 6c9b240..ab8a09b 100644 --- a/class.portage.package.php +++ b/class.portage.package.php @@ -1,87 +1,128 @@ <? - class PortagePackage extends PortageCategory { + require_once 'class.portage.tree.php'; + + class PortagePackage { private $name; - private $changelog; + private $category; + private $tree; + private $dir; + private $portage_mtime; + private $arr_ebuilds; private $arr_herds; private $arr_maintainers; - private $changelog_filename; + private $manifest; + private $manifest_filename; + private $manifesh_hash; + private $manifest_mtime; + private $metadata; private $metadata_filename; - private $metadata_xml; - - private $portage_mtime; - private $changelog_mtime; + private $metadata_hash; private $metadata_mtime; + private $metadata_xml; - private $package_dir; - - function __construct($category = null, $package = null) { + function __construct($category = null, $package = null, $tree = "/usr/portage") { global $hits; $hits['package']++; - parent::__construct(); - - if($category && $package) - $this->setPackage($category, $package); + if($category && $package && $tree) + $this->setPackage($category, $package, $tree); } public function __get($var) { - return $this->$var; + + switch($var) { + + case 'category': + case 'dir': + case 'name': + case 'package_dir': + case 'portage_mtime': + case 'tree': + return $this->$var; + break; + + case 'manifest': + return $this->getManifest(); + break; + + case 'manifest_hash': + return $this->getManifestHash(); + break; + + case 'manifest_mtime': + return $this->getManifestMtime(); + break; + + case 'metadata': + return $this->getMetadata(); + break; + + case 'metadata_hash': + return $this->getMetadataHash(); + break; + + case 'metadata_mtime': + return $this->getMetadataMtime(); + break; + + } + } public function __toString() { return $this->name; } - private function setPackage($category, $package) { - - parent::setCategory($category); + private function setPackage($category, $package, $tree) { $package = basename($package); - $this->package_dir = $dir = $this->dir."/".$package; + // Changed the name of package_dir to dir + $this->dir = $this->package_dir = $dir = "$tree/$category/$package"; if(is_dir($dir)) { $this->name = $package; - - $scandir = scandir($dir); - $arr = preg_grep('/\.ebuild$/', $scandir); - $arr = preg_replace("/\.ebuild$/", "", $arr); - - sort($arr); - - $this->arr_ebuilds = $arr; - + $this->category = $category; + $this->tree = $tree; + $this->portage_mtime = filemtime($dir); } - if(file_exists("$dir/ChangeLog")) { - $this->changelog_filename = "$dir/ChangeLog"; - $str = file_get_contents($this->changelog_filename); - $str = trim($str); - $this->changelog = $str; - $this->changelog_mtime = filemtime($this->changelog_filename); + if(file_exists($this->package_dir."/ChangeLog")) { + $this->changelog_filename = $this->package_dir."/ChangeLog"; } - if(file_exists("$dir/metadata.xml")) { - $this->metadata_filename = "$dir/metadata.xml"; - $this->metadata_xml = simplexml_load_file($this->metadata_filename); - $this->metadata_mtime = filemtime($this->metadata_filename); + if(file_exists($this->package_dir."/metadata.xml")) { + $this->metadata_filename = $this->package_dir."/metadata.xml"; + } + + if(file_exists($this->package_dir."/Manifest")) { + $this->manifest_filename = $this->package_dir."/Manifest"; } - $this->portage_mtime = filemtime($dir); - } public function getCategory() { - return parent::getName(); + return $this->category; } public function getEbuilds() { + + if(!$this->arr_ebuilds) { + $scandir = scandir($this->dir); + $arr = preg_grep('/\.ebuild$/', $scandir); + $arr = preg_replace("/\.ebuild$/", "", $arr); + + sort($arr); + + $this->arr_ebuilds = $arr; + } + return $this->arr_ebuilds; } @@ -91,17 +132,15 @@ if(!$this->metadata_filename) return $arr; - - if(!$this->metadata_xml) - $this->metadata_xml = simplexml_load_file($this->metadata_filename); + + $obj =& $this->getMetadataXML(); - if($this->metadata_xml->herd) { - foreach($this->metadata_xml->herd as $name) { + if($obj->herd) { + foreach($obj->herd as $name) { $arr[] = (string)$name; } + sort($arr); } - - sort($arr); return $arr; @@ -114,12 +153,11 @@ if(!$this->metadata_filename) return $arr; - if(!$this->metadata_xml) - $this->metadata_xml = simplexml_load_file($this->metadata_filename); + $obj =& $this->getMetadataXML(); - if($this->metadata_xml->maintainer) { + if($obj->maintainer) { $x = 0; - foreach($this->metadata_xml->maintainer as $maintainer) { + foreach($obj->maintainer as $maintainer) { if($maintainer->name) $arr[$x]['name'] = (string)$maintainer->name; if($maintainer->email) @@ -132,6 +170,59 @@ } + public function getManifest() { + if(!$this->manifest) { + $this->manifest = file_get_contents($this->manifest_filename); + $this->manifest_hash = sha1($this->manifest); + $this->manifest_mtime = filemtime($this->manifest_filename); + } + return $this->manifest; + } + + public function getManifestHash() { + if(!$this->manifest_hash) + $this->getManifest(); + return $this->manifest_hash; + } + + public function getManifestMtime() { + if(!$this->manifest_mtime) + $this->getManifest(); + return $this->manifest_mtime; + } + + public function getMetadata() { + if(is_null($this->metadata)) { + $this->metadata = file_get_contents($this->metadata_filename); + $this->metadata_hash = sha1($this->metadata); + $this->metadata_xml = simplexml_load_string($this->metadata); + $this->metadata_mtime = filemtime($this->metadata_filename); + } + + return $this->metadata; + } + + public function getMetadataHash() { + if(!$this->metadata_hash) + $this->getMetadata(); + return $this->metadata_hash; + } + + public function getMetadataMtime() { + if(!$this->metadata_mtime) + $this->getMetadata(); + return $this->metadata_mtime; + } + + public function getMetadataXML() { + + if(is_null($this->metadata_xml)) + $this->getMetadata(); + + return $this->metadata_xml; + + } + public function getUseFlags() { $arr = array(); @@ -139,13 +230,12 @@ if(!$this->metadata_filename) return $arr; - if(!$this->metadata_xml) - $this->metadata_xml = simplexml_load_file($this->metadata_filename); + $obj =& $this->getMetadataXML(); // Getting attributes is always a pain // http://us.php.net/manual/en/function.simplexml-element-attributes.php - if($this->metadata_xml->use) { - foreach($this->metadata_xml->use->flag as $flag) { + if($obj->use) { + foreach($obj->use->flag as $flag) { foreach($flag->attributes() as $key => $name) { if($key == 'name') { $name = (string)$name; @@ -158,6 +248,6 @@ return $arr; } - + } ?>
\ No newline at end of file |