[mirrorbrain-commits] [opensuse-svn] r6330 - trunk/tools/download-redirector-v2/scanner

From: Novell Forge SVN <noreply_at_novell.com>
Date: Tue, 3 Feb 2009 02:32:53 -0700 (MST)
Author: poeml
Date: 2009-02-03 02:32:50 -0700 (Tue, 03 Feb 2009)
New Revision: 6330

Modified:
   trunk/tools/download-redirector-v2/scanner/scanner.pl
Log:
scanner:
 - use standard SQL, no MySQL idiosyncrasies
 - allow logging of SQL statements and arguments with -S commandline switch


Modified: trunk/tools/download-redirector-v2/scanner/scanner.pl
===================================================================
--- trunk/tools/download-redirector-v2/scanner/scanner.pl	2009-02-03 09:30:16 UTC (rev 6329)
+++ trunk/tools/download-redirector-v2/scanner/scanner.pl	2009-02-03 09:32:50 UTC (rev 6330)
_at_@ -96,6 +96,7 @@
 my $version = '0.21';
 my $scanner_email = 'poeml_at_suse.de';
 my $verbose = 1;
+my $sqlverbose = 0;
 
 #$DB::inhibit_exit = 0;
 
_at_@ -162,6 +163,7 @@
 	elsif ($arg =~ m{^(-i|--ignore)})      { push _at_norecurse_list, shift; }
 	elsif ($arg =~ m{^-q})                 { $verbose = 0; }
 	elsif ($arg =~ m{^-v})                 { $verbose++; }
+	elsif ($arg =~ m{^-S})                 { $sqlverbose++; }
 	elsif ($arg =~ m{^-a})                 { $all_servers++; }
 	elsif ($arg =~ m{^-j})                 { $parallel = shift; }
 	elsif ($arg =~ m{^-e})                 { $enable_after_scan++; }
_at_@ -228,6 +230,7 @@
 my $dbh = DBI->connect( $db_cred->{dbi}, $db_cred->{user}, $db_cred->{pass}, $db_cred->{opt}) or die $DBI::errstr;
 
 my $sql = qq{SELECT * FROM server where country != '**'};
+print "$sql\n" if $sqlverbose;
 my $ary_ref = $dbh->selectall_hashref($sql, 'id')
 		   or die $dbh->errstr();
 
_at_@ -321,22 +324,22 @@
       $sql .= " AND fileid IN (SELECT id FROM file WHERE path LIKE ?)";
     }
 
-    print "$sql\n" if $verbose > 1;
     # Keep in sync with $start_dir setup above!
     my $sth = $dbh->prepare( $sql );
+    print "$sql  <--- " . length($start_dir) ? "$start_dir/%" : () . " \n" if $sqlverbose;
     $sth->execute(length($start_dir) ? "$start_dir/%" : ()) or die $sth->errstr;
   }
 
   unless ($extra_schedule_run) {
     $sql = "UPDATE server SET last_scan = NOW(), scan_fpm = $fpm WHERE id = $row->{id};";
-    print "$sql\n" if $verbose > 1;
+    print "$sql\n" if $sqlverbose;
     my $sth = $dbh->prepare( $sql );
     $sth->execute() or die $sth->err;
   }
 
   if($enable_after_scan && $file_count > 1 && !$row->{enabled}) {
     $sql = "UPDATE server SET enabled = 1 WHERE id = $row->{id};";
-    print "$sql\n" if $verbose > 1;
+    print "$sql\n" if $sqlverbose;
     my $sth = $dbh->prepare( $sql );
     $sth->execute() or die $sth->err;
     print "server $row->{id} is now enabled.\n" if $verbose > 0;
_at_@ -362,6 +365,7 @@
   -b        MirrorBrain instance to use 
             Default: the first which is defined in the config.
   -v        Be more verbose (Default: $verbose).
+  -S        Show SQL statements.
   -q        Be quiet.
   -l        Do not scan. List enabled mirrors only.
   -ll       As -l, but include disabled mirrors and print urls.
_at_@ -489,7 +493,7 @@
       join(', ', map { "$_ = ".$dbh->quote($fields->{$_}) } keys %$fields) . 
       " WHERE id = $old->[0]{id}";
 
-    print "$sql\n" if $verbose;
+    print "$sql\n" if $sqlverbose;
     $dbh->do($sql) or die "$sql: ".$dbh->errstr;
   }
   else {
_at_@ -511,7 +515,7 @@
     my $sql = "INSERT INTO server SET " . 
       join(', ', map { "$_ = ".$dbh->quote($fields->{$_}) } keys %$fields);
 
-    print "$sql\n" if $verbose;
+    print "$sql\n" if $sqlverbose;
     $dbh->do($sql) or die "$sql: ".$dbh->errstr;
   }
 return 0;
