summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-06-21 15:51:25 -0400
committerEudyptula <eitan@mosenkis.net>2009-06-21 15:51:25 -0400
commit8ca317c1a77759f38c9ec304291912b6808055ea (patch)
tree9f302f27266aecc576d4cb40a6f91e3a453ab728
parentFinished infrastructure for 1st gen. build wizard, enhanced backend logging (diff)
downloadingenue-8ca317c1a77759f38c9ec304291912b6808055ea.tar.gz
ingenue-8ca317c1a77759f38c9ec304291912b6808055ea.tar.bz2
ingenue-8ca317c1a77759f38c9ec304291912b6808055ea.zip
Did some cleanup and added a Packages file parser and simple package list printer script
-rwxr-xr-xbackend/backend.php1
-rw-r--r--backend/functions/build.php2
-rw-r--r--backend/functions/get_profile_headers.php17
-rw-r--r--backend/functions/tempdir.php10
-rw-r--r--frontend/functions/debug.php12
-rw-r--r--frontend/functions/sql.php32
-rw-r--r--frontend/functions/timetosecs.php13
-rw-r--r--frontend/index.php1
-rwxr-xr-xpkglist.php20
-rwxr-xr-xsetup.php1
-rw-r--r--shared/classes/profile.php70
-rw-r--r--shared/functions/debug.php16
-rw-r--r--shared/include/includes.php1
13 files changed, 108 insertions, 88 deletions
diff --git a/backend/backend.php b/backend/backend.php
index 0dbd8a9..6cfb28e 100755
--- a/backend/backend.php
+++ b/backend/backend.php
@@ -1,7 +1,6 @@
#!/usr/bin/php
<?php
require_once(dirname(__FILE__).'/../shared/include/includes.php'); // USE __DIR__ once 5.3.0 is out
-require_once(SHARED.'/config.php');
require_once(SHARED.'/include/dbinit.php');
$pdo=&$S['pdo'];
$opts=getopt('f');
diff --git a/backend/functions/build.php b/backend/functions/build.php
index 84b2a77..36841f6 100644
--- a/backend/functions/build.php
+++ b/backend/functions/build.php
@@ -9,7 +9,7 @@ function build(&$build) {
$opts[$opt->name]=$opt;
}
$profile=new sql_profile($opts['profile']->value);
- $headers=get_profile_headers($profile);
+ $headers=$profile->get_headers();
$makeconf['pkgdir']=$conf['pkgdir_root'].'/'.$profile->pkgdir;
$makeconf['chost']=$headers['chost'];
$build->status='build/started';
diff --git a/backend/functions/get_profile_headers.php b/backend/functions/get_profile_headers.php
deleted file mode 100644
index 0a63f61..0000000
--- a/backend/functions/get_profile_headers.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-function get_profile_headers($profile) {
- global $conf;
- $file=fopen($conf['pkgdir_root'].'/'.$profile->pkgdir.'/Packages', 'r');
- $headers=array();
- while (true) {
- $line=rtrim(fgets($file));
- if (strlen($line) == 0) {
- break;
- } elseif (preg_match('/^([a-zA-Z0-9_-]+): (.*)$/', $line, $match)) {
- $headers[strtolower($match[1])]=$match[2];
- }
- }
- fclose($file);
- return $headers;
-}
-?>
diff --git a/backend/functions/tempdir.php b/backend/functions/tempdir.php
deleted file mode 100644
index cbda127..0000000
--- a/backend/functions/tempdir.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-// Adapted from code by Ron Korving (http://us3.php.net/manual/en/function.tempnam.php#61436)
-function tempdir($dir, $prefix='', $mode=0700, $recursive=false) {
- if (substr($dir, -1) != '/') $dir .= '/';
- do {
- $path = $dir.$prefix.randstring(6);
- } while (!mkdir($path, $mode, $recursive));
- return $path;
-}
-?>
diff --git a/frontend/functions/debug.php b/frontend/functions/debug.php
deleted file mode 100644
index 8487916..0000000
--- a/frontend/functions/debug.php
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-function debug ($type, $text=null) {
- global $conf, $S;
- if ($conf['debug']) {
- if ($text===null) {
- $text=$type;
- $type=null;
- }
- $S['debug'][]=array($type, $text);
- }
-}
-?>
diff --git a/frontend/functions/sql.php b/frontend/functions/sql.php
deleted file mode 100644
index f100413..0000000
--- a/frontend/functions/sql.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-if (version_compare(PHP_VERSION, '5.0.0', '<')) die('MySQLi can only be used with PHP >= 5.0.0');
-function sql_query($q, $cache=true) {
- global $state, $conf;
- $result=$state->sql->query($q, $cache) or trigger_error('Query failed: "'.$q.'"', E_USER_ERROR);
- return $result;
-}
-function sql_escape_string($string) {
- global $state;
- return $state->sql->real_escape_string($string);
-}
-function sql_last_insert_id() {
- global $state;
- return $state->sql->last_insert_id();
-}
-function sql_quick_query($query) {
- global $state;
- return $state->sql->quick_query($query);
-}
-function sql_count($from, $where=null) {
- global $state;
- return $state->sql->count($from, $where);
-}
-function sql_max($from, $of, $where=null) {
- global $state;
- return $state->sql->max($from, $of, $where);
-}
-function sql_min($from, $of, $where=null) {
- global $state;
- return $state->sql->min($from, $of, $where);
-}
-?>
diff --git a/frontend/functions/timetosecs.php b/frontend/functions/timetosecs.php
deleted file mode 100644
index 7cc278b..0000000
--- a/frontend/functions/timetosecs.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-function timetosecs($time) {
- if (preg_match('/^([0-9]+):([0-9]+):([0-9]+(\.[0-9]+)?)$/', $time, $match)) {
- return(3600*$match[1]+60*$match[2]+$match[3]);
- } elseif (preg_match('/^([0-9]+):([0-9]+(\.[0-9]+)?)$/', $time, $match)) {
- return(60*$match[1]+$match[2]);
- } elseif (preg_match('/^([0-9]+(\.[0-9]+)?)$/', $time, $match)) {
- return($match[1]);
- } else {
- return 0;
- }
-}
-?>
diff --git a/frontend/index.php b/frontend/index.php
index b66257a..d17324a 100644
--- a/frontend/index.php
+++ b/frontend/index.php
@@ -4,7 +4,6 @@ date_default_timezone_set('UTC');
require_once('../shared/include/includes.php');
require_once('include/error_handling.php');
require_once('include/constants.php');
-require_once(SHARED.'/config.php');
require_once('include/setup.php');
register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php'));
$request=get_magic_quotes_gpc()?r_stripslashes($_REQUEST):$_REQUEST;
diff --git a/pkglist.php b/pkglist.php
new file mode 100755
index 0000000..1be1dbb
--- /dev/null
+++ b/pkglist.php
@@ -0,0 +1,20 @@
+#!/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 `profiles`');
+while ($p=$r->fetch(PDO::FETCH_ASSOC)) {
+ $p=new sql_profile($p);
+ echo ($p->name?$p->name:$p->pkgdir)."\n";
+ $packages=$p->get_packages();
+ foreach ($packages as $cat => $pkg) {
+ foreach ($pkg as $name => $vers) {
+ foreach ($vers as $ver => $attrs) {
+ echo ($attrs['masked']?color('[MASKED] ', 'red'):'')."$cat/$name-$ver: ".$attrs['description']."\n";
+ }
+ }
+ }
+}
+?>
diff --git a/setup.php b/setup.php
index 24bc0a5..c67c723 100755
--- a/setup.php
+++ b/setup.php
@@ -1,7 +1,6 @@
#!/usr/bin/php
<?php
require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0
-require_once(SHARED.'/config.php');
function echo_and_query($q) {
global $pdo;
echo $q."\n";
diff --git a/shared/classes/profile.php b/shared/classes/profile.php
index b528b47..055ad97 100644
--- a/shared/classes/profile.php
+++ b/shared/classes/profile.php
@@ -24,5 +24,75 @@ class sql_profile extends sql_row_obj {
)
);
+ private function &open_Packages() {
+ global $conf;
+ return fopen($conf['pkgdir_root'].'/'.$this->pkgdir.'/Packages', 'r');
+ }
+ public function &get_headers($return_filehandle=false) {
+ $file=$this->open_Packages();
+ $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);
+ // echo $headers['accept_keywords'];
+ $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(, $cat, $name, $ver, $r)=$match;
+ $ver.=$r;
+ } else {
+ debug("Unsplittable atom: $val");
+ continue;
+ }
+ if (isset($p[$cat][$name][$ver])) {
+ $dups[$cat][$name][$ver]=$p[$cat][$name][$ver];
+ if (defined('STDERR')) {
+ debug($this->pkgdir.": Duplicate package $cat/$name-$ver");
+ }
+ }
+ $p[$cat][$name][$ver]=array();
+ $cur=&$p[$cat][$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;
+ default:
+ $cur[$name]=$val;
+ }
+ }
+ }
+ return $p;
+ }
}
?>
diff --git a/shared/functions/debug.php b/shared/functions/debug.php
new file mode 100644
index 0000000..4231e21
--- /dev/null
+++ b/shared/functions/debug.php
@@ -0,0 +1,16 @@
+<?php
+function debug ($type, $text=null) {
+ global $conf, $S;
+ if ($conf['debug']) {
+ if ($text===null) {
+ $text=$type;
+ $type=null;
+ }
+ if (defined('STDERR')) { // This is backend, probably
+ fputs(STDERR, (isset($type)?$type.': ':'').$text."\n");
+ } else { // This is probably frontend
+ $S['debug'][]=array($type, $text);
+ }
+ }
+}
+?>
diff --git a/shared/include/includes.php b/shared/include/includes.php
index b3ff5a3..ae12d81 100644
--- a/shared/include/includes.php
+++ b/shared/include/includes.php
@@ -9,4 +9,5 @@ foreach (array('functions', 'classes') as $type) {
}
}
unset($dir, $file, $type);
+require_once(SHARED.'/config.php');
?>