summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Dibb <beandog@gentoo.org>2010-02-03 13:41:17 +0000
committerSteve Dibb <beandog@gentoo.org>2010-02-03 13:41:17 +0000
commitf1077f05773037ea78d2d62c7367cdc3eecd6e09 (patch)
tree889c667d3b84911b9a4724a6d7aee27b377b44c7
parentUse singleton (diff)
downloadznurt-org-backend-f1077f05773037ea78d2d62c7367cdc3eecd6e09.tar.gz
znurt-org-backend-f1077f05773037ea78d2d62c7367cdc3eecd6e09.tar.bz2
znurt-org-backend-f1077f05773037ea78d2d62c7367cdc3eecd6e09.zip
Stop extending PortageTree and use singleton instead
git-svn-id: file:///var/svn/portage@80 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
-rw-r--r--class.portage.category.php11
-rw-r--r--class.portage.ebuild.php5
-rw-r--r--class.portage.license.php9
-rw-r--r--class.portage.package.changelog.php3
-rw-r--r--class.portage.package.mask.php9
-rw-r--r--class.portage.package.php7
-rw-r--r--class.portage.tree.php27
-rw-r--r--class.portage.use_flag.php9
-rw-r--r--header.php14
-rw-r--r--import.all.php8
-rw-r--r--import.arches.php3
-rw-r--r--import.bugzilla.php3
-rw-r--r--import.categories.php3
-rw-r--r--import.ebuild_arch.php4
-rw-r--r--import.ebuild_homepage.php3
-rw-r--r--import.ebuild_license.php3
-rw-r--r--import.ebuild_mask.php3
-rw-r--r--import.ebuild_metadata.php3
-rw-r--r--import.ebuilds.php3
-rw-r--r--import.eclasses.php3
-rw-r--r--import.final.php5
-rw-r--r--import.herds.php3
-rw-r--r--import.licenses.php3
-rw-r--r--import.package_mask.php3
-rw-r--r--import.packages.php3
-rw-r--r--import.use_expand.php3
-rw-r--r--import.use_flags.php3
-rw-r--r--import.use_global.php8
-rw-r--r--import.use_local.php3
-rw-r--r--use.php2
30 files changed, 103 insertions, 66 deletions
diff --git a/class.portage.category.php b/class.portage.category.php
index 7b3ced6..b4f8a96 100644
--- a/class.portage.category.php
+++ b/class.portage.category.php
@@ -1,6 +1,6 @@
<?
- class PortageCategory extends PortageTree {
+ class PortageCategory {
private $name;
protected $dir;
@@ -10,7 +10,8 @@
function __construct($str = null) {
- parent::__construct();
+ global $hits;
+ $hits['category']++;
if($str)
$this->setCategory($str);
@@ -27,9 +28,11 @@
protected function setCategory($str) {
+ $tree =& PortageTree::singleton();
+
$str = basename($str);
- $dir = $this->getTree()."/".$str;
- $this->cache_dir = $this->getTree()."/metadata/cache/".$str;
+ $dir = $tree->getTree()."/".$str;
+ $this->cache_dir = $tree->getTree()."/metadata/cache/".$str;
$this->metadata = $dir."/metadata.xml";
if(is_dir($dir)) {
diff --git a/class.portage.ebuild.php b/class.portage.ebuild.php
index 73391f6..3875f25 100644
--- a/class.portage.ebuild.php
+++ b/class.portage.ebuild.php
@@ -62,6 +62,9 @@
function __construct($str) {
+ global $hits;
+ $hits['ebuild']++;
+
$this->atom = trim($str);
$this->arr_suffix = array('alpha', 'beta', 'rc', 'pre', 'p');
$this->portage = '/usr/portage';
@@ -201,7 +204,7 @@
if(!is_null($this->arr_metadata))
return $this->arr_metadata;
- if(!file_exists($this->filename))
+ if(!file_exists($this->filename) || !file_exists($this->filename_cache))
return array();
$file = file($this->filename_cache, FILE_IGNORE_NEW_LINES);
diff --git a/class.portage.license.php b/class.portage.license.php
index f269181..d983101 100644
--- a/class.portage.license.php
+++ b/class.portage.license.php
@@ -1,13 +1,14 @@
<?
- class PortageLicense extends PortageTree {
+ class PortageLicense {
private $name;
private $pdf;
function __construct($license = null) {
- parent::__construct();
+ global $hits;
+ $hits['license']++;
if($license)
$this->setLicense($license);
@@ -18,7 +19,9 @@
$str = basename($str);
- if(file_exists($this->getTree()."/licenses/$str")) {
+ $tree =& PortageTree::singleton();
+
+ if(file_exists($tree->getTree()."/licenses/$str")) {
if(substr($str, -4, 4) == ".pdf") {
$this->name = basename($str, ".pdf");
diff --git a/class.portage.package.changelog.php b/class.portage.package.changelog.php
index a839fd9..a013c64 100644
--- a/class.portage.package.changelog.php
+++ b/class.portage.package.changelog.php
@@ -7,6 +7,9 @@
function __construct($str, $date = null) {
+ global $hits;
+ $hits['changelog']++;
+
$this->changelog = $str;
if(!is_null($date))
diff --git a/class.portage.package.mask.php b/class.portage.package.mask.php
index c23d570..81dcb8a 100644
--- a/class.portage.package.mask.php
+++ b/class.portage.package.mask.php
@@ -1,13 +1,16 @@
<?
- class PackageMask extends PortageTree {
+ class PackageMask {
private $filename;
private $mtime;
function __construct($profile = 'portage') {
- parent::__construct();
+ global $hits;
+ $hits['package_mask']++;
+
+ $tree =& PortageTree::singleton();
switch($profile) {
@@ -17,7 +20,7 @@
}
- $this->filename = $this->getTree()."/profiles/$filename";
+ $this->filename = $tree->getTree()."/profiles/$filename";
$this->mtime = filemtime($this->filename);
}
diff --git a/class.portage.package.php b/class.portage.package.php
index e2b008d..6c9b240 100644
--- a/class.portage.package.php
+++ b/class.portage.package.php
@@ -16,9 +16,14 @@
private $portage_mtime;
private $changelog_mtime;
private $metadata_mtime;
+
+ private $package_dir;
function __construct($category = null, $package = null) {
+ global $hits;
+ $hits['package']++;
+
parent::__construct();
if($category && $package)
@@ -39,7 +44,7 @@
parent::setCategory($category);
$package = basename($package);
- $dir = $this->dir."/".$package;
+ $this->package_dir = $dir = $this->dir."/".$package;
if(is_dir($dir)) {
$this->name = $package;
diff --git a/class.portage.tree.php b/class.portage.tree.php
index c9ba655..e413990 100644
--- a/class.portage.tree.php
+++ b/class.portage.tree.php
@@ -2,27 +2,42 @@
class PortageTree {
+ private static $instance;
+
// Strings
protected $tree;
// Arrays
protected $arr_licenses;
- function __construct($tree = "/usr/portage") {
+ public function __construct($tree = "/usr/portage") {
+
+ global $hits;
+ $hits['tree']++;
+
if($tree)
$this->setTree($tree);
}
- function getTree() {
+ public static function singleton() {
+ if (!isset(self::$instance)) {
+ $c = __CLASS__;
+ self::$instance = new $c;
+ }
+
+ return self::$instance;
+ }
+
+ public function getTree() {
return $this->tree;
}
- function setTree($x) {
+ public function setTree($x) {
if(is_string($x) && is_dir($x))
$this->tree = $x;
}
- function getArches($prefix = false) {
+ public function getArches($prefix = false) {
$filename = $this->getTree().'/profiles/arch.list';
$arr = file($filename, FILE_IGNORE_NEW_LINES);
@@ -79,7 +94,7 @@
}
- function getLicenses() {
+ public function getLicenses() {
$scandir = scandir($this->getTree().'/licenses/');
$scandir = preg_grep('/^\.{1,2}$/', $scandir, PREG_GREP_INVERT);
@@ -132,7 +147,7 @@
*
* @return array
*/
- function getHerds() {
+ public function getHerds() {
$arr = array();
diff --git a/class.portage.use_flag.php b/class.portage.use_flag.php
index 3572660..6bef4c4 100644
--- a/class.portage.use_flag.php
+++ b/class.portage.use_flag.php
@@ -1,6 +1,6 @@
<?
- class PortageUseFlag extends PortageTree {
+ class PortageUseFlag {
private $name;
private $description;
@@ -11,9 +11,12 @@
function __construct($type = 'global', $name = "") {
- parent::__construct();
+ global $hits;
+ $hits['use_flag']++;
- $dir = $this->getTree()."/profiles/";
+ $tree =& PortageTree::singleton();
+
+ $dir = $tree->getTree()."/profiles/";
switch($type) {
diff --git a/header.php b/header.php
index 0e53d22..b43f114 100644
--- a/header.php
+++ b/header.php
@@ -30,6 +30,13 @@
$mdb2 = "mdb2/alan-one.portage.php";
break;
+
+ case 'dumont':
+
+ $include_path = ":/home/znurt/php/inc:/var/www/znurt.org/htdocs";
+ $mdb2 = "mdb2/dumont.portage.php";
+
+ break;
}
@@ -45,7 +52,7 @@
function importDiff($table, $arr_new, $where = "") {
- global $db;
+ $db =& MDB2::singleton();
if($where)
$where = "WHERE $where";
@@ -60,5 +67,10 @@
return($arr);
}
+
+ // This gets used everywhere, might as well create it here
+ // and check for it later.
+ require_once 'class.portage.tree.php';
+ $tree =& PortageTree::singleton();
?>
diff --git a/import.all.php b/import.all.php
index fd4c397..73b95f8 100644
--- a/import.all.php
+++ b/import.all.php
@@ -2,17 +2,15 @@
require_once 'header.php';
- // This gets used everywhere, might as well create it here
- // and check for it later.
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
-
// Had it choke out on me when starting from scratch
ini_set('memory_limit', -1);
// Always verbose since we are generally running manually from CLI
$verbose = true;
+ // Do some performance analysis
+ $hits = array();
+
// Run with -cron arg to go quietly into the night.
// No code in here to do emerge --sync. Runs separately.
if(in_array("-cron", $argv)) {
diff --git a/import.arches.php b/import.arches.php
index efa09a9..539da81 100644
--- a/import.arches.php
+++ b/import.arches.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
// FIXME This is really dumb, just grab all the arches
diff --git a/import.bugzilla.php b/import.bugzilla.php
index 092f456..febdee9 100644
--- a/import.bugzilla.php
+++ b/import.bugzilla.php
@@ -11,8 +11,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
$import_bugzilla = false;
diff --git a/import.categories.php b/import.categories.php
index 96673da..d4dcd63 100644
--- a/import.categories.php
+++ b/import.categories.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.ebuild_arch.php b/import.ebuild_arch.php
index ab9e77b..797f041 100644
--- a/import.ebuild_arch.php
+++ b/import.ebuild_arch.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
@@ -15,7 +14,6 @@
// $qa = true;
// Get the arches
- $tree = new PortageTree();
$arr_arches = $tree->getArches();
// Find all the ebuilds that are missing ebuild arch
diff --git a/import.ebuild_homepage.php b/import.ebuild_homepage.php
index 6f244db..72a2b93 100644
--- a/import.ebuild_homepage.php
+++ b/import.ebuild_homepage.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.ebuild_license.php b/import.ebuild_license.php
index 22c7b6c..c645638 100644
--- a/import.ebuild_license.php
+++ b/import.ebuild_license.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.ebuild_mask.php b/import.ebuild_mask.php
index 1fda64f..35d3ce5 100644
--- a/import.ebuild_mask.php
+++ b/import.ebuild_mask.php
@@ -12,8 +12,7 @@
require_once 'import.functions.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.ebuild_metadata.php b/import.ebuild_metadata.php
index 23df142..22cd5aa 100644
--- a/import.ebuild_metadata.php
+++ b/import.ebuild_metadata.php
@@ -15,8 +15,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.ebuilds.php b/import.ebuilds.php
index 0eae3a5..9abd8e1 100644
--- a/import.ebuilds.php
+++ b/import.ebuilds.php
@@ -46,8 +46,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.eclasses.php b/import.eclasses.php
index 2c2912d..4911efe 100644
--- a/import.eclasses.php
+++ b/import.eclasses.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
$table = 'eclass';
diff --git a/import.final.php b/import.final.php
index b3eca98..c2cf5da 100644
--- a/import.final.php
+++ b/import.final.php
@@ -76,4 +76,9 @@
$db->query($sql);
}
+ if(!$cron) {
+ shell::msg("Total hits:");
+ print_r($hits);
+ }
+
?> \ No newline at end of file
diff --git a/import.herds.php b/import.herds.php
index dc70ea2..dad000d 100644
--- a/import.herds.php
+++ b/import.herds.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
$table = 'herd';
diff --git a/import.licenses.php b/import.licenses.php
index 0ce22fb..d22f6d5 100644
--- a/import.licenses.php
+++ b/import.licenses.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
$table = 'license';
diff --git a/import.package_mask.php b/import.package_mask.php
index 4d9a2cb..3aafefa 100644
--- a/import.package_mask.php
+++ b/import.package_mask.php
@@ -19,8 +19,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.packages.php b/import.packages.php
index 8bc0ce2..ea555c4 100644
--- a/import.packages.php
+++ b/import.packages.php
@@ -33,8 +33,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.category.php';
diff --git a/import.use_expand.php b/import.use_expand.php
index 7fc18d6..7596313 100644
--- a/import.use_expand.php
+++ b/import.use_expand.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.use_flag.php';
diff --git a/import.use_flags.php b/import.use_flags.php
index bd626f2..4ea0054 100644
--- a/import.use_flags.php
+++ b/import.use_flags.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.use_flag.php';
diff --git a/import.use_global.php b/import.use_global.php
index e192d0c..c51dc2d 100644
--- a/import.use_global.php
+++ b/import.use_global.php
@@ -5,11 +5,13 @@
require_once 'class.portage.use_flag.php';
require_once 'class.portage.ebuild.php';
require_once 'class.portage.atom.php';
- require_once '/home/steve/svn/znurt/class.db.mtime.php';
- require_once '/home/steve/svn/znurt/class.db.use.php';
+ require_once 'class.db.mtime.php';
+ require_once 'class.db.use.php';
require_once 'File/Find.php';
- $tree = new PortageTree();
+ if(!$tree) {
+ $tree =& PortageTree::singleton();
+ }
// Global use flags
$type = 'global';
diff --git a/import.use_local.php b/import.use_local.php
index 00f9f77..9a0a81e 100644
--- a/import.use_local.php
+++ b/import.use_local.php
@@ -3,8 +3,7 @@
require_once 'header.php';
if(!$tree) {
- require_once 'class.portage.tree.php';
- $tree = new PortageTree();
+ $tree =& PortageTree::singleton();
}
require_once 'class.portage.use_flag.php';
diff --git a/use.php b/use.php
index d08fb20..cf425d6 100644
--- a/use.php
+++ b/use.php
@@ -2,7 +2,7 @@
require_once 'class.portage.tree.php';
require_once 'class.portage.use_flag.php';
- require_once '/home/steve/php/inc/class.shell.php';
+ require_once 'class.shell.php';
$u = new PortageUseFlag('local');