diff options
author | Steve Dibb <beandog@gentoo.org> | 2010-01-02 19:56:55 +0000 |
---|---|---|
committer | Steve Dibb <beandog@gentoo.org> | 2010-01-02 19:56:55 +0000 |
commit | f83f1aea639b708cef7bad495e557bed5404bdce (patch) | |
tree | dc9af9b03c05d1a4ec784d539b4c65c00806a293 | |
parent | less verbose (diff) | |
download | znurt-org-backend-f83f1aea639b708cef7bad495e557bed5404bdce.tar.gz znurt-org-backend-f83f1aea639b708cef7bad495e557bed5404bdce.tar.bz2 znurt-org-backend-f83f1aea639b708cef7bad495e557bed5404bdce.zip |
only update package masks if package.mask filemtime has changed
git-svn-id: file:///var/svn/portage@46 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
-rw-r--r-- | class.portage.package.mask.php | 7 | ||||
-rw-r--r-- | import.ebuild_mask.php | 242 | ||||
-rw-r--r-- | import.final.php | 19 | ||||
-rw-r--r-- | import.package_mask.php | 75 |
4 files changed, 186 insertions, 157 deletions
diff --git a/class.portage.package.mask.php b/class.portage.package.mask.php index 88936cb..c23d570 100644 --- a/class.portage.package.mask.php +++ b/class.portage.package.mask.php @@ -2,8 +2,8 @@ class PackageMask extends PortageTree { - private $filename; + private $mtime; function __construct($profile = 'portage') { @@ -18,7 +18,12 @@ } $this->filename = $this->getTree()."/profiles/$filename"; + $this->mtime = filemtime($this->filename); + + } + function __get($var) { + return $this->$var; } function getMaskedPackages() { diff --git a/import.ebuild_mask.php b/import.ebuild_mask.php index 3e9373c..9a2ac29 100644 --- a/import.ebuild_mask.php +++ b/import.ebuild_mask.php @@ -1,9 +1,8 @@ <? - $verbose = true; - $debug = true; - $qa = true; - +// $verbose = true; +// $debug = true; +// $qa = true; require_once 'header.php'; require_once 'import.functions.php'; @@ -12,144 +11,152 @@ require_once 'class.portage.package.php'; require_once 'class.portage.ebuild.php'; - $sql = "DELETE FROM ebuild_mask;"; - $db->query($sql); - - if($debug) - $str_status = "0,1"; - else - $str_status = "1"; - - // Insert entries where the entire package is masked - $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE e.status IN($str_status) AND pm.pvr = '' AND lt = FALSE AND gt = FALSE AND eq = FALSE AND ar = FALSE AND av = FALSE;"; - $db->query($sql); - - // Insert entries where it's an exact package and version - $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE e.status IN($str_status) AND pm.pvr = e.pvr AND lt = FALSE AND gt = FALSE AND eq = TRUE AND ar = FALSE AND av = FALSE;"; - $db->query($sql); - - // Insert entries where atom is like: - // =media-video/mplayer-1.0* - // Specifically IGNORE gt and lt - $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE e.status IN($str_status) AND e.pvr LIKE (pm.pvr || '%') AND eq = TRUE AND ar = FALSE AND av = TRUE;"; - $db->query($sql); - - // Insert entries where atom is like: - // ~media-video/mplayer-1.0 - $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE e.status IN($str_status) AND pm.pvr = e.version AND lt = FALSE AND gt = FALSE AND eq = FALSE AND ar = TRUE AND av = FALSE;"; - $db->query($sql); - - // All others - $sql = "SELECT pm.id AS pm_id, pm.package, pm.atom, pm.version AS pm_version, pm.gt, pm.lt, pm.eq, pl.level AS pm_level, e.version AS ebuild_version, el.level AS ebuild_level, e.id AS ebuild FROM package_mask pm INNER JOIN view_pmask_level pl ON pl.id = pm.id INNER JOIN ebuild e ON e.package = pm.package INNER JOIN view_ebuild_level el ON el.id = e.id WHERE e.status IN($str_status) AND pm.gt = TRUE OR pm.lt = TRUE ORDER BY pm.gt, pm.eq, pm.package;"; -// shell::msg($sql); + $sql = "SELECT COUNT(1) FROM package_mask WHERE status = 1;"; + $count = $db->getOne($sql); - $arr = $db->getAll($sql); + if($count) { - foreach($arr as $row) { - - extract($row); - - if(!$arr_pmask[$pm_id]) { - $arr_pmask[$pm_id] = array( - 'atom' => $atom, - 'package' => $package, - 'version' => $pm_version, - 'level' => $pm_level, - 'gt' => $gt, - 'lt' => $lt, - 'eq' => $eq, - ); - - $arr_versions[$pm_id]['mask'] = $pm_version; - - } + // Insert entries where the entire package is masked + $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id, 1 FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE pm.pvr = '' AND lt = FALSE AND gt = FALSE AND eq = FALSE AND ar = FALSE AND av = FALSE;"; + $db->query($sql); -// print_r($arr_pmask); + // Insert entries where it's an exact package and version + $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id, 1 FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE pm.pvr = e.pvr AND lt = FALSE AND gt = FALSE AND eq = TRUE AND ar = FALSE AND av = FALSE;"; + $db->query($sql); - $arr_ebuilds[$pm_id][$ebuild] = array( - 'version' => $ebuild_version, - 'level' => $ebuild_level, - - ); + // Insert entries where atom is like: + // =media-video/mplayer-1.0* + // Specifically IGNORE gt and lt + $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id, 1 FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE e.pvr LIKE (pm.pvr || '%') AND eq = TRUE AND ar = FALSE AND av = TRUE;"; + $db->query($sql); - $arr_versions[$pm_id][$ebuild] = $ebuild_version; - - } - -// print_r($arr_versions); - - foreach($arr_versions as $pm_id => $arr) { - - // Strip out any alpha chars, since we don't need them here - foreach($arr as $key => $value) - $arr[$key] = preg_replace("/[A-Za-z]/", "", $value); + // Insert entries where atom is like: + // ~media-video/mplayer-1.0 + $sql = "INSERT INTO ebuild_mask SELECT pm.id, e.id, 1 FROM ebuild e INNER JOIN package p ON e.package = p.id INNER JOIN package_mask pm ON pm.package = e.package WHERE pm.pvr = e.version AND lt = FALSE AND gt = FALSE AND eq = FALSE AND ar = TRUE AND av = FALSE;"; + $db->query($sql); - $ext = extendVersions($arr); + // All others + $sql = "SELECT pm.id AS pm_id, pm.package, pm.atom, pm.version AS pm_version, pm.gt, pm.lt, pm.eq, pl.level AS pm_level, e.version AS ebuild_version, el.level AS ebuild_level, e.id AS ebuild FROM package_mask pm INNER JOIN view_pmask_level pl ON pl.id = pm.id INNER JOIN ebuild e ON e.package = pm.package INNER JOIN view_ebuild_level el ON el.id = e.id WHERE pm.gt = TRUE OR pm.lt = TRUE ORDER BY pm.gt, pm.eq, pm.package;"; + // shell::msg($sql); - $arr_extended[$pm_id] = $ext; + $arr = $db->getAll($sql); -// print_r($arr); -// print_r($ext); + foreach($arr as $row) { -// die; + extract($row); - } - -// print_r($arr_extended); - - foreach($arr_pmask as $pm_id => $arr) { + if(!$arr_pmask[$pm_id]) { + $arr_pmask[$pm_id] = array( + 'atom' => $atom, + 'package' => $package, + 'version' => $pm_version, + 'level' => $pm_level, + 'gt' => $gt, + 'lt' => $lt, + 'eq' => $eq, + ); + + $arr_versions[$pm_id]['mask'] = $pm_version; + + } + + // print_r($arr_pmask); + + $arr_ebuilds[$pm_id][$ebuild] = array( + 'version' => $ebuild_version, + 'level' => $ebuild_level, + ); + + $arr_versions[$pm_id][$ebuild] = $ebuild_version; - extract($arr); + } - $mask_version = $arr_extended[$pm_id]['mask']; + // print_r($arr_versions); + + foreach($arr_versions as $pm_id => $arr) { - foreach($arr_extended[$pm_id] as $key => $str) { + // Strip out any alpha chars, since we don't need them here + foreach($arr as $key => $value) + $arr[$key] = preg_replace("/[A-Za-z]/", "", $value); + + $ext = extendVersions($arr); + + $arr_extended[$pm_id] = $ext; + + // print_r($arr); + // print_r($ext); + + // die; + + } - // Check against versions - if($key != 'mask' && ( ($gt == 't' && $str > $mask_version) || ($lt == 't' && $str < $mask_version) ) ) { + // print_r($arr_extended); + + foreach($arr_pmask as $pm_id => $arr) { - $arr_ebuild_masks[$pm_id][] = $key; - - $arr_insert = array('package_mask' => $pm_id, 'ebuild' => $key); - - $db->autoExecute('ebuild_mask', $arr_insert, MDB2_AUTOQUERY_INSERT); + extract($arr); - // If its the same version, look closer - } elseif($key != 'mask' && $str == $mask_version) { + $mask_version = $arr_extended[$pm_id]['mask']; - $pm_level = $arr_pmask[$pm_id]['level']; - $ebuild_level = $arr_ebuilds[$pm_id][$key]['level']; - - $pm_ext = $arr_extended[$pm_id][$key]; + foreach($arr_extended[$pm_id] as $key => $str) { + + // Check against versions + if($key != 'mask' && ( ($gt == 't' && $str > $mask_version) || ($lt == 't' && $str < $mask_version) ) ) { - // Check against levels (alpha, beta, etc.) - if( ($gt == 't' && $ebuild_level > $pm_level) || ($lt == 't' && $ebuild_level < $pm_level) ) { - $arr_insert = array('package_mask' => $pm_id, 'ebuild' => $key); + $arr_ebuild_masks[$pm_id][] = $key; + + $arr_insert = array( + 'package_mask' => $pm_id, + 'ebuild' => $key, + 'status' => 1 + ); + $db->autoExecute('ebuild_mask', $arr_insert, MDB2_AUTOQUERY_INSERT); - // If the levels are the same too, then you need to look - // at which one is actually higher / lower - // Actually, I'm not sure if it ever really gets to this point anyway.... currently - // I don't have anything that gets this far. - // I think the queries above for checking level actually grab this already. Not sure. - } elseif($ebuild_level == $pm_level && $eq == 'f' && $pm_ext != $str) { - - shell::msg("race condition! check import.ebuild_mask.php"); + // If its the same version, look closer + } elseif($key != 'mask' && $str == $mask_version) { -// var_dump($ebuild_level); -// var_dump($pm_level); + $pm_level = $arr_pmask[$pm_id]['level']; + $ebuild_level = $arr_ebuilds[$pm_id][$key]['level']; - switch($ebuild_level) { + $pm_ext = $arr_extended[$pm_id][$key]; - case "5": + // Check against levels (alpha, beta, etc.) + if( ($gt == 't' && $ebuild_level > $pm_level) || ($lt == 't' && $ebuild_level < $pm_level) ) { -// var_dump($arr_pmask[$pm_id]['atom']); -// -// var_dump($arr_extended[$pm_id][$key]); -// var_dump($str); -// echo "\n"; + $arr_insert = array( + 'package_mask' => $pm_id, + 'ebuild' => $key, + 'status' => 1, + ); - break; + $db->autoExecute('ebuild_mask', $arr_insert, MDB2_AUTOQUERY_INSERT); + + // If the levels are the same too, then you need to look + // at which one is actually higher / lower + // Actually, I'm not sure if it ever really gets to this point anyway.... currently + // I don't have anything that gets this far. + // I think the queries above for checking level actually grab this already. Not sure. + } elseif($ebuild_level == $pm_level && $eq == 'f' && $pm_ext != $str) { + + shell::msg("race condition! check import.ebuild_mask.php"); + + // var_dump($ebuild_level); + // var_dump($pm_level); + + switch($ebuild_level) { + + case "5": + + // var_dump($arr_pmask[$pm_id]['atom']); + // + // var_dump($arr_extended[$pm_id][$key]); + // var_dump($str); + // echo "\n"; + + break; + + } } @@ -158,7 +165,6 @@ } } - } diff --git a/import.final.php b/import.final.php index 2f06950..a407695 100644 --- a/import.final.php +++ b/import.final.php @@ -1,8 +1,5 @@ <? - $verbose = true; - $qa = true; - require_once 'header.php'; // Reset packages that were updated @@ -40,6 +37,22 @@ $sql = "UPDATE package_recent SET status = 0 WHERE status = 1;"; $db->query($sql); } + + // Check for package_mask replacements + $sql = "SELECT COUNT(1) FROM package_mask WHERE status = 1;"; + $count = $db->getOne($sql); + + if($count) { + // Foreign key will remove any ebuild_mask entries as well + $sql = "DELETE FROM package_mask WHERE status = 0;"; + $db->query($sql); + + $sql = "UPDATE package_mask SET status = 0 WHERE status = 1;"; + $db->query($sql); + + $sql = "UPDATE ebuild_mask SET status = 0 WHERE status = 1;"; + $db->query($sql); + } ?>
\ No newline at end of file diff --git a/import.package_mask.php b/import.package_mask.php index b439b4e..efc4ea9 100644 --- a/import.package_mask.php +++ b/import.package_mask.php @@ -1,7 +1,8 @@ <? - $verbose = true; - $qa = true; +// $verbose = true; +// $debug = true; +// $qa = true; require_once 'header.php'; require_once 'class.portage.tree.php'; @@ -10,54 +11,58 @@ require_once 'class.portage.ebuild.php'; require_once 'class.portage.atom.php'; require_once 'class.portage.package.mask.php'; - + require_once 'class.db.mtime.php'; $pmask = new PackageMask(); - $arr = $pmask->getMaskedPackages(); - - $arr_pg_bool = array('false', 'true'); - // FIXME do an importDiff - $db->query("DELETE FROM package_mask;"); + $dbmtime = new DBMtime($pmask->filename); - function null2str($var) { + $import = false; - global $db; + if($debug) + $import = true; - if(is_null($var)) - return 'NULL'; - else - return $db->quote($var); + if(is_null($dbmtime->mtime)) { + $dbmtime->mtime = $pmask->mtime; + $import = true; + } elseif($pmask->mtime > $dbmtime->mtime) { + $dbmtime->mtime = $pmask->mtime; + $import = true; } - foreach($arr as $str) { + if($import) { + + // Delete any previous import attempts + $sql = "DELETE FROM package_mask WHERE status = 1;"; - $a = new PortageAtom($str); + $arr = $pmask->getMaskedPackages(); -// shell::msg("atom: ".$a->atom); -// shell::msg("pn: ".$a->pn); -// shell::msg("pf: ".$a->pf); -// shell::msg("_alpha: ".$a->_alpha); -// shell::msg("_beta: ".$a->_beta); -// shell::msg("_pre: ".$a->_pre); -// shell::msg("_rc: ".$a->_rc); -// shell::msg("_p: ".$a->_p); -// shell::msg("pr: ".$a->pr); -// shell::msg("version: ".$a->version); -// echo "\n"; + $arr_pg_bool = array('false', 'true'); - $pvr = $a->pvr; + function null2str($var) { - if(!$pvr) - $pvr = ''; + global $db; - $sql = "INSERT INTO package_mask (package, atom, lt, gt, eq, ar, av, pf, pv, pr, pvr, alpha, beta, pre, rc, p, version) SELECT p.id, ".$db->quote($str).", ".$arr_pg_bool[intval($a->lt)].", ".$arr_pg_bool[intval($a->gt)].", ".$arr_pg_bool[intval($a->eq)].", ".$arr_pg_bool[intval($a->ar)].", ".$arr_pg_bool[intval($a->av)].", ".null2str($a->pf).", ".null2str($a->pv).", ".null2str($a->pr).", ".null2str($a->pvr).", ".null2str($a->_alpha).", ".null2str($a->_beta).", ".null2str($a->_pre).", ".null2str($a->_rc).", ".null2str($a->_p).", ".null2str($a->version)." FROM category c INNER JOIN package p ON p.category = c.id WHERE c.name = ".$db->quote($a->category)." AND p.name = ".$db->quote($a->pn).";"; -// shell::msg($sql); - $db->query($sql); - -// die; + if(is_null($var)) + return 'NULL'; + else + return $db->quote($var); + } + + foreach($arr as $str) { + $a = new PortageAtom($str); + + $pvr = $a->pvr; + + if(!$pvr) + $pvr = ''; + + $sql = "INSERT INTO package_mask (package, atom, lt, gt, eq, ar, av, pf, pv, pr, pvr, alpha, beta, pre, rc, p, version, status) SELECT p.id, ".$db->quote($str).", ".$arr_pg_bool[intval($a->lt)].", ".$arr_pg_bool[intval($a->gt)].", ".$arr_pg_bool[intval($a->eq)].", ".$arr_pg_bool[intval($a->ar)].", ".$arr_pg_bool[intval($a->av)].", ".null2str($a->pf).", ".null2str($a->pv).", ".null2str($a->pr).", ".null2str($a->pvr).", ".null2str($a->_alpha).", ".null2str($a->_beta).", ".null2str($a->_pre).", ".null2str($a->_rc).", ".null2str($a->_p).", ".null2str($a->version).", 1 FROM category c INNER JOIN package p ON p.category = c.id WHERE c.name = ".$db->quote($a->category)." AND p.name = ".$db->quote($a->pn).";"; + $db->query($sql); + } + } |