gdb-cross/cross-sdk: Fixup DEPENDS further
[openembedded.git] / contrib / feed-browser / update.php
blobba6775fb4042b6d5d4e5eeb09409b35fdffb04d4
1 <?php
2 /*
3 * (c) Koen Kooi 2006, 2007
4 * (c) Marcin Juszkiewicz 2006, 2007
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License along
15 * with this library; see the file COPYING.LIB. If not, write to the Free
16 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
19 */
21 require_once 'includes/config.inc';
22 require_once 'includes/functions.inc';
25 A package entry looks like this:
26 Package: zeroconf
27 Version: 0.9-r0
28 Depends: libc6 (>= 2.4)
29 Provides: libfontconfig-utils
30 Replaces: libfontconfig-utils
31 Conflicts: libfontconfig-utils
32 Section: net
33 Architecture: armv5te
34 Maintainer: Angstrom Developers <angstrom-dev@handhelds.org>
35 License: GPL
36 MD5Sum: b8bd197224e24759d2162091a0fa727f
37 Size: 12346
38 Filename: zeroconf_0.9-r0_armv5te.ipk
39 Source: http://www.progsoc.org/~wildfire/zeroconf/download/zeroconf-0.9.tar.gz file://zeroconf-default file://debian-zeroconf
40 Description: IPv4 link-local address allocator
43 if(!check_database())
45 die("Database not found and cannot be created.");
48 $feeds = db_query("SELECT f_id, f_name, f_uri FROM feeds");
50 if($argc == 2)
52 $feeds = db_query("SELECT f_id, f_name, f_uri FROM feeds WHERE f_uri = '${argv[1]}'");
53 } else if ($argc == 3 && $argv[1] == "--type") {
54 $feeds = db_query("SELECT f_id, f_name, f_uri FROM feeds WHERE f_type = '${argv[2]}'");
57 if (!$feeds) {
58 die("Cannot find feed(s) in the DB\n");
61 $start = time();
62 $p_count = 0;
64 foreach($feeds as $feed)
66 print("Updating {$feed['f_name']}: ");
67 db_query_n("DELETE FROM packages WHERE p_feed = '{$feed['f_id']}'");
69 $count = 0;
71 $packagesgz_h = fopen("compress.zlib://{$feed['f_uri']}/Packages.gz", "r");
73 if ($packagesgz_h)
75 $package_info = array(
76 'name'=>'', 'version'=>'', 'arch'=>'', 'depends'=>'',
77 'maintainer'=>'', 'homepage'=>'', 'section'=>'', 'replaces'=>'',
78 'provides'=>'', 'recommends'=>'', 'conflicts'=>'', 'size'=>'',
79 'md5sum'=>'', 'source'=>'', 'feed'=>$feed['f_id'], 'file'=>'', 'desc'=>''
82 while (!feof($packagesgz_h))
84 $buffer = fscanf($packagesgz_h, "%[^:]: %[ -~]");
85 list ($field, $value) = $buffer;
87 if($field == 'Package' && $count > 0)
89 insert_ipkgs($package_info);
91 $package_info = array(
92 'name'=>'', 'version'=>'', 'arch'=>'', 'depends'=>'',
93 'maintainer'=>'', 'homepage'=>'', 'section'=>'', 'replaces'=>'',
94 'provides'=>'', 'recommends'=>'', 'conflicts'=>'', 'size'=>'',
95 'md5sum'=>'', 'source'=>'', 'feed'=>$feed['f_id'], 'file'=>'', 'desc'=>''
99 switch($field)
101 case 'Package':
102 $package_info['name'] = $value;
103 $count++;
104 break;
105 case 'Version':
106 $package_info['version'] = $value;
107 break;
108 case 'Depends':
109 $package_info['depends'] = $value;
110 break;
111 case 'Provides':
112 $package_info['provides'] = $value;
113 break;
114 case 'Recommends':
115 $package_info['recommends'] = $value;
116 break;
117 case 'Replaces':
118 $package_info['replaces'] = $value;
119 break;
120 case 'Conflicts':
121 $package_info['conflicts'] = $value;
122 break;
123 case 'Section':
124 $package_info['section'] = strtolower($value);
125 break;
126 case 'Architecture':
127 $package_info['arch'] = $value;
128 break;
129 case 'Maintainer':
130 $package_info['maintainer'] = str_replace("'","\"", $value);
131 break;
132 case 'MD5sum':
133 $package_info['md5sum'] = $value;
134 break;
135 case 'Size':
136 $package_info['size'] = $value;
137 break;
138 case 'Filename':
139 $package_info['file'] = $value;
140 break;
141 case 'Source':
142 $package_info['source'] = $value;
143 break;
144 case 'Description':
145 $package_info['desc'] = str_replace("'","\"", $value);
146 break;
151 insert_ipkgs($package_info);
154 $p_count = $count + $p_count;
155 print("$count packages\n");
156 gzclose($packagesgz_h);
158 //close the db
160 $end = time();
161 $difference = $end - $start;
163 $days = floor($difference/86400);
164 $difference = $difference - ($days*86400);
166 $hours = floor($difference/3600);
167 $difference = $difference - ($hours*3600);
169 $minutes = floor($difference/60);
170 $difference = $difference - ($minutes*60);
172 $seconds = $difference;
174 print "Added $p_count packages in $days days, $hours hours, $minutes minutes and $seconds seconds \n";
177 function insert_ipkgs(&$package_info)
179 db_query_n("INSERT INTO packages VALUES (
180 '{$package_info['name']}', '{$package_info['version']}',
181 '{$package_info['arch']}', '{$package_info['depends']}',
182 '{$package_info['maintainer']}', '{$package_info['homepage']}',
183 '{$package_info['section']}', '{$package_info['replaces']}',
184 '{$package_info['provides']}', '{$package_info['recommends']}',
185 '{$package_info['conflicts']}', '{$package_info['size']}',
186 '{$package_info['md5sum']}', '{$package_info['source']}',
187 '{$package_info['feed']}', '{$package_info['file']}',
188 '{$package_info['desc']}'
189 )");