OSSP CVS Repository

ossp - Difference in ossp-pkg/quos/openpkg-rdf2sql.pl versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/quos/openpkg-rdf2sql.pl 1.1 -> 1.2

--- openpkg-rdf2sql.pl   2004/10/25 14:35:11     1.1
+++ openpkg-rdf2sql.pl   2004/11/08 15:26:01     1.2
@@ -30,8 +30,108 @@
 use XML::Parser;
 use DBI;
 use DBD::SQLite;
+use Data::Dumper;
+use XML::Simple;
 
-#   ...FIXME...
+#   configure optional debugging
+$Data::Dumper::Purity = 1;
+$Data::Dumper::Indent = 1;
+$Data::Dumper::Terse  = 1;
+
+my $rdf = XML::Simple::XMLin(
+    "openpkg.rdf",
+    KeepRoot     => 1,
+    ForceContent => 0,
+    ForceArray   => 1,
+);
+#print Dumper($xml);
+#exit(0);
+
+#   connect to database
+my $db = DBI->connect("dbi:SQLite:dbname=openpkg.db", "", "",
+                      { RaiseError => 1, AutoCommit => 1 });
+
+#   prepare SQL commands
+my $sql = {};
+$sql->{-rdf} = $db->prepare(
+    "INSERT INTO quos_rdf (rd_url) VALUES (?);"
+);
+$sql->{-package} = $db->prepare(
+    "INSERT INTO quos_package" .
+    " (pk_name, pk_version, pk_release, pk_distribution, pk_group," .
+    "  pk_license, pk_packager, pk_summary, pk_url, pk_vendor, pk_description, pk_rdf)" .
+    " VALUES (?,?,?,?,?,?,?,?,?,?,?,(SELECT MAX(rd_id) FROM quos_rdf));\n"
+);
+$sql->{-buildprereq} = $db->prepare(
+    "INSERT INTO quos_buildprereq" .
+    " (bp_id, bp_key, bp_op, bp_val)" .
+    " VALUES ((SELECT MAX(pk_id) FROM quos_package),?,?,?);" 
+);
+$sql->{-prereq} = $db->prepare(
+    "INSERT INTO quos_prereq" .
+    " (rp_id, rp_key, rp_op, rp_val)" .
+    " VALUES ((SELECT MAX(pk_id) FROM quos_package),?,?,?);" 
+);
+$sql->{-provide} = $db->prepare(
+    "INSERT INTO quos_provide" .
+    " (pr_id, pr_key, pr_op, pr_val)" .
+    " VALUES ((SELECT MAX(pk_id) FROM quos_package),?,?,?);" 
+);
+$sql->{-source} = $db->prepare(
+    "INSERT INTO quos_source" .
+    " (sr_id, sr_url)" .
+    " VALUES ((SELECT MAX(pk_id) FROM quos_package),?);" 
+);
+
+#   iterate over XML/RDF data structure
+foreach my $repo (@{$rdf->{'rdf:RDF'}->[0]->{'Repository'}}) {
+    my $rd_url = $repo->{'rdf:resource'};
+
+    #   store repository information
+    $db->begin_work();
+    $sql->{-rdf}->execute($rd_url);
+
+    #   interate over all packages in a repository
+    foreach my $desc (@{$repo->{'rdf:Description'}}) {
+        #   store simple (single-value) properties of a package
+        my $prop = {};
+        foreach my $attr (qw(
+            Name Version Release Distribution Group License
+            Packager Summary URL Vendor Description
+        )) {
+            $prop->{$attr} = $desc->{$attr}->[0];
+        }
+        $sql->{-package}->execute(
+            $prop->{'Name'}, $prop->{'Version'}, $prop->{'Release'}, $prop->{'Distribution'}, $prop->{'Group'},
+            $prop->{'License'}, $prop->{'Packager'}, $prop->{'Summary'}, $prop->{'URL'}, $prop->{'Vendor'},
+            $prop->{'Description'}
+        );
+
+        #   store complex (multi-value) properties of a package
+        foreach my $attr (qw(
+            BuildPreReq
+            PreReq
+            Provide
+        )) {
+            foreach my $el (@{$desc->{$attr}->[0]->{'rdf:bag'}->[0]->{'resource'}}) {
+                my ($key, $op, $val) = ($el, '=', '*');
+                if (ref($key) eq 'HASH') {
+                    $key = $el->{'content'};
+                    $op  = (grep { $_ ne 'content' } keys(%{$el}))[0];
+                    $val = $el->{$op};
+                }
+                $sql->{"-".lc($attr)}->execute($key, $op, $val);
+            }
+        }
+        foreach my $url (@{$desc->{'Source'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}}) {
+            $sql->{-source}->execute($url);
+        }
+    }
+    $db->commit();
+}
+
+#   disconnect from database
+$db->disconnect();
 
 __END__
 

CVSTrac 2.0.1