summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Dibb <beandog@gentoo.org>2009-12-15 20:44:20 +0000
committerSteve Dibb <beandog@gentoo.org>2009-12-15 20:44:20 +0000
commit09088aa9aee870ff3e9dc490683976d224a68b4b (patch)
tree99637a9cd8193a2c937a3efd0e09d6726055916a
downloadznurt-org-backend-09088aa9aee870ff3e9dc490683976d224a68b4b.tar.gz
znurt-org-backend-09088aa9aee870ff3e9dc490683976d224a68b4b.tar.bz2
znurt-org-backend-09088aa9aee870ff3e9dc490683976d224a68b4b.zip
initial commit
git-svn-id: file:///var/svn/portage@1 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
-rw-r--r--atom.php64
-rw-r--r--header.php29
-rw-r--r--import.all.php43
-rw-r--r--import.arches.php29
-rw-r--r--import.categories.php28
-rw-r--r--import.ebuild_arch.php99
-rw-r--r--import.ebuild_ev.php51
-rw-r--r--import.ebuild_homepage.php67
-rw-r--r--import.ebuild_license.php78
-rw-r--r--import.ebuild_mask.php163
-rw-r--r--import.ebuild_metadata.php53
-rw-r--r--import.ebuilds.php234
-rw-r--r--import.eclasses.php29
-rw-r--r--import.final.php18
-rw-r--r--import.functions.php78
-rw-r--r--import.herds.php27
-rw-r--r--import.licenses.php30
-rw-r--r--import.package_mask.php66
-rw-r--r--import.packages.php41
-rw-r--r--import.use_flags.php27
20 files changed, 1254 insertions, 0 deletions
diff --git a/atom.php b/atom.php
new file mode 100644
index 0000000..0ed8f12
--- /dev/null
+++ b/atom.php
@@ -0,0 +1,64 @@
+<?
+
+ // Testing parsing atoms
+
+ require_once '../class.portage.ebuild.php';
+ require_once '../class.portage.atom.php';
+ require_once '../class.shell.php';
+
+ $str = 'x11-misc/seyon';
+ $str ='x11-libs/gtk-canvas';
+
+ $e = new PortageEbuild($str);
+
+
+ shell::msg("atom: ".$e->atom);
+ shell::msg("pn: ".$e->pn);
+ shell::msg("pf: ".$e->pf);
+ shell::msg("_alpha: ".$e->_alpha);
+ shell::msg("_beta: ".$e->_beta);
+ shell::msg("_pre: ".$e->_pre);
+ shell::msg("_rc: ".$e->_rc);
+ shell::msg("_p: ".$e->_p);
+ shell::msg("pr: ".$e->pr);
+ shell::msg("version: ".$e->version);
+
+// shell::msg($e->getSuffix("_p"));
+//
+// shell::msg("mtime: ".$e->mtime);
+
+ #print_r($e->metadata());
+
+
+// var_dump($e->_alpha);
+// var_dump($e->_beta);
+
+// $e->getSuffix('_beta');
+
+
+// var_dump($e->version);
+// var_dump($e->_alpha);
+// var_dump($e->_beta);
+
+ $e->getComponents();
+
+// var_dump($e->arr_components);
+
+// var_dump($e->getPackageVersionMinusRevision());
+
+
+ shell::msg("Class Atom");
+ $a = new PortageAtom($str);
+
+// shell::msg("atom: ".$a->atom);
+ shell::msg("pn: ".$a->getPackageName());
+ 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);
+
+?>
diff --git a/header.php b/header.php
new file mode 100644
index 0000000..452147b
--- /dev/null
+++ b/header.php
@@ -0,0 +1,29 @@
+<?
+
+ ini_set('include_path', ini_get('include_path').":/home/steve/php/inc");
+
+ require_once "mdb2/charlie.portage.php";
+ require_once 'class.common.php';
+ require_once 'class.shell.php';
+
+ $c = new Common();
+
+ function importDiff($table, $arr_new, $where = "") {
+
+ global $db;
+
+ if($where)
+ $where = "WHERE $where";
+
+ $sql = "SELECT name FROM $table $where ORDER BY name;";
+ $arr_old = $db->getCol($sql);
+
+ $arr_insert = array_diff($arr_new, $arr_old);
+ $arr_delete = array_diff($arr_old, $arr_new);
+
+ $arr = array('insert' => $arr_insert, 'delete' => $arr_delete);
+
+ return($arr);
+ }
+
+?>
diff --git a/import.all.php b/import.all.php
new file mode 100644
index 0000000..337c6cc
--- /dev/null
+++ b/import.all.php
@@ -0,0 +1,43 @@
+<?
+
+ ini_set('memory_limit', -1);
+
+ $verbose = true;
+
+ $base = true;
+ $packages = true;
+ $ebuilds = true;
+ $metadata = true;
+
+ $arr_import['base'] = array('arches', 'eclasses', 'herds', 'licenses', 'use_flags');
+ $arr_import['packages'] = array('categories', 'packages');
+ $arr_import['ebuilds'] = array('ebuilds');
+ $arr_import['metadata'] = array('ebuild_metadata', 'ebuild_arch', 'ebuild_homepage', 'ebuild_license', 'package_mask', 'ebuild_mask', 'ebuild_ev');
+ $arr_import['final'] = array('final');
+
+
+ foreach($arr_import as $key => $arr) {
+ if($$key) {
+ foreach($arr as $file) {
+// if($verbose)
+ echo "[import] $file\n";
+ include "import.$file.php";
+ }
+ }
+ }
+
+ function memory_usage() {
+ $mem_usage = memory_get_usage(true);
+
+ if ($mem_usage < 1024)
+ $str = $mem_usage."b";
+ else
+ $str = round($mem_usage/1024,2)."kb";
+// else
+// $str = round($mem_usage/1048576,2)." megabytes";
+
+ return $str;
+ }
+
+
+?> \ No newline at end of file
diff --git a/import.arches.php b/import.arches.php
new file mode 100644
index 0000000..7ef209b
--- /dev/null
+++ b/import.arches.php
@@ -0,0 +1,29 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+
+ $tree = new PortageTree();
+
+ $arr_arches = $tree->getArches();
+
+ $arr = importDiff('arch', $arr_arches);
+
+ if(count($arr['delete'])) {
+ foreach($arr['delete'] as $name) {
+ $sql = "DELETE FROM arch WHERE name = ".$db->quote($name).";";
+ shell::msg($sql);
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr['insert'])) {
+ foreach($arr['insert'] as $name) {
+ $arr_insert = array('name' => $name);
+ $db->autoExecute('arch', $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+ unset($arr);
+
+?> \ No newline at end of file
diff --git a/import.categories.php b/import.categories.php
new file mode 100644
index 0000000..a0fd341
--- /dev/null
+++ b/import.categories.php
@@ -0,0 +1,28 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+
+ $tree = new PortageTree();
+ $table = 'category';
+
+ $arr = $tree->getCategories();
+
+ $arr_diff = importDiff($table, $arr);
+
+ if(count($arr_diff['delete'])) {
+ foreach($arr_diff['delete'] as $name) {
+ $sql = "DELETE FROM $table WHERE name = ".$db->quote($name).";";
+ shell::msg($sql);
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr_diff['insert'])) {
+ foreach($arr_diff['insert'] as $name) {
+ $arr_insert = array('name' => $name);
+ $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+?> \ No newline at end of file
diff --git a/import.ebuild_arch.php b/import.ebuild_arch.php
new file mode 100644
index 0000000..4380d80
--- /dev/null
+++ b/import.ebuild_arch.php
@@ -0,0 +1,99 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+
+ // Get the arches
+ $tree = new PortageTree();
+ $arr_arches = $tree->getArches();
+
+ // Find all the ebuilds that are missing ebuild arch
+ $sql = "SELECT id, metadata FROM missing_arch;";
+ $arr = $db->getAssoc($sql);
+
+ if($verbose)
+ shell::msg(count($arr)." ebuilds to check");
+
+ // Get the arches from the database
+ $db_arches = $db->getAssoc("SELECT name, id FROM arch;");
+
+ foreach($arr as $ebuild_id => $keywords) {
+
+ if(!empty($keywords))
+ $arr = arrKeywords($keywords, $arr_arches);
+ else {
+ $arr = array();
+ }
+
+ if(count($arr)) {
+ foreach($arr as $arch => $status) {
+
+ if($db_arches[$arch]) {
+ $arr_insert = array(
+ 'ebuild' => $ebuild_id,
+ 'arch' => $db_arches[$arch],
+ 'status' => $status,
+ );
+
+ $db->autoExecute('ebuild_arch', $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+ }
+
+
+ }
+
+ /**
+ * Create an array of the arch keywords
+ *
+ * @param string keywords
+ * @return array
+ */
+ function arrKeywords($str, $arches) {
+
+ $arr = explode(' ', $str);
+
+ $arr_keywords = array();
+
+ if(count($arr)) {
+
+ // If it has -* at all, set them all to -arch by default
+ if(in_array('-*', $arr)) {
+ foreach($arches as $name) {
+ $arr_keywords[$name] = 2;
+ }
+ }
+
+ foreach($arr as $name) {
+ if($name[0] == '~' || $name[0] == '-')
+ $arch = substr($name, 1);
+ else
+ $arch = $name;
+
+ if($name[0] == '~') {
+ $arr_keywords[$arch] = 1;
+ }
+ elseif($name[0] == '-') {
+ $arr_keywords[$arch] = 2;
+ }
+ else {
+ $arr_keywords[$arch] = 0;
+ }
+ }
+ }
+
+ ksort($arr_keywords);
+
+ return $arr_keywords;
+ }
+
+
+
+?> \ No newline at end of file
diff --git a/import.ebuild_ev.php b/import.ebuild_ev.php
new file mode 100644
index 0000000..d2e67e9
--- /dev/null
+++ b/import.ebuild_ev.php
@@ -0,0 +1,51 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+
+ require_once 'header.php';
+ require_once 'import.functions.php';
+
+ // Also fix the levels
+ $sql = "UPDATE ebuild e SET lvl = CASE
+ WHEN e.p IS NOT NULL THEN 6
+ WHEN e.rc IS NOT NULL THEN 4
+ WHEN e.pre IS NOT NULL THEN 3
+ WHEN e.beta IS NOT NULL THEN 2
+ WHEN e.alpha IS NOT NULL THEN 1
+ ELSE 5
+ END;";
+ $db->query($sql);
+
+ $sql = "SELECT * FROM missing_ev;";
+ $arr = $db->getAll($sql);
+
+ $arr_packages = array();
+
+ foreach($arr as $row) {
+ extract($row);
+ $arr_packages[$package][$ebuild] = $version;
+
+ }
+
+ foreach($arr_packages as $package => $arr) {
+
+// print_r($arr);
+
+ $ext = extendVersions($arr);
+
+// print_r($ext); die;
+
+ foreach($ext as $ebuild => $ev) {
+ $arr_update = array('ev' => $ev);
+ $db->autoExecute('ebuild', $arr_update, MDB2_AUTOQUERY_UPDATE, "id = $ebuild");
+ }
+
+ }
+
+// print_r($arr_packages);
+
+
+
+?> \ No newline at end of file
diff --git a/import.ebuild_homepage.php b/import.ebuild_homepage.php
new file mode 100644
index 0000000..fad0537
--- /dev/null
+++ b/import.ebuild_homepage.php
@@ -0,0 +1,67 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+
+ // Find all the ebuilds that are missing ebuild arch
+ $sql = "SELECT id, metadata FROM missing_homepage;";
+ $arr = $db->getAssoc($sql);
+
+ if($verbose)
+ shell::msg(count($arr)." ebuilds to check");
+
+ foreach($arr as $ebuild_id => $homepages) {
+
+ if(!empty($homepages))
+ $arr = arrHomepages($homepages);
+ else {
+ $arr = array();
+ }
+
+ if(count($arr)) {
+ foreach($arr as $homepage) {
+
+ $arr_insert = array(
+ 'ebuild' => $ebuild_id,
+ 'homepage' => $homepage,
+ );
+
+ $db->autoExecute('ebuild_homepage', $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+
+ }
+
+ /**
+ * Create an array of the arch keywords
+ *
+ * @param string keywords
+ * @return array
+ */
+ function arrHomepages($str) {
+
+ $arr = explode(' ', $str);
+
+ $arr_keywords = array();
+
+ if(count($arr)) {
+
+ foreach($arr as $str) {
+ if(substr($str, 0, 4) == "http" || substr($str, 0, 6) == "ftp://" || substr($str, 0, 9) == "gopher://")
+ $arr_homepages[] = $str;
+ }
+ }
+
+ return $arr_homepages;
+ }
+
+
+?> \ No newline at end of file
diff --git a/import.ebuild_license.php b/import.ebuild_license.php
new file mode 100644
index 0000000..c214ccf
--- /dev/null
+++ b/import.ebuild_license.php
@@ -0,0 +1,78 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+
+ // Get the arches
+ $tree = new PortageTree();
+ $arr_licenses = $tree->getLicenses();
+
+ // Find all the ebuilds that are missing ebuild arch
+ $sql = "SELECT id, metadata FROM missing_license;";
+ $arr = $db->getAssoc($sql);
+
+ if($verbose)
+ shell::msg(count($arr)." ebuilds to check");
+
+ // Get the licenses from the database
+ $db_licenses = $db->getAssoc("SELECT name, id FROM license;");
+
+ foreach($arr as $ebuild_id => $str) {
+
+ if(!empty($str)) {
+ $arr = arrLicenses($str, $arr_licenses);
+ } else {
+ $arr = array();
+ }
+
+ if(count($arr)) {
+ foreach($arr as $str) {
+ if($db_licenses[$str]) {
+ $arr_insert = array(
+ 'ebuild' => $ebuild_id,
+ 'license' => $db_licenses[$str],
+ );
+
+ $db->autoExecute('ebuild_license', $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+ }
+
+
+ }
+
+ /**
+ * Create an array of the ebuild's licenses
+ *
+ * @param string licenses
+ * @return array
+ */
+ function arrLicenses($str, $licenses) {
+
+ $arr = explode(' ', $str);
+
+ $arr_licenses = array();
+
+ if(count($arr)) {
+
+ foreach($arr as $str) {
+ if(in_array($str, $licenses))
+ $arr_licenses[] = $str;
+ }
+
+ $arr_licenses = array_unique($arr_licenses);
+
+ }
+
+ return $arr_licenses;
+ }
+
+
+?> \ No newline at end of file
diff --git a/import.ebuild_mask.php b/import.ebuild_mask.php
new file mode 100644
index 0000000..d54bb87
--- /dev/null
+++ b/import.ebuild_mask.php
@@ -0,0 +1,163 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+
+ require_once 'header.php';
+ require_once 'import.functions.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+
+ $sql = "DELETE FROM ebuild_mask;";
+ $db->query($sql);
+
+ // Delete the old masks
+// $sql = "DELETE FROM ebuild_mask;";
+// $db->query($sql);
+
+ // 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 = 2 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 = 2 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 = 2 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 = 2 AND pm.pvr = e.version AND lt = FALSE AND gt = FALSE AND eq = FALSE AND ar = TRUE AND av = FALSE;";
+ $db->query($sql);
+
+
+ $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 = 2 AND pm.gt = TRUE OR pm.lt = TRUE ORDER BY pm.gt, pm.eq, pm.package;";
+// shell::msg($sql);
+
+ $arr = $db->getAll($sql);
+
+ 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;
+
+ }
+
+// print_r($arr_pmask);
+
+ $arr_ebuilds[$pm_id][$ebuild] = array(
+ 'version' => $ebuild_version,
+ 'level' => $ebuild_level,
+
+ );
+
+ $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);
+
+ $ext = extendVersions($arr);
+
+ $arr_extended[$pm_id] = $ext;
+
+// print_r($arr);
+// print_r($ext);
+
+// die;
+
+ }
+
+// print_r($arr_extended);
+
+ foreach($arr_pmask as $pm_id => $arr) {
+
+ extract($arr);
+
+ $mask_version = $arr_extended[$pm_id]['mask'];
+
+ foreach($arr_extended[$pm_id] as $key => $str) {
+
+ // Check against versions
+ if($key != 'mask' && ( ($gt == 't' && $str > $mask_version) || ($lt == 't' && $str < $mask_version) ) ) {
+
+ $arr_ebuild_masks[$pm_id][] = $key;
+
+ $arr_insert = array('package_mask' => $pm_id, 'ebuild' => $key);
+
+ $db->autoExecute('ebuild_mask', $arr_insert, MDB2_AUTOQUERY_INSERT);
+
+ // If its the same version, look closer
+ } elseif($key != 'mask' && $str == $mask_version) {
+
+ $pm_level = $arr_pmask[$pm_id]['level'];
+ $ebuild_level = $arr_ebuilds[$pm_id][$key]['level'];
+
+ $pm_ext = $arr_extended[$pm_id][$key];
+
+ // 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);
+ $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;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+
+?> \ No newline at end of file
diff --git a/import.ebuild_metadata.php b/import.ebuild_metadata.php
new file mode 100644
index 0000000..7192995
--- /dev/null
+++ b/import.ebuild_metadata.php
@@ -0,0 +1,53 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+// $debug = true;
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+
+ // Find all the ebuilds that are missing ebuild arch
+ $sql = "SELECT * FROM missing_metadata;";
+ $arr = $db->getAssoc($sql);
+
+ if($verbose)
+ shell::msg(number_format(count($arr))." ebuilds to check");
+
+ foreach($arr as $ebuild_id => $row) {
+ extract($row);
+
+ $obj_ebuild = new PortageEbuild("$category/$pf");
+
+ if($debug)
+ shell::msg("[$category/".$obj_ebuild->pn."]");
+
+ $arr_metadata = $obj_ebuild->metadata();
+
+ if(count($arr_metadata)) {
+
+ foreach($arr_metadata as $keyword => $value) {
+
+ if(!empty($value)) {
+ $arr_insert = array(
+ 'ebuild' => $ebuild_id,
+ 'keyword' => $keyword,
+ 'value' => $value,
+ );
+
+ $db->autoExecute('ebuild_metadata', $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+ } else {
+ if($verbose || $qa)
+ shell::msg("[QA] No metadata: $category/".$obj_ebuild->pf);
+ }
+
+
+ }
+
+?> \ No newline at end of file
diff --git a/import.ebuilds.php b/import.ebuilds.php
new file mode 100644
index 0000000..3fa6978
--- /dev/null
+++ b/import.ebuilds.php
@@ -0,0 +1,234 @@
+<?
+
+ /**
+ * Right now this will run fine is run as a cron job. It will clean up after itself
+ * if there are NO ebuilds in the tree, but if you accidentally remove an entire package
+ * or something, it will still only insert what's new (recently modified since last mtime).
+ * For now, you're going to have to manually flip some bits to get it to correct mistakes
+ * like that. It's too much of a pain to have it check for it (at this point).
+ */
+
+ $verbose = false;
+ $debug = false;
+ $all = false;
+
+ if($debug) {
+ $all = $verbose = true;
+ }
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+
+ // Delete any that were previously getting inserted or deleted
+ $sql = "DELETE FROM ebuild WHERE status > 0;";
+ $db->query($sql);
+
+ // Check to see if there are any ebuilds
+ $sql = "SELECT COUNT(1) FROM ebuild WHERE status = 0;";
+ $count = $db->getOne($sql);
+
+ // If there aren't any, then import *all* packages
+ if(!$count)
+ $all = true;
+ else {
+
+ // If there are, get the last modified time
+ $sql = "SELECT MAX(mtime) FROM ebuild WHERE status = 0;";
+ $mtime = $db->getOne($sql);
+
+ if(is_null($mtime))
+ $all = true;
+ else {
+ $x = time() - $mtime;
+ $x = $x / 60;
+ $mmin = intval($x) + 1;
+ }
+
+ }
+
+ $tree = new PortageTree();
+ $categories = $tree->getCategories();
+ $arr_import = array();
+
+ // Find all the ebuilds that are currently in the db
+ // FIXME rewrite to exclude update/delete statuses?
+ $arr = $arr_db = array();
+ if(!$all) {
+ // Find all the packages that have been updated in the last 24 hours
+ // Need to check the packages themselves, because something may have
+ // been deleted.
+ $cache = $tree->getTree()."/metadata/cache/";
+
+ $exec = "find $cache -type f -mmin -$mmin";
+ $arr = shell::cmd($exec);
+
+ if($verbose) {
+ shell::msg($exec);
+ shell::msg("(".count($arr).") new/updated ebuilds found since last sync.");
+ }
+
+ foreach($arr as $dir) {
+ $atom = str_replace($tree->getTree()."/metadata/cache/", "", $dir);
+ $e = new PortageEbuild($atom);
+
+ $arr_import[$e->category][] = $e->pn;
+ $arr_import[$e->category] = array_unique($arr_import[$e->category]);
+ }
+
+ ksort($arr_import);
+
+ } elseif($all) {
+
+ foreach($categories as $name) {
+ $c = new PortageCategory($name);
+ $arr_import[$name] = $c->getPackages();
+ }
+
+ }
+
+ if($debug || $all) {
+ shell::msg("Checking ALL categories");
+ } elseif($verbose) {
+ shell::msg("(".count($arr_import).") RECENTLY MODIFIED categories ");
+ }
+
+ // Get the package IDs for reference
+ // and the mtimes of the ebuilds for verification
+ $sql = "SELECT p.id AS package_id, c.name AS category_name, p.name AS package_name, e.pf AS ebuild_name, e.mtime FROM ebuild e RIGHT OUTER JOIN package p ON e.package = p.id INNER JOIN category c ON p.category = c.id ORDER BY c.name, p.name;";
+ $arr = $db->getAll($sql);
+ if(count($arr)) {
+ foreach($arr as $row) {
+ extract($row);
+ $arr_db[$category_name][$package_name] = $package_id;
+ if($ebuild_name)
+ $arr_mtime[$category_name][$package_name][$ebuild_name] = $mtime;
+ }
+ }
+
+
+ if(count($arr_import)) {
+ foreach($arr_import as $category_name => $arr_category) {
+
+ foreach($arr_category as $package_name) {
+
+ if($verbose)
+ shell::msg("[$category_name/$package_name]");
+
+ $arr_insert = array();
+ $arr_delete = array();
+
+ if(count($arr_mtime[$category_name][$package_name]))
+ $arr_old = array_keys($arr_mtime[$category_name][$package_name]);
+ else
+ $arr_old = array();
+
+ $obj_package = new PortagePackage($category_name, $package_name);
+
+ $package_id =& $arr_db[$category_name][$package_name];
+
+ // If there are any old ebuilds (in the DB), then compare the new (in portage)
+ if(count($arr_old)) {
+
+ $arr_new = $obj_package->getEbuilds();
+
+ if(count($arr_new)) {
+ $arr_delete = array_diff($arr_old, $arr_new);
+ $arr_insert = array_diff($arr_new, $arr_old);
+ }
+
+ // Next, look at the mtimes and see if any need to be updated
+ if(count($arr_new)) {
+
+ foreach($arr_new as $ebuild_name) {
+
+ $obj_ebuild = new PortageEbuild("$category_name/$ebuild_name");
+
+ if($obj_ebuild->mtime != $arr_mtime[$category_name][$package_name][$ebuild_name]) {
+
+ if($verbose)
+ shell::msg("[update] $category_name/$ebuild_name");
+
+ $arr_delete[] = $ebuild_name;
+ $arr_insert[] = $ebuild_name;
+ }
+ }
+ }
+
+ if(count($arr_delete)) {
+
+ foreach($arr_delete as $ebuild_name) {
+
+ if($verbose)
+ shell::msg("[delete] $category_name/$ebuild_name");
+
+ $arr_update = array(
+ 'status' => 2,
+ );
+
+ $db->autoExecute('ebuild', $arr_update, MDB2_AUTOQUERY_UPDATE, "package = $package_id AND pf = ".$db->quote($ebuild_name));
+
+ }
+
+ }
+
+ }
+ // Otherwise, insert all of them
+ else {
+ $arr_insert = $obj_package->getEbuilds();
+ }
+
+ if(count($arr_insert)) {
+
+ $arr_insert = array_unique($arr_insert);
+
+ foreach($arr_insert as $ebuild_name) {
+
+ if($verbose)
+ shell::msg("[insert] $category_name/$ebuild_name");
+
+ $obj_ebuild = new PortageEbuild("$category_name/$ebuild_name");
+
+ // print_r($obj_ebuild);
+ // var_dump($obj_ebuild->_beta);
+ // var_dump($obj_ebuild->_pre);
+ // var_dump($obj_ebuild->_rc);
+ // var_dump($obj_ebuild->_p);
+ // var_dump($obj_ebuild->_r);
+ // var_dump($obj_ebuild->slot);
+
+
+
+ $arr = array(
+ 'package' => $package_id,
+ 'pf' => $obj_ebuild->pf,
+ 'pv' => $obj_ebuild->pv,
+ 'pr' => $obj_ebuild->pr,
+ 'pvr' => $obj_ebuild->pvr,
+ 'alpha' => $obj_ebuild->_alpha,
+ 'beta' => $obj_ebuild->_beta,
+ 'pre' => $obj_ebuild->_pre,
+ 'rc' => $obj_ebuild->_rc,
+ 'p' => $obj_ebuild->_p,
+ 'version' => $obj_ebuild->version,
+ 'slot' => $obj_ebuild->slot,
+ 'mtime' => $obj_ebuild->mtime,
+ 'status' => 1,
+ );
+
+ $db->autoExecute('ebuild', $arr, MDB2_AUTOQUERY_INSERT);
+
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+?> \ No newline at end of file
diff --git a/import.eclasses.php b/import.eclasses.php
new file mode 100644
index 0000000..1fbaf34
--- /dev/null
+++ b/import.eclasses.php
@@ -0,0 +1,29 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+
+ $tree = new PortageTree();
+ $table = 'eclass';
+
+ $arr = $tree->getEclasses();
+
+ $arr_diff = importDiff($table, $arr);
+
+ if(count($arr_diff['delete'])) {
+ foreach($arr_diff['delete'] as $name) {
+ $sql = "DELETE FROM $table WHERE name = ".$db->quote($name).";";
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr_diff['insert'])) {
+ foreach($arr_diff['insert'] as $name) {
+ $arr_insert = array('name' => $name);
+ $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+ unset($tree, $arr, $arr_diff);
+
+?> \ No newline at end of file
diff --git a/import.final.php b/import.final.php
new file mode 100644
index 0000000..84ec914
--- /dev/null
+++ b/import.final.php
@@ -0,0 +1,18 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+ require_once 'header.php';
+
+ // Set those that were gonna be updated to be live
+ $sql = "UPDATE ebuild SET status = 0 WHERE status = 1;";
+ $db->query($sql);
+
+ // Delete the ones flagged for removal
+// $sql = "DELETE FROM ebuild WHERE status = 2;";
+// $db->query($sql);
+
+
+
+?> \ No newline at end of file
diff --git a/import.functions.php b/import.functions.php
new file mode 100644
index 0000000..d5407b7
--- /dev/null
+++ b/import.functions.php
@@ -0,0 +1,78 @@
+<?
+
+
+ /**
+ * Create the 'extended version' of the original versions,
+ * which is basically numerical version schemes padded
+ * with zeroes to be able to be sorted numerically.
+ *
+ * @param array indexed array of original versions (pv)
+ * @return array of extended versions with original version as key
+ */
+ function extendVersions($arr) {
+
+ if(!count($arr))
+ return array();
+
+ // Check if we have any dots in versions
+ // If we don't, it's fine as is -- just pad the zeroes
+ if(!(count($arr) && preg_grep('/\./', $arr))) {
+
+ foreach($arr as $value) {
+ $max = max($max, strlen($value));
+ }
+
+ foreach($arr as $key => $value) {
+ $ext[$key] = str_pad($value, $max, 0, STR_PAD_LEFT);
+ }
+
+ return $ext;
+
+ }
+
+ // Keep a count of the max number of version breaks (dots)
+ // array('1.2', '2.12.3') would have a max of 2.
+ $max = 0;
+ foreach($arr as $key => $str) {
+
+ $max = max($max, substr_count($str, '.'));
+ $arr_extended[$key] = explode('.', $str);
+ }
+
+ $max++;
+
+ // Get the max *numerical* lengths for each split
+ // 2.12.3 would create: array(1, 2, 1);
+ foreach($arr_extended as $tmp) {
+ foreach($tmp as $key => $value) {
+ $value = preg_replace('/\D/', '', $value);
+ $arr_max_strlen[$key] = max($arr_max_strlen[$key], strlen($value));
+ }
+ }
+
+ // Now pad everything to the extended version
+ foreach($arr as $key => $value) {
+
+ // Split the version into each of its dot values
+ $explode = explode(".", $value);
+
+ // Pad and/or create the version for each dot version
+ for($x = 0; $x < $max; $x++) {
+
+ // Yes, you *have* to pad the first number too. Otherwise PHP
+ // will compare it wrong if there's more than one decimal point.
+ if($x == 0)
+ $ext[$key] = str_pad($explode[$x], $arr_max_strlen[$x], 0, STR_PAD_LEFT);
+ if($x > 0)
+ $ext[$key] .= ".".str_pad($explode[$x], $arr_max_strlen[$x], 0, STR_PAD_LEFT);
+
+ }
+
+ }
+
+ asort($ext);
+
+ return $ext;
+
+ }
+?> \ No newline at end of file
diff --git a/import.herds.php b/import.herds.php
new file mode 100644
index 0000000..e89be0c
--- /dev/null
+++ b/import.herds.php
@@ -0,0 +1,27 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+
+ $tree = new PortageTree();
+ $table = 'herd';
+
+ $arr = $tree->getHerds();
+
+ $arr_diff = importDiff($table, $arr);
+
+ if(count($arr_diff['delete'])) {
+ foreach($arr_diff['delete'] as $name) {
+ $sql = "DELETE FROM $table WHERE name = ".$db->quote($name).";";
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr_diff['insert'])) {
+ foreach($arr_diff['insert'] as $name) {
+ $arr_insert = array('name' => $name);
+ $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+?> \ No newline at end of file
diff --git a/import.licenses.php b/import.licenses.php
new file mode 100644
index 0000000..dccb612
--- /dev/null
+++ b/import.licenses.php
@@ -0,0 +1,30 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+
+ $tree = new PortageTree();
+ $table = 'license';
+
+ $arr = $tree->getLicenses();
+
+ $arr_diff = importDiff($table, $arr);
+ $arr_diff = null;
+
+ if(count($arr_diff['delete'])) {
+ foreach($arr_diff['delete'] as $name) {
+ $sql = "DELETE FROM $table WHERE name = ".$db->quote($name).";";
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr_diff['insert'])) {
+ foreach($arr_diff['insert'] as $name) {
+ $arr_insert = array('name' => $name);
+ $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+ unset($arr, $arr_diff);
+
+?> \ No newline at end of file
diff --git a/import.package_mask.php b/import.package_mask.php
new file mode 100644
index 0000000..5352bd7
--- /dev/null
+++ b/import.package_mask.php
@@ -0,0 +1,66 @@
+<?
+
+ $verbose = true;
+ $qa = true;
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+ require_once '../class.portage.ebuild.php';
+ require_once '../class.portage.atom.php';
+ require_once '../class.portage.package.mask.php';
+
+
+ $pmask = new PackageMask();
+ $arr = $pmask->getMaskedPackages();
+
+ $arr_pg_bool = array('false', 'true');
+
+ // FIXME do an importDiff
+ $db->query("DELETE FROM package_mask;");
+
+ function null2str($var) {
+
+ global $db;
+
+ if(is_null($var))
+ return 'NULL';
+ else
+ return $db->quote($var);
+ }
+
+ foreach($arr as $str) {
+
+ $a = new PortageAtom($str);
+
+// 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";
+
+ $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) 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;
+
+
+ }
+
+
+
+
+?> \ No newline at end of file
diff --git a/import.packages.php b/import.packages.php
new file mode 100644
index 0000000..f3f08a9
--- /dev/null
+++ b/import.packages.php
@@ -0,0 +1,41 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+ require_once '../class.portage.category.php';
+ require_once '../class.portage.package.php';
+
+ $sql = "SELECT id, name FROM category ORDER BY name;";
+ $arr_categories = $db->getAssoc($sql);
+
+ $table = 'package';
+
+ foreach($arr_categories as $category_id => $category_name) {
+
+ $obj_category = new PortageCategory($category_name);
+
+ $arr_packages = $obj_category->getPackages();
+
+ $arr_diff = importDiff('package', $arr_packages, "category = $category_id");
+
+ if(count($arr_diff['delete'])) {
+ foreach($arr_diff['delete'] as $name) {
+ $sql = "DELETE FROM $table WHERE name = ".$db->quote($name)." AND category = $category_id;";
+ shell::msg($sql);
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr_diff['insert'])) {
+ foreach($arr_diff['insert'] as $name) {
+
+ $obj_package = new PortagePackage($obj_category->name, $name);
+
+ $arr_insert = array('category' => $category_id, 'name' => $name, 'changelog' => $obj_package->changelog);
+ $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+ }
+
+?> \ No newline at end of file
diff --git a/import.use_flags.php b/import.use_flags.php
new file mode 100644
index 0000000..48635dd
--- /dev/null
+++ b/import.use_flags.php
@@ -0,0 +1,27 @@
+<?
+
+ require_once 'header.php';
+ require_once '../class.portage.tree.php';
+
+ $tree = new PortageTree();
+ $table = 'use';
+
+ $arr = $tree->getUseFlags();
+
+ $arr_diff = importDiff($table, $arr);
+
+ if(count($arr_diff['delete'])) {
+ foreach($arr_diff['delete'] as $name) {
+ $sql = "DELETE FROM $table WHERE name = ".$db->quote($name).";";
+ $db->query($sql);
+ }
+ }
+
+ if(count($arr_diff['insert'])) {
+ foreach($arr_diff['insert'] as $name) {
+ $arr_insert = array('name' => $name);
+ $db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
+ }
+ }
+
+?> \ No newline at end of file