_at_@ -766,21 +770,17 @@
 
 
   if(checkfileserver_fileid($serverid, $fileid)) {
-    my $sql = "UPDATE file_server SET 
-      timestamp_file = FROM_UNIXTIME(?),
-      timestamp_scanner = NOW()
-      WHERE fileid = ? AND serverid = ?;";
+    my $sql = "UPDATE file_server SET timestamp_file = FROM_UNIXTIME(?), timestamp_scanner = NOW() WHERE fileid = ? AND serverid = ?;";
+    my $sth = $dbh->prepare( $sql );
 
-    my $sth = $dbh->prepare( $sql );
+    printf "$sql  <-- $file_tstamp, $fileid, $serverid \n" if $sqlverbose;
     $sth->execute( $file_tstamp, $fileid, $serverid ) or die $sth->errstr;
   }
   else {
-    my $sql = "INSERT INTO file_server SET fileid = ?,
-      serverid = ?,
-      timestamp_file = FROM_UNIXTIME(?), 
-      timestamp_scanner = NOW();";
-    #convert timestamp to mysql timestamp
+    my $sql = "INSERT INTO file_server (fileid, serverid, timestamp_file, timestamp_scanner) VALUES (?, ?, FROM_UNIXTIME(?), NOW());";
     my $sth = $dbh->prepare( $sql );
+
+    printf "$sql  <-- $fileid, $serverid, $file_tstamp \n" if $sqlverbose;
     $sth->execute( $fileid, $serverid, $file_tstamp ) or die $sth->errstr;
   }
   return $path;
_at_@ -823,6 +823,7 @@
   my $path = shift;
 
   my $sql = "SELECT id FROM file WHERE path = " . $dbh->quote($path);
+  printf "$sql\n" if $sqlverbose;
 
   my $ary_ref = $dbh->selectall_arrayref( $sql )
                      or die $dbh->errstr();
_at_@ -830,13 +831,15 @@
 
   return $id if defined $id;
   
-  $sql = "INSERT INTO file SET path = ?;";
+  $sql = "INSERT INTO file (path) VALUES (?);";
+  printf "$sql  <--- $path \n" if $sqlverbose;
 
   my $sth = $dbh->prepare( $sql );
   $sth->execute( $path ) or die $sth->err;
 
   # FIXME: should use last_insert_id rather
   $sql = "SELECT id FROM file WHERE path = " . $dbh->quote($path);
+  printf "$sql\n" if $sqlverbose;
 
   $ary_ref = $dbh->selectall_arrayref( $sql ) or die $dbh->errstr();
 
_at_@ -852,6 +855,7 @@
   my ($serverid, $fileid) = _at__;
 
   my $sql = "SELECT 1 FROM file_server WHERE fileid = $fileid AND serverid = $serverid;";
+  printf "$sql\n" if $sqlverbose;
   my $ary_ref = $dbh->selectall_arrayref($sql) or die $dbh->errstr();
 
   return defined($ary_ref->[0]) ? 1 : 0;

_______________________________________________
Opensuse-svn mailing list
Opensuse-svn_at_forge.novell.com
http://forge.novell.com/mailman/listinfo/opensuse-svn


_______________________________________________
mirrorbrain-commits mailing list

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Tue Feb 03 2009 - 09:33:28 GMT

This archive was generated by hypermail 2.3.0 : Thu Mar 25 2010 - 19:29:04 GMT