diff options
author | Erik Hovland <erik@hovland.org> | 2006-08-30 18:42:42 +0000 |
---|---|---|
committer | Erik Hovland <erik@hovland.org> | 2006-08-30 18:42:42 +0000 |
commit | 4d36c0d6c6c4e6ed9f148d70588fdb16798e9b9c (patch) | |
tree | e1e2d433887f193ea6be861ece68309e7d667619 /contrib/feed-browser/update.php | |
parent | ff49b42aedb3c09f71cb35456140b9afcf6b40b8 (diff) | |
parent | 71bd0cd9cf4addbc38028705674fb56c2a644071 (diff) |
merge of 'd0e2c30b999cbef32c26717651606b8411ad02d6'
and 'ffac2606c1f6116f54c1871ff55c69f027252547'
Diffstat (limited to 'contrib/feed-browser/update.php')
-rw-r--r-- | contrib/feed-browser/update.php | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/contrib/feed-browser/update.php b/contrib/feed-browser/update.php new file mode 100644 index 0000000000..ed67d3b78a --- /dev/null +++ b/contrib/feed-browser/update.php @@ -0,0 +1,180 @@ +<?php +/* (c) Koen Kooi 2006 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License along + * with this library; see the file COPYING.LIB. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + * + */ + +require_once 'includes/config.inc'; +require_once 'includes/functions.inc'; + +/* + A package entry looks like this: + Package: zeroconf + Version: 0.9-r0 + Depends: libc6 (>= 2.4) + Provides: libfontconfig-utils + Replaces: libfontconfig-utils + Conflicts: libfontconfig-utils + Section: net + Architecture: armv5te + Maintainer: Angstrom Developers <angstrom-dev@handhelds.org> + MD5Sum: b8bd197224e24759d2162091a0fa727f + Size: 12346 + Filename: zeroconf_0.9-r0_armv5te.ipk + Source: http://www.progsoc.org/~wildfire/zeroconf/download/zeroconf-0.9.tar.gz file://zeroconf-default file://debian-zeroconf + Description: IPv4 link-local address allocator + */ + +check_database(); + +$feeds = db_query("SELECT f_id, f_name, f_uri FROM feeds"); + +if($argc > 1 AND $argv[1] == 'upgrades') +{ + $feeds = db_query("SELECT f_id, f_name, f_uri FROM feeds WHERE f_type = 'upgrades'"); +} + +$start = time(); +$p_count = 0; + +foreach($feeds as $feed) +{ + print("Updating {$feed['f_name']}: "); + db_query_n("DELETE FROM packages WHERE p_feed = '{$feed['f_id']}'"); + + $count = 0; + + $packagesgz_h = fopen("compress.zlib://{$feed['f_uri']}/Packages.gz", "r"); + + if ($packagesgz_h) + { + $package_info = array( + 'name'=>'', 'version'=>'', 'arch'=>'', 'depends'=>'', + 'maintainer'=>'', 'homepage'=>'', 'section'=>'', 'replaces'=>'', + 'provides'=>'', 'recommends'=>'', 'conflicts'=>'', 'size'=>'', + 'md5sum'=>'', 'source'=>'', 'feed'=>$feed['f_id'], 'file'=>'', 'desc'=>'' + ); + + while (!feof($packagesgz_h)) + { + $buffer = fscanf($packagesgz_h, "%[^:]: %[ -~]"); + list ($field, $value) = $buffer; + + if($field == 'Package' && $count > 0) + { + insert_ipkgs($package_info); + + $package_info = array( + 'name'=>'', 'version'=>'', 'arch'=>'', 'depends'=>'', + 'maintainer'=>'', 'homepage'=>'', 'section'=>'', 'replaces'=>'', + 'provides'=>'', 'recommends'=>'', 'conflicts'=>'', 'size'=>'', + 'md5sum'=>'', 'source'=>'', 'feed'=>$feed['f_id'], 'file'=>'', 'desc'=>'' + ); + } + + switch($field) + { + case 'Package': + $package_info['name'] = $value; + $count++; + break; + case 'Version': + $package_info['version'] = $value; + break; + case 'Depends': + $package_info['depends'] = $value; + break; + case 'Provides': + $package_info['provides'] = $value; + break; + case 'Recommends': + $package_info['recommends'] = $value; + break; + case 'Replaces': + $package_info['replaces'] = $value; + break; + case 'Conflicts': + $package_info['conflicts'] = $value; + break; + case 'Section': + $package_info['section'] = strtolower($value); + break; + case 'Architecture': + $package_info['arch'] = $value; + break; + case 'Maintainer': + $package_info['maintainer'] = str_replace("'","\"", $value); + break; + case 'MD5sum': + $package_info['md5sum'] = $value; + break; + case 'Size': + $package_info['size'] = $value; + break; + case 'Filename': + $package_info['file'] = $value; + break; + case 'Source': + $package_info['source'] = $value; + break; + case 'Description': + $package_info['desc'] = str_replace("'","\"", $value); + break; + } + + } + + insert_ipkgs($package_info); + } + + $p_count = $count + $p_count; + print("$count packages\n"); + gzclose($packagesgz_h); +} +//close the db + +$end = time(); +$difference = $end - $start; + +$days = floor($difference/86400); +$difference = $difference - ($days*86400); + +$hours = floor($difference/3600); +$difference = $difference - ($hours*3600); + +$minutes = floor($difference/60); +$difference = $difference - ($minutes*60); + +$seconds = $difference; + +print "Added $p_count packages in $days days, $hours hours, $minutes minutes and $seconds seconds \n"; + + +function insert_ipkgs(&$package_info) +{ + db_query_n("INSERT INTO packages VALUES ( + '{$package_info['name']}', '{$package_info['version']}', + '{$package_info['arch']}', '{$package_info['depends']}', + '{$package_info['maintainer']}', '{$package_info['homepage']}', + '{$package_info['section']}', '{$package_info['replaces']}', + '{$package_info['provides']}', '{$package_info['recommends']}', + '{$package_info['conflicts']}', '{$package_info['size']}', + '{$package_info['md5sum']}', '{$package_info['source']}', + '{$package_info['feed']}', '{$package_info['file']}', + '{$package_info['desc']}' + )"); +} + +?> |