]> mj.ucw.cz Git - pciids.git/blob - scripts/feeddb.pl
Remove useless directories
[pciids.git] / scripts / feeddb.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 BEGIN {
6         unshift @INC, ".";
7 }
8 use PciIds::Db;
9 use DBI;
10
11 my $dbh = connectDb();
12 my $query = $dbh->prepare( "INSERT INTO locations (id, name, description, parent) VALUES(?, ?, ?, ?);" ) or die "Could not create the query (".DBI->errstr.")\n";
13 my $comment = $dbh->prepare( "INSERT INTO history (location, nodename, nodedescription, seen) VALUES(?, ?, ?, '1')" ) or die "Could not create query (".DBI->errstr.")\n";
14 my $update = $dbh->prepare( "UPDATE locations SET maincomment = ? WHERE id = ?" ) or die "Could not create query (".DBI->errstr.")\n";
15 my( $vendor, $type, $sub, $description, $name );
16
17 $query->execute( "PC", undef, undef, undef ) or die "Could not add toplevel node\n";
18 $query->execute( "PD", undef, undef, undef ) or die "Could not add toplevel node\n";
19
20 sub submit( $ ) {
21         my( $id ) = @_;
22         my $parent = $id;
23         $parent =~ s/\/[^\/]+$//;
24         $query->execute( $id, $name, $description, $parent );
25         $comment->execute( $id, $name, $description );
26         my $com = $dbh->last_insert_id( undef, undef, undef, undef );
27         $update->execute( $com, $id );
28         undef $description;
29 }
30
31 print "Filling database from id file\n";
32
33 foreach( <> ) {
34         chomp;
35         if( s/^\s*#\s*// ) {
36                 $description = $_;
37         } elsif( /^\s*$/ ) {
38                 undef $description;
39         } elsif( /^\t\t/ ) {
40                 if( $vendor =~ /^PC/ ) {
41                         ( $sub, $name ) = /^\s*([0-9a-fA-F]+\s[0-9a-fA-F]+)\s+(.*)$/;
42                         $sub =~ s/\s+//g;
43                 } else {
44                         ( $sub, $name ) = /^\s*([0-9a-fA-F]+)\s+(.*)$/;
45                 }
46                 submit( $vendor.'/'.$type.'/'.$sub );
47         } elsif( /^\t/ ) {
48                 ( $type, $name ) = /^\s*([0-9a-fA-F]+)\s+(.*)$/;
49                 submit( $vendor.'/'.$type );
50         } elsif( /^C\s/ ) {
51                 ( $vendor, $name ) = /^C\s+([0-9a-fA-F]+)\s+(.*)$/;
52                 $vendor = 'PD/'.$vendor;
53                 submit( $vendor );
54         } elsif( /^[0-9a-fA-F]/ ) {
55                 ( $vendor, $name ) = /([0-9a-fA-F]+)\s+(.*)$/;
56                 $vendor = 'PC/'.$vendor;
57                 submit( $vendor );
58         } else {
59                 die "Um what?? $_\n";
60         }
61 }
62 $dbh->commit();
63 $dbh->disconnect;