]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/hwinfo/src/ids/cdb_x11
Kleiner netter neuer Versuch.
[people/teissler/ipfire-2.x.git] / src / hwinfo / src / ids / cdb_x11
1 #!/usr/bin/perl -w
2 # Copyright (c) 1996 SuSE GmbH Nuernberg, Germany. All rights reserved.
3 #
4 # Author: Dirk Hessing <dhess@suse.de>, 08/2001
5 #
6 # Exporting hw-data for x11 from developer-CDB
7
8
9 use DBI;
10 use strict;
11 use IO::Handle;
12 use Getopt::Long;
13
14 # MySQL-Host / MySQL-User
15 my $hostname = "cdbintern.suse.de";
16 my $mysql_user = "cdbclient";
17 my $mysql_passwd = "cdb";
18 my $target = "cdb";
19
20 my $driver = DBI->install_driver('mysql');
21 my $dbh = DBI->connect('DBI:mysql:'.$target.':'.$hostname,$mysql_user,$mysql_passwd)
22 or die "Can't connect to the MySQL Database, table $target";
23
24 ### Log-Handle und STDOUT-Handle auf ungepufferte Ausgabe setzten (schlechtere Performance ;-)
25 STDOUT->autoflush();
26
27
28 my $dist_name = "Stable";
29 my $date = localtime();
30
31 my (@query,$x,$result,$arch_name,@arch_names,$filename,$count);
32 my ($product_id,$product_name,$vendor_name,$bus_name,$subclass_name);
33 my ($vId,$dId,$sdId,$svId);
34 my (%tooltopics,$tooltopic_name,$vario_name,$charvalue);
35
36 my $opt_dir = "tmp";
37
38
39 # convert to new id format
40 sub new_id
41 {
42 my ($old_id, $id_class, $tag, $id);
43
44 ($old_id, $id_class) = @_;
45
46 if($old_id =~ /^([us]?)(\S{4})$/) {
47 $tag = $1;
48 $id = $2;
49 }
50 else {
51 die "invalid id format: \"$old_id\"\n";
52 }
53
54 if($tag eq "" && $id_class && $id_class =~ /^([us]?)(\S{4})$/) {
55 $tag = $1;
56 }
57
58 if($tag eq "s") {
59 $tag = "special ";
60 }
61 elsif($tag eq "u") {
62 $tag = "usb ";
63 }
64 elsif($tag eq "") {
65 $tag = "pci ";
66 }
67 else {
68 die "invalid id format: \"$old_id\"\n";
69 }
70
71 return "${tag}0x$id";
72 }
73
74
75 # write data to FH
76 sub write_info
77 {
78 my ($arch, $xfree, $has3d, $vId, $dId, $svId, $sdId, $vName, $dName, $tt, $raw, @raw);
79
80 ($arch, $xfree, $has3d, $vId, $dId, $svId, $sdId, $vName, $dName, $tt) = @_;
81
82 return unless $vId ne "" && $dId ne "";
83
84 # print FH "\n# vId = $vId, dId = $dId, svId = $svId, sdId = $sdId, vName = \"$vName\", dName = \"$dName\"\n";
85
86 if($svId ne "" && $sdId ne "") {
87 print FH "\n vendor.id\t\t${\new_id $vId}\n";
88 print FH "+vendor.name\t\t$vName\n";
89
90 print FH "\n vendor.id\t\t${\new_id $vId}\n";
91 print FH "&device.id\t\t${\new_id $dId, $vId}\n";
92 print FH "&subvendor.id\t\t${\new_id $svId, $vId}\n";
93 print FH "&subdevice.id\t\t${\new_id $sdId, $vId}\n";
94 print FH "+subdevice.name\t\t$dName\n";
95 }
96 else {
97 print FH "\n vendor.id\t\t${\new_id $vId}\n";
98 print FH "+vendor.name\t\t$vName\n";
99
100 print FH "\n vendor.id\t\t${\new_id $vId}\n";
101 print FH "&device.id\t\t${\new_id $dId, $vId}\n";
102 print FH "+device.name\t\t$dName\n";
103 }
104
105 if($$tt{resol} ne "") {
106 $$tt{resol} =~ s/bpp//g;
107 }
108
109 # Teste ob mehr als ein driver- oder installscript-topic vorhanden ist:
110 if(($$tt{driver} =~ /,/) || ($$tt{installscript} =~ /,/)) {
111 warn
112 "\nMore than one driver- or installscript-topic.\n" .
113 " Product-id = $product_id, Vario = $vario_name, Arch = $arch\n" .
114 " Id = (${\new_id $vId}, ${\new_id $dId, $vId}), Name = $dName\n" .
115 " Driver = \"$$tt{driver}\", script = \"$$tt{installscript}\"\n";
116 }
117
118 print FH
119 "+driver.xfree\t\t$xfree|$$tt{driver}|" .
120 ($has3d ? "3d" : "") .
121 "|$$tt{package}|$$tt{extension}|$$tt{option}|$$tt{resol}||$$tt{installscript}|\n";
122
123 if ($$tt{raw} ne "") {
124 @raw = (split(',',$$tt{raw}));
125 foreach $raw (@raw) {
126 print FH "+driver.xfree.config\t$raw\n";
127 }
128 }
129 }
130
131
132 # get product info and write everything to FH
133 sub get_info
134 {
135 my ($arch_name, $xfree, $has3d);
136
137 ($arch_name, $vario_name) = @_;
138
139 $xfree = $vario_name =~ /XFree3/ ? 3 : 4;
140 $has3d = $vario_name =~ /3D/ ? 1 : 0;
141
142 $tooltopics{driver} = "";
143 $tooltopics{package} = "";
144 $tooltopics{extension} = "";
145 $tooltopics{option} = "";
146 $tooltopics{resol} = "";
147 $tooltopics{installscript} = "";
148 $tooltopics{raw} = "";
149
150 # Product supported=full?
151 $query[2] = $dbh->prepare("SELECT toolproperty.charvalue FROM toolproperty
152 LEFT JOIN tooltopic ON toolproperty.tooltopic_id=tooltopic.id
153 LEFT JOIN arch_dist_l_vario ON toolproperty.arch_dist_l_vario_id=arch_dist_l_vario.id
154 LEFT JOIN arch ON arch_dist_l_vario.arch_id=arch.id
155 LEFT JOIN distribution ON arch_dist_l_vario.distribution_id=distribution.id
156 LEFT JOIN vario ON arch_dist_l_vario.vario_id=vario.id
157 WHERE toolproperty.product_id=$product_id
158 AND tooltopic.name='supported'
159 AND arch.name='$arch_name'
160 AND distribution.name='$dist_name'
161 AND vario.name='$vario_name'
162 AND toolproperty.valid=1
163 AND tooltopic.valid=1
164 AND arch_dist_l_vario.valid=1")
165 or die "Can\'t select table toolproperty";
166 $query[2]->execute or die "Can\'t select table toolproperty";
167
168 undef $result;
169 $count = 0;
170 while ($x = $query[2]->fetchrow_array) {
171 $result = $x if defined $x;
172 multiple_supportedtopics($dbh,$product_id,$product_name,$arch_name,$dist_name,$vario_name) if $count > 0;
173 $count++;
174 }
175 $result = "" if not defined $result;
176
177 if ($result eq "full") {
178 $query[2] = $dbh->prepare("SELECT tooltopic.name,toolproperty.charvalue FROM toolproperty
179 LEFT JOIN tooltopic ON toolproperty.tooltopic_id=tooltopic.id
180 LEFT JOIN arch_dist_l_vario ON toolproperty.arch_dist_l_vario_id=arch_dist_l_vario.id
181 LEFT JOIN arch ON arch_dist_l_vario.arch_id=arch.id
182 LEFT JOIN distribution ON arch_dist_l_vario.distribution_id=distribution.id
183 LEFT JOIN language ON arch_dist_l_vario.lang_id=language.id
184 LEFT JOIN vario ON arch_dist_l_vario.vario_id=vario.id
185 WHERE arch.name='$arch_name'
186 AND distribution.name='$dist_name'
187 AND vario.name='$vario_name'
188 AND toolproperty.product_id=$product_id
189 AND tooltopic.name != 'supported'
190 AND toolproperty.valid=1
191 AND tooltopic.valid=1
192 AND arch_dist_l_vario.valid=1")
193 or die "Can\'t select table toolproperty";
194 $query[2]->execute or die "Can\'t select table toolproperty";
195
196 while ( ($tooltopic_name,$charvalue) = ($query[2]->fetchrow_array) ) {
197 if (($charvalue eq "none") || ($charvalue eq "None")) {
198 $charvalue = "";
199 }
200 next if $charvalue eq "";
201 if (!$tooltopics{"$tooltopic_name"}) {
202 $tooltopics{"$tooltopic_name"} = $charvalue;
203 } else {
204 $tooltopics{"$tooltopic_name"} .= ",".$charvalue;
205 }
206 }
207
208 write_info $arch_name, $xfree, $has3d, $vId, $dId, $svId, $sdId, $vendor_name, $product_name, \%tooltopics;
209 }
210 }
211
212
213 GetOptions(
214 'dir=s' => \$opt_dir
215 ) ;
216
217
218 print "\n\nGenerating x11.hwinfo-files, one for each architecture.\n";
219 mkdir($opt_dir, 0755) || die "\nmkdir: $opt_dir: $!\n" unless -d $opt_dir;
220
221 print "\nStoring files in \"$opt_dir\"\n\n";
222
223 $query[0] = $dbh->prepare("SELECT name FROM arch WHERE valid=1")
224 or die "Can\'t select table arch";
225 $query[0]->execute or die "Can\'t select table arch";
226 while ($result = $query[0]->fetchrow_array) {
227 push(@arch_names,$result);
228 }
229
230 # Für jede Architektur wird eine eigene Datei geschrieben
231 foreach $arch_name (@arch_names) {
232 $filename = "$opt_dir/x11.hwinfo.$arch_name";
233 open(FH,"> $filename") or die "Can\'t open $filename";
234 print FH "#\n";
235 print FH "# x11.hwinfo-file for architecture $arch_name\n";
236 print FH "#\n";
237 print FH "# generated at: $date\n";
238 print FH "# data source: CDB\n";
239 print FH "# distribution: $dist_name\n";
240 print FH "#\n\n\n";
241
242 $query[0] = $dbh->prepare("SELECT product.id,product.name,
243 product.vId,product.dId,product.svId,product.sdId,
244 vendor.longname,product.vId,
245 bus.name,subclass.name FROM product
246 LEFT JOIN product_area ON product.id=product_area.product_id
247 LEFT JOIN groups ON product_area.group_id=groups.id
248 LEFT JOIN vendor ON product.vendor_id=vendor.id
249 LEFT JOIN bus ON product.bus_id=bus.id
250 LEFT JOIN subclass ON product.subclass_id=subclass.id
251 WHERE groups.name='graphic-developer'
252 AND product_area.valid=1
253 AND product.valid=1")
254 or die "Can\'t select table product";
255 $query[0]->execute or die "Can\'t select table product";
256 while ( ($product_id,$product_name,$vId,$dId,$svId,$sdId,$vendor_name,$vId,$bus_name,$subclass_name) = ($query[0]->fetchrow_array) ) {
257 # Postinitialisierung, falls undefinierte Werte
258 $vId = "----" if !defined($vId);
259 $dId = "----" if !defined($dId);
260 $svId = "----" if !defined($svId);
261 $sdId = "----" if !defined($sdId);
262
263 $vId = "" if $vId eq "----";
264 $dId = "" if $dId eq "----";
265 $svId = "" if $svId eq "----";
266 $sdId = "" if $sdId eq "----";
267
268 # Step 1: Erzeuge Zeilen für XFree 3 ohne 3D
269 get_info $arch_name, "XFree3";
270
271 # Step 2: Erzeuge Zeilen für XFree 3 mit 3D
272 get_info $arch_name, "XFree3 with 3D";
273
274 # Step 2: Erzeuge Zeilen für XFree 4 ohne 3D
275 get_info $arch_name, "XFree4";
276
277 # Step 2: Erzeuge Zeilen für XFree 4 mit 3D
278 get_info $arch_name, "XFree4 with 3D";
279
280 } # Ende der Produktschleife
281 close(FH);
282 } # Ende der Arch-Schleife
283
284
285
286
287 sub multiple_supportedtopics {
288 my $handle = shift;
289 my $product_id = shift;
290 my $product_name = shift;
291 my $arch_name = shift;
292 my $dist_name = shift;
293 my $vario_name = shift;
294 my ($query,$id,$value,$name,$time,$htime,%topic,$key,$answer,%key);
295
296 my $min_key = "0";
297 undef %key;
298
299 print "\n *********** Unconsistency registered *******************";
300 print "\nMultiple supported-topics:";
301 print "\nProduct_name: $product_name ID=$product_id";
302 print "\nArch=$arch_name Dist=$dist_name Vario=$vario_name";
303 print "\n";
304
305 $query = $handle->prepare("SELECT toolproperty.id,tooltopic.name,
306 toolproperty.charvalue,toolproperty.createtime
307 FROM toolproperty
308 LEFT JOIN tooltopic ON toolproperty.tooltopic_id=tooltopic.id
309 LEFT JOIN arch_dist_l_vario ON toolproperty.arch_dist_l_vario_id=arch_dist_l_vario.id
310 LEFT JOIN arch ON arch_dist_l_vario.arch_id=arch.id
311 LEFT JOIN distribution ON arch_dist_l_vario.distribution_id=distribution.id
312 LEFT JOIN vario ON arch_dist_l_vario.vario_id=vario.id
313 WHERE toolproperty.product_id=$product_id
314 AND tooltopic.name='supported'
315 AND toolproperty.valid=1
316 AND arch.name='$arch_name'
317 AND distribution.name='$dist_name'
318 AND vario.name='$vario_name'")
319 or die "Can\'t select table toolproperty";
320 $query->execute or die "Can\'t select table toolproperty";
321 while (($id,$name,$value,$time) = ($query->fetchrow_array)) {
322 $htime = localtime($time);
323 $topic{$id} = $htime." ".$value;
324 $min_key = $id;
325 }
326 foreach $key (sort keys %topic) {
327 $min_key = $key if $key<$min_key;
328 }
329 foreach $key (sort keys %topic) {
330 print "\nD toolproperty-ID $key: $topic{$key}" if $key != $min_key;
331 }
332 print "\n* toolproperty-ID $min_key:$topic{$min_key}";
333 print "\n\nDeleting doublettes marked with D (* will be left the valid one) [N|y] ?";
334 $answer = <STDIN>;
335 chop($answer);
336 if ( ($answer eq "y") || ($answer eq "Y") ) {
337 print "\n\nDeleting supported-doublettes.... done\n";
338 foreach $key (keys %topic) {
339 if ($key != $min_key) {
340 $query = $handle->prepare("DELETE FROM toolproperty
341 WHERE id=$key")
342 or die "Can\'t delete from toolproperty";
343 $query->execute or die "Can\'t delete from toolproperty";
344 }
345 }
346 }
347 return;
348 }
349