summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-06 16:08:33 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-06 16:08:33 -0400
commit8142c45b618eaa99f3380c2e0714e95d87e14ee2 (patch)
treeec1461d218b966307dd0239dbf362888ed600b55
parentAdd javascript-based searching to package adding stage (diff)
downloadingenue-8142c45b618eaa99f3380c2e0714e95d87e14ee2.tar.gz
ingenue-8142c45b618eaa99f3380c2e0714e95d87e14ee2.tar.bz2
ingenue-8142c45b618eaa99f3380c2e0714e95d87e14ee2.zip
Stored all data from Packages files in the db to allow frontend/backend separation; created script to update db cache of available packages; renamed profiles -> gentoo_profiles for proper modularity
-rw-r--r--backend/functions/get_pkgdirs.php (renamed from shared/functions/get_pkgdirs.php)0
-rw-r--r--backend/modules/gentoo_catalyst/build.php2
-rw-r--r--backend/modules/gentoo_portage/build.php12
-rw-r--r--frontend/modules/gentoo/step1.php8
-rw-r--r--frontend/modules/gentoo/step2.php4
-rwxr-xr-xpkglist.php4
-rwxr-xr-xsetup.php6
-rw-r--r--shared/classes/0sql_row_obj.php38
-rw-r--r--shared/classes/configopt.php1
-rw-r--r--shared/classes/gentoo_package.php78
-rw-r--r--shared/classes/gentoo_profile.php137
-rw-r--r--shared/classes/profile.php114
-rw-r--r--shared/config.php2
-rw-r--r--todo13
-rwxr-xr-xupdate_gentoo_profiles.php14
15 files changed, 273 insertions, 160 deletions
diff --git a/shared/functions/get_pkgdirs.php b/backend/functions/get_pkgdirs.php
index 1f39420..1f39420 100644
--- a/shared/functions/get_pkgdirs.php
+++ b/backend/functions/get_pkgdirs.php
diff --git a/backend/modules/gentoo_catalyst/build.php b/backend/modules/gentoo_catalyst/build.php
index 45b2b6e..80746b2 100644
--- a/backend/modules/gentoo_catalyst/build.php
+++ b/backend/modules/gentoo_catalyst/build.php
@@ -1,7 +1,7 @@
<?php
function gentoo_catalyst_build(&$build, &$opts, &$W) {
global $conf, $profile;
- $profile=new sql_profile($opts['profile']);
+ $profile=new sql_gentoo_profile($opts['profile']);
$headers=$profile->get_headers();
$arch=explode(' ', $headers['accept_keywords']);
$arch=$arch[0];
diff --git a/backend/modules/gentoo_portage/build.php b/backend/modules/gentoo_portage/build.php
index c2d0be8..aa8e8b5 100644
--- a/backend/modules/gentoo_portage/build.php
+++ b/backend/modules/gentoo_portage/build.php
@@ -2,7 +2,7 @@
// This is the main function that carries out a build from start to finish
function gentoo_portage_build(&$build, &$opts, &$W) {
global $conf;
- $profile=new sql_profile($opts['profile']);
+ $profile=new sql_gentoo_profile($opts['profile']);
$headers=$profile->get_headers();
$I=$W.'/image';
$C=$W.'/config_root';
@@ -52,19 +52,17 @@ function gentoo_portage_build(&$build, &$opts, &$W) {
if ($imgtype == 'tbz2') {
execute_command('Compress finished image to tar/bzip2', "tar -p --same-owner -cjvf '$W/image.tar.bz2' -C '$I' .");
return "$W/image.tar.bz2";
-// rename($W.'/image.tar.bz2', COMPLETED.'/build-'.$build->id.'.tar.bz2') || throw_exception('rename failed');
} elseif ($imgtype == 'tgz') {
execute_command('Compress finished image to tar/gz', "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$I' .");
return "$W/image.tar.gz";
-// rename($W.'/image.tar.gz', COMPLETED.'/build-'.$build->id.'.tar.gz') || throw_exception('rename failed');
} elseif ($imgtype == 'livecd' || $imgtype == 'installcd') {
if (strpos($headers['chost'], 'x86_64') === false)
$minimaliso='/home/eitan/soc/install-x86-minimal-20090623.iso';
else
$minimaliso='/home/eitan/soc/install-amd64-minimal-20090625.iso';
- execute_command_with_env('Mount minimal CD image', "mount -o loop -t iso9660 '$minimaliso' '$W/tmp'", $prtg_cfgrt); // TODO check if env is necessary (and for umount)
+ execute_command('Mount minimal CD image', "mount -o loop -t iso9660 '$minimaliso' '$W/tmp'");
execute_command('Copy CD image to writable temp directory', "cp -va '$W/tmp' '$W/cd'");
- execute_command_with_env('Unmount CD image', "umount '$W/tmp'", $prtg_cfgrt);
+ execute_command('Unmount CD image', "umount '$W/tmp'");
execute_command('Copy kernel and initrd from CD to image', "cp -va '$W/cd/isolinux/gentoo' '$W/cd/isolinux/gentoo.igz' '$I/boot/'");
file_put_contents("$W/unsquashfs-files", "/lib64/modules\n\lib\modules\n");
execute_command('Copy kernel modules from SquashFS to image', "unsquashfs -i -d '$I' -e '$W/unsquashfs-files' '$W/cd/image.squashfs'");
@@ -78,11 +76,9 @@ function gentoo_portage_build(&$build, &$opts, &$W) {
// mkisofs -J -R -l ${mkisofs_zisofs_opts} -V "${clst_iso_volume_id}" -o ${1} -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table ${clst_target_path}
execute_command('Create ISO image', "mkisofs -J -R -l -V 'Ingenue Build $build->id' -o '$W/image.iso' -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table '$W/cd'");
return "$W/image.iso";
-// rename("$W/image.iso", COMPLETED.'/build-'.$build->id.'.iso') || throw_exception('rename failed');
} elseif ($imgtype == 'jffs2') {
execute_command('Create JFFS2 image', "mkfs.jffs2 -x lzo -n -e 0x20000 -l -p -r '$I' -o '$W/image.jffs2'");
return "$W/image.jffs2";
-// rename("$W/image.jffs2", COMPLETED.'/build-'.$build->id.'.jffs2') || throw_exception ('rename failed');
} elseif ($imgtype == 'ext2') {
execute_command('Make blank file for ext2 image', "dd if=/dev/zero of='$W/image.ext2' bs=1024 count=1048576");
execute_command('Make ext2 filesystem', "mke2fs -t ext2 -F '$W/image.ext2'");
@@ -92,10 +88,8 @@ function gentoo_portage_build(&$build, &$opts, &$W) {
execute_command('Unmount ext2 image', "umount '$W/ext2'");
execute_command('Compress ext2 image', "gzip '$W/image.ext2'");
return "$W/image.ext2.gz";
-// rename("$W/image.ext2.gz", COMPLETED.'/build-'.$build->id.'.ext2.gz') || throw_exception('rename failed');
} else {
throw_exception('invalid image type: '.$imgtype);
}
-// return true;
}
?>
diff --git a/frontend/modules/gentoo/step1.php b/frontend/modules/gentoo/step1.php
index aeb0a9e..20899bb 100644
--- a/frontend/modules/gentoo/step1.php
+++ b/frontend/modules/gentoo/step1.php
@@ -6,10 +6,10 @@ function gentoo_body_step1() {
global $S;
$configuration=&$S['wizard.configuration'];
//$opts=$configuration->get_configopts(); // TODO use this to set selected="selected" on the current profile
- echo 'Profile: <select name="pkgdir">';
- $r=$S['pdo']->query('SELECT * FROM `profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled
+ echo 'Profile: <select name="profileid">';
+ $r=$S['pdo']->query('SELECT * FROM `gentoo_profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled
while ($profile=$r->fetch(PDO::FETCH_ASSOC)) {
- $profile=new sql_profile($profile);
+ $profile=new sql_gentoo_profile($profile);
$display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/');
echo '<option value="'.$profile->id.'">'.htmlentities($display).'</option>';
}
@@ -17,7 +17,7 @@ function gentoo_body_step1() {
}
function gentoo_process_step1() {
global $S, $request;
- $profile=new sql_profile($request['pkgdir']);
+ $profile=new sql_gentoo_profile($request['profileid']);
$profileopt=new sql_configopt($S['wizard.configuration']->id, 'profile', $profile->id);
$profileopt->write();
}
diff --git a/frontend/modules/gentoo/step2.php b/frontend/modules/gentoo/step2.php
index e94e978..c800a5d 100644
--- a/frontend/modules/gentoo/step2.php
+++ b/frontend/modules/gentoo/step2.php
@@ -107,7 +107,7 @@ function gentoo_body_step2() {
global $S;
$configuration=&$S['wizard.configuration'];
$opts=$configuration->get_configopts();
- $profile=new sql_profile($opts['profile']);
+ $profile=new sql_gentoo_profile($opts['profile']);
$bcs=$profile->get_packages();
echo 'Search packages: <input id="psearch" onkeyup="packagesearch(this)" /> <a href="javascript:var e=document.getElementById(\'psearch\'); e.value=\'\'; e.onkeyup()">Clear</a>';
echo '<div id="plist"><div id="zero" style="display: none">'.print_error('No results found.').'</div>';
@@ -119,7 +119,7 @@ function gentoo_body_step2() {
foreach ($packages as $name => $vers) {
foreach ($vers as $ver => $attrs) {
$safename=htmlentities("$bc$lc/$name-$ver");
- echo '<div class="pkg'.($attrs['masked']?' masked':'').'"><input id="p'.$i.'" type="checkbox" name="expkgs['.$safename.']" /><label class="pd" for="p'.$i++.'">'.htmlentities("$name-$ver").' - '.htmlentities($attrs['description']).($attrs['masked']?' [MASKED]':'').'</label></div>'."\n";
+ echo '<div class="pkg'.($attrs['masked']?' masked':'').'"><input id="p'.$i.'" type="checkbox" name="expkgs['.$safename.']" /><label class="pd" for="p'.$i++.'">'.htmlentities("$name-$ver").' - '.htmlentities($attrs['desc']).($attrs['masked']?' [MASKED]':'').'</label></div>'."\n";
}
}
echo '</div>'."\n";
diff --git a/pkglist.php b/pkglist.php
index 747a436..cc22686 100755
--- a/pkglist.php
+++ b/pkglist.php
@@ -4,9 +4,9 @@ require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ i
require_once(SHARED.'/config.php');
require_once(SHARED.'/include/dbinit.php');
$pdo=&$S['pdo'];
-$r=$pdo->query('SELECT * FROM `profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':''));
+$r=$pdo->query('SELECT * FROM `gentoo_profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':''));
while ($p=$r->fetch(PDO::FETCH_ASSOC)) {
- $p=new sql_profile($p);
+ $p=new sql_gentoo_profile($p);
echo ($p->name?$p->name:$p->pkgdir)."\n";
$packages=$p->get_packages();
foreach ($packages as $cat => $pkg) {
diff --git a/setup.php b/setup.php
index 0862c09..ad3fd2b 100755
--- a/setup.php
+++ b/setup.php
@@ -27,9 +27,11 @@ foreach (get_declared_classes() as $class) {
}
foreach (get_pkgdirs() as $dir) {
echo 'Creating profile for '.$conf['pkgdir_root'].'/'.$dir.'...';
- $profile=new sql_profile();
+ $profile=new sql_gentoo_profile();
$profile->pkgdir=$dir;
- $profile->write();
+ echo "done\n";
+ echo 'Loading data from '.$conf['pkgdir_root'].'/'.$dir.'/Packages...';
+ $profile->read_Packages();
echo "done\n";
}
do {
diff --git a/shared/classes/0sql_row_obj.php b/shared/classes/0sql_row_obj.php
index 1db8703..62ef90f 100644
--- a/shared/classes/0sql_row_obj.php
+++ b/shared/classes/0sql_row_obj.php
@@ -1,5 +1,6 @@
<?php
// TODO
+// Improve caching to include anything constructed from the DB
// Fall back to multi key if single key didn't work (so unique key can be null)
// consider replacing the one sql_col class with a bunch of child classes for different types (will work well with defaults() when 5.3.0 comes out)
// make sure things really work with enum
@@ -25,14 +26,14 @@
abstract class sql_row_obj { // If the name of this class changes, it must be updated where is_subclass_of() is found
// PDO object to use for queries
protected static $pdo;
- // This line is the static cache so each class is only initialized once per page-load (maybe this should really be once per class edit, saved in a file somewhere...)
- private static $cache=array(), $table_cache=array();
+ // The static cache so each class is only initialized once per page-load (maybe this should really be once per class edit, saved in a file somewhere...)
+ private static $cache=array(), $table_cache=array(), $ref_cache=array();
// These are input by the source class (auto-filled by cache after init)
protected $table, $columns, $primary_key; // TODO $unique_keys
// These are loaded from the static cache
private $auto_increment, $num_key, $misc_key;
// These are run-time variables
- private $db_values=array(), $values, $ref_cache;
+ private $db_values=array(), $values;
// Sets the PDO object to use
public static function set_pdo_obj(&$obj) {
$obj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@@ -72,18 +73,9 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
}
}
private function init_constructors() {
- // Primary key is its own key now, we don't care if others are available
-/* // Sets the primary key as a constructor if it exists
- if (isset($this->primary_key)) {
- $pk=$this->columns[$this->primary_key];
- if ($this->columns[$this->primary_key]->is_numeric()) {
- $this->num_key=$this->primary_key;
- } else {
- $this->misc_key=$this->primary_key;
- }
- }*/
// Fills num and misc constructors with other unique columns
// TODO check where this is called and see if we really need this first check
+ // TODO fix this for multi-column keys - as of now, it's dangerous!
if (!isset($this->num_key) || !isset($this->misc_key)) {
foreach ($this->columns as $name => $col) {
if ($col->unique) {
@@ -474,9 +466,10 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
}
}
// Fetches objects for 'refers to' columns (column given by $name)
- function get($name) {
- if (isset($this->ref_cache[$name])) {
- return $this->ref_cache[$name];
+ function &get($name) {
+ // TODO in 5.3.0, this can be a static variable in each class instead of array[$class]
+ if (isset(self::$ref_cache[get_class($this)][$name][$this->__get($name)])) {
+ return self::$ref_cache[get_class($this)][$name][$this->__get($name)];
}
if (!isset($this->columns[$name])) {
throw new Exception('Tried to fetch object for `'.$name.'` column of '.get_class($this).' object, but that column does not exist.');
@@ -486,7 +479,8 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
throw new Exception('Tried to fetch object for `'.$name.'` column of '.get_class($this).' object, but that column does not refer to another table row.');
}
if (!$this->__isset($name)) {
- return null;
+ $null=null;
+ return $null;
}
list($reftable, $refcol)=explode('.', $col->refers_to, 2); // Should be refclass also
$obj=self::table_to_obj($reftable);
@@ -498,8 +492,8 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
return null;
} elseif ($r->rowCount() == 1) {
$obj->from_array($r->fetch());
- $this->ref_cache[$name]=$obj;
- return $this->ref_cache[$name];
+ self::$ref_cache[get_class($this)][$name][$this->__get($name)]=&$obj;
+ return $obj;
} else {
throw new Exception('Fetching '.$refclass.' object for `'.$name.'` column of `'.$this->table.'` table based on `'.$refcol.'`='.$col->sql_value($this->__get($name)).' and expected one row but got '.$r->rowCount().'.');
}
@@ -508,7 +502,8 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
// TODO this shouldn't have to instantiate every class, we need 5.3.0 so this can be fully static
public static function &table_to_obj($table) {
if (isset(self::$table_cache[$table])) {
- return new self::$table_cache[$table];
+ $obj=new self::$table_cache[$table]();
+ return $obj;
}
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, 'sql_row_obj')) {
@@ -519,7 +514,8 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
}
}
}
- return null;
+ $null=null;
+ return $null;
}
// Same as table_to_class, but returns the name of the class, not an instance
public static function table_to_class($table) {
diff --git a/shared/classes/configopt.php b/shared/classes/configopt.php
index 178d0bb..c157d22 100644
--- a/shared/classes/configopt.php
+++ b/shared/classes/configopt.php
@@ -5,6 +5,7 @@ class sql_configopt extends sql_row_obj {
'type' => 'CHAR',
'length' => 6,
'not_null' => true,
+ 'default' => '',
'refers_to' => 'configurations.id'
),
'name' => array (
diff --git a/shared/classes/gentoo_package.php b/shared/classes/gentoo_package.php
new file mode 100644
index 0000000..580312f
--- /dev/null
+++ b/shared/classes/gentoo_package.php
@@ -0,0 +1,78 @@
+<?php
+class sql_gentoo_package extends sql_row_obj {
+ protected $table='gentoo_packages', $primary_key=array('id'), $columns=array(
+ 'id' => array (
+ 'type' => 'INT',
+ 'length' => 10,
+ 'unsigned' => true,
+ 'not_null' => true,
+ 'auto_increment' => true
+ ),
+ 'profile' => array (
+ 'type' => 'TINYINT',
+ 'length' => 3,
+ 'unsigned' => true,
+ 'not_null' => true,
+ 'default' => 0,
+ 'refers_to' => 'gentoo_profiles.id'
+ ),
+ 'bcat' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
+ 'lcat' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
+ 'name' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
+ 'version' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
+ 'data' => array (
+ 'type' => 'TEXT',
+ 'not_null' => true
+ )
+
+ );
+ function &to_array($skip_masked=false) {
+ $r=array();
+ foreach (explode("\n", $this->data) as $line) {
+ if (!strlen($line)) continue;
+ list($name, $val)=explode(': ', $line, 2);
+ $name=strtolower($name);
+ $r[$name]=$val;
+ }
+ if (!$skip_masked) {
+ $r['masked']=$this->is_masked($r);
+ }
+ return $r;
+ }
+ function is_masked(&$array=null) {
+ if ($array === null) {
+ $array=$this->to_array(true);
+ }
+ $heads=$this->get_profile()->get_headers();
+ $accept=explode(' ', $heads['accept_keywords']);
+ foreach ($accept as $akwd) {
+ foreach (explode(' ', $array['keywords']) as $kwd) {
+ if ($akwd == $kwd) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
+?>
diff --git a/shared/classes/gentoo_profile.php b/shared/classes/gentoo_profile.php
new file mode 100644
index 0000000..b705a97
--- /dev/null
+++ b/shared/classes/gentoo_profile.php
@@ -0,0 +1,137 @@
+<?php
+class sql_gentoo_profile extends sql_row_obj {
+ protected $table='gentoo_profiles', $primary_key=array('id'), $columns=array(
+ 'id' => array (
+ 'type' => 'TINYINT',
+ 'length' => 3,
+ 'unsigned' => true,
+ 'not_null' => true,
+ 'auto_increment' => true
+ ),
+ 'pkgdir' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => '',
+ 'unique' => true
+ ),
+ 'name' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'unique' => true
+ ),
+ 'order' => array (
+ 'type' => 'TINYINT',
+ 'length' => 4
+ ),
+ 'flags' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
+ 'headers' => array (
+ 'type' => 'TEXT',
+ 'not_null' => true
+ )
+
+ );
+ private $headers_cache;
+ // Returns $this->headers as an array
+ public function &get_headers() {
+ if (isset($headers_cache)) return $headers_cache;
+ foreach (explode("\n", $this->headers) as $line) {
+ if (!$line) continue;
+ list($name, $val)=explode(': ', $line, 2);
+ $this->headers_cache[strtolower($name)]=$val;
+ }
+ return $this->headers_cache;
+ }
+ // Reads the data from the Packages file in $this->pkgdir
+ public function read_Packages($update_pkgs=false) {
+ global $conf;
+ $file=fopen($conf['pkgdir_root'].'/'.$this->pkgdir.'/Packages', 'r');
+ $this->headers='';
+ while (!feof($file)) {
+ $line=rtrim(fgets($file));
+ if (strlen($line) == 0) {
+ break;
+ } else {
+ list($name, $val)=array_merge(explode(': ', $line, 2), array(null));
+ if ($val !== null) {
+ $this->headers.="$name: $val\n";
+ }
+ }
+ }
+ $p=array();
+ $cur=null;
+ $this->write();
+ while (!feof($file)) {
+ $line=rtrim(fgets($file));
+ if (strlen($line) == 0) {
+ unset($cur);
+ continue;
+ }
+ list($name, $val)=array_merge(explode(': ', $line, 2), array(null));
+ if ($name == 'CPV') {
+ if (preg_match('#^([^/-]+)([^/]*)/(.+?)-([^-]+)((?:-r[0-9]+)?)$#', $val, $match)) {
+ list(, $bcat, $lcat, $name, $ver, $r)=$match;
+ $ver.=$r;
+ } else {
+ debug("Unsplittable atom: $val");
+ continue;
+ }
+ if (isset($p[$bcat][$lcat][$name][$ver])) {
+ debug("Duplicate package $bcat$lcat/$name-$ver");
+ }
+ $p[$bcat][$lcat][$name][$ver]='';
+ $cur=&$p[$bcat][$lcat][$name][$ver];
+ } elseif (isset($cur, $val)) {
+ $cur.="$name: $val\n";
+ }
+ }
+ unset($cur);
+ $u=0;
+ if ($update_pkgs) {
+ global $S;
+ $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id);
+ while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) {
+ $pkg=new sql_gentoo_package($pkg);
+ if (isset($p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version])) {
+ if ($pkg->data != $p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version]) {
+ $u++;
+ $pkg->data=$p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version];
+ $pkg->write();
+ }
+ unset($p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version]);
+ } else {
+ $pkg->delete();
+ }
+ }
+ }
+ $n=0;
+ foreach ($p as $bcat => $lcats) {
+ foreach ($lcats as $lcat => $pkgs) {
+ foreach ($pkgs as $pkg => $vers) {
+ foreach ($vers as $ver => $data) {
+ $n++;
+ $gp=new sql_gentoo_package(null, $this->id, $bcat, $lcat, $pkg, $ver, $data);
+ $gp->write();
+ }
+ }
+ }
+ }
+ return array($n, $u);
+ }
+ public function &get_packages() {
+ global $S;
+ $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id);
+ $p=array();
+ while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) {
+ $pkg=new sql_gentoo_package($pkg);
+ $p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version]=$pkg->to_array();
+ }
+ return $p;
+ }
+}
+?>
diff --git a/shared/classes/profile.php b/shared/classes/profile.php
deleted file mode 100644
index 77603e2..0000000
--- a/shared/classes/profile.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-class sql_profile extends sql_row_obj {
- protected $table='profiles', $primary_key=array('id'), $columns=array(
- 'id' => array (
- 'type' => 'TINYINT',
- 'length' => 3,
- 'unsigned' => true,
- 'not_null' => true,
- 'auto_increment' => true
- ),
- 'pkgdir' => array (
- 'type' => 'VARCHAR',
- 'length' => 255,
- 'not_null' => true,
- 'default' => '',
- 'unique' => true
- ),
- 'name' => array (
- 'type' => 'VARCHAR',
- 'length' => 255,
- 'unique' => true
- ),
- 'order' => array (
- 'type' => 'TINYINT',
- 'length' => 4
- ),
- 'flags' => array (
- 'type' => 'VARCHAR',
- 'length' => 255,
- 'not_null' => true,
- 'default' => ''
- )
-
- );
- public function get_headers($return_filehandle=false) {
- global $conf;
- $file=fopen($conf['pkgdir_root'].'/'.$this->pkgdir.'/Packages', 'r');
- $headers=array();
- while (!feof($file)) {
- $line=rtrim(fgets($file));
- if (strlen($line) == 0) {
- break;
- } else {
- list($name, $val)=array_merge(explode(': ', $line, 2), array(null));
- if ($val !== null) {
- $headers[strtolower($name)]=$val;
- }
- }
- }
- if ($return_filehandle) {
- return array(&$headers, &$file);
- } else {
- fclose($file);
- return $headers;
- }
- }
- public function &get_packages() {
- list($headers, $file)=$this->get_headers(true);
- $accept_keywords=explode(' ', $headers['accept_keywords']);
- $p=array();
- $cur=null;
- while (!feof($file)) {
- $line=rtrim(fgets($file));
- if (strlen($line) == 0) {
- unset($cur);
- continue;
- }
- list($name, $val)=array_merge(explode(': ', $line, 2), array(null));
- if ($name == 'CPV') {
- if (preg_match('#^([^/-]+)([^/]*)/(.+?)-([^-]+)((?:-r[0-9]+)?)$#', $val, $match)) {
- list(, $bcat, $lcat, $name, $ver, $r)=$match;
- $ver.=$r;
- } else {
- debug("Unsplittable atom: $val");
- continue;
- }
- if (isset($p[$bcat][$lcat][$name][$ver])) {
- debug("Duplicate package $bcat$lcat/$name-$ver");
- // We don't really care about having correct info
-/* global $conf;
- $tbz=$conf['pkgdir_root'].'/'.$this->pkgdir.'/'.(isset($p[$cat][$name][$ver]['path'])?$p[$cat][$name][$ver]['path']:"$cat/$name-$ver.tbz2");
- if (filesize($tbz) == $p[$cat][$name][$ver]['size']) {
- debug($this->pkgdir.": Duplicate package $cat/$name-$ver - current entry matches size, dropping new entry");
- continue;
- } else {
- debug($this->pkgdir.": Duplicate package $cat/$name-$ver - current entry invalid, using new entry");
- }*/
- }
- $p[$bcat][$lcat][$name][$ver]=array();
- $cur=&$p[$bcat][$lcat][$name][$ver];
- } elseif (isset($cur, $val)) {
- switch($name) {
- case 'KEYWORDS':
- $cur['keywords']=explode(' ', $val);
- $cur['masked']=!array_intersect($cur['keywords'], $accept_keywords);
- break;
- case 'DESC':
- $cur['description']=$val;
- break;
-/* case 'SIZE':
- $cur['size']=$val;
- break;
- case 'PATH':
- $cur['path']=$val;
- break;*/
- default:
- $cur[$name]=$val;
- }
- }
- }
- return $p;
- }
-}
-?>
diff --git a/shared/config.php b/shared/config.php
index c8f1179..ecf22fc 100644
--- a/shared/config.php
+++ b/shared/config.php
@@ -14,7 +14,7 @@ $conf['timezone']=10800; // Time difference in seconds between UTC and the defau
$conf['mod_rewrite']=true; // Use mod_rewrite for pretty URLs
$conf['emailfrom']='noreply@gentoo.org'; // Used as the From: field in emails
$conf['check_email_dns']=true; // Use DNS to check the domain of submitted emails for validity
-$conf['pkgdir_root']='/home/eitan/soc/tinderbox'; // The directory to recursively search for pkgdirs in
+$conf['pkgdir_root']='/home/eitan/soc/tinderbox'; // The directory to recursively search for pkgdirs in (Backend only)
$conf['emerge_default_opts']='-t -v -K --color=y --root-deps=rdeps'; // DON'T CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING
$conf['portdir']='/usr/portage'; // The directory conatining the portage tree to use (/usr/portage unless you have a reason to think otherwise)
$conf['logview_max']=1000; // The maximum number of log entries shown on one page (1000 is a good start)
diff --git a/todo b/todo
index 3e2c716..eb18365 100644
--- a/todo
+++ b/todo
@@ -1,6 +1,8 @@
Have backend handle builds that it finds to already be running (break in to steps and store current status)
Make package adding friendly for browsers without JS/CSS (use ul/li, not div)
-Reduce page size for package adding
+Use database package ID instead of full package name in package selection
+Figure out how to adapt to newer versions of packages
+Further reduce page size for package adding
Write a live git ebuild
Write an AJAX-based self-updating status viewer
*** Add logging besides just commands ***
@@ -9,16 +11,19 @@ Have builds and tasks not give links to logs if we're already viewing the logs
Either make task status a TEXT or stop putting command name in the status (via thrown exception) - we can fetch this later anyway - just store the task id that failed (or use the last task)
Consider saving env. passed to tasks, path if we ever use it
Add metadata back to logviewer
-Do like wikipedia and put the header in the footer so important parts load first
Add configurable groups of suggested packages to frontend, backend
Add a statistics page
+Add a profiles management page/backend utility
Add cleanup functions to the frontend and backend
Separate variables we got from the URL from the rest, stop using $request, instead keep super globals and strip slashes on them
-Support ~arch installation or remove it from listings
+Support ~arch installation
Completely plan out how frontend modules should function - each step needs to report if it finished successfully (required values)
See if I can figure any way to use classes instead of funny named functions (namespaces in 5.3.0 perhaps) - also needs to have a depend of some sort so we can make a quick-config page that doesn't show things that we don't have enough info for yet (use AJAX to show them when we're ready)
Allow backend to define bail-out functions to call when it dies (things like unmounting the ISO it was copying)
Add STDERR (maybe STDOUT) only option to log viewer
-*** Make frontend/backend split possible *** - Stop directly accessing PKGDIR from the frontend - put whatever info we need in the database and write a script for updating it from the backend; track which backend is doing which build
+Make multiple backends possible - avoid race condition when choosing a task; track which backend is doing which build
Simplify status to numeric on builds, configurations - varchar isn't necessary
Add config option to enable/disable user self-registration/invitations/admin-only invites
+Fix the bug where refreshing a wizard page and resending data causes it to continue to the next step
+Change profiles to gentoo_profiles
+Move gentoo_profiles setup out of the general setup.php, allow per-module setup
diff --git a/update_gentoo_profiles.php b/update_gentoo_profiles.php
new file mode 100755
index 0000000..545b08f
--- /dev/null
+++ b/update_gentoo_profiles.php
@@ -0,0 +1,14 @@
+#!/usr/bin/php
+<?php
+require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0
+require_once(SHARED.'/config.php');
+require_once(SHARED.'/include/dbinit.php');
+$pdo=&$S['pdo'];
+$r=$pdo->query('SELECT * FROM `gentoo_profiles`'.(isset($argv[1])?' WHERE `name` LIKE "%'.$argv[1].'%" OR `pkgdir` LIKE "%'.$argv[1].'%"':''));
+while ($p=$r->fetch(PDO::FETCH_ASSOC)) {
+ $p=new sql_gentoo_profile($p);
+ echo 'Updating from '.$conf['pkgdir_root'].'/'.$p->pkgdir.'/Packages...';
+ list($new, $updated)=$p->read_Packages(true);
+ echo "done\nPackages: $new new, $updated updated.\n";
+}
+?>