id3fsd verbosity: -v => sql, -vv => fuse debugging
authorIan Beckwith <ianb@erislabs.net>
Sun, 17 Oct 2010 02:59:35 +0000 (03:59 +0100)
committerIan Beckwith <ianb@erislabs.net>
Sun, 17 Oct 2010 02:59:35 +0000 (03:59 +0100)
lib/ID3FS/Fuse.pm
lib/ID3FS/Path.pm
sbin/id3fsd

index 50e7060..14304f7 100644 (file)
@@ -18,7 +18,7 @@ sub new
     $self->{db}=shift;
     $self->{source}=shift;
     $self->{mountpoint}=Cwd::abs_path(shift);
-    $self->{debug}=shift;
+    $self->{verbose}=shift;
     $self->{perms} = S_IRUSR() | S_IXUSR() | S_IRGRP() | S_IXGRP() | S_IROTH() | S_IXOTH();
 
     return $self;
@@ -30,7 +30,7 @@ sub run
     Fuse::main(
        mountpoint  => $self->{mountpoint},
        threaded    => 0,
-       debug       => $self->{debug},
+       debug       => ($self->{verbose} > 1),
        mountopts   => "allow_other,ro",
        getattr     => sub { $self->getattr(@_); },
        readlink    => sub { $self->readlink(@_); },
@@ -65,7 +65,7 @@ sub getattr
 {
     my($self, $filename)=@_;
 #    print "**GETATTR: $filename\n";
-    my $path=ID3FS::Path->new($self->{db}, $filename);
+    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose});
     my $last_update=$self->{db}->last_update();
     return(-ENOENT()) unless($path->isvalid());
     my($dev,$ino,$nlink)=(0,0,1);
@@ -83,7 +83,7 @@ sub readlink
 {
     my($self,$filename)=@_;
 #    print "**READLINK: $filename\n";
-    my $path=ID3FS::Path->new($self->{db}, $filename);
+    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose});
     return(-EINVAL()) unless($path->isfile());
     return $path->dest($self->{mountpoint});
 }
@@ -92,7 +92,7 @@ sub getdir
 {
     my($self, $filename)=@_;
 #    print "**GETDIR: $filename\n";
-    my $path=ID3FS::Path->new($self->{db}, $filename);
+    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose});
     return(-ENOENT()) unless($path->isvalid());
     return(-ENOTDIR()) unless($path->isdir());
     my @dents=();
index 8284a98..60b628f 100644 (file)
@@ -30,6 +30,7 @@ sub new
     $self->{elements}=[];
     $self->{db}=shift;
     $self->{path}=shift;
+    $self->{verbose}=shift;
     $self->{path} =~ s/\/\//\//g; # drop doubled slashes
 
     $self->parse();
@@ -561,9 +562,9 @@ sub tags
        $sql .= "WHERE " . join(' AND ', @andclauses) . "\n";
     }
     $sql .= "GROUP BY tags.name;";
-#    print "SQL(TAGS): $sql\n";
+    print "SQL(TAGS): $sql\n" if($self->{verbose});
     my @tagnames=$self->{db}->cmd_firstcol($sql);
-#    print "SUBNAMES: ", join(', ', @tagnames), "\n";
+    print("SUBNAMES: ", join(', ', @tagnames), "\n") if($self->{verbose});
     return(@tagnames);
 }
 
@@ -593,9 +594,9 @@ sub artists
             "INNER JOIN artists ON files.artists_id=artists.id\n" .
             "WHERE artists.name != ''\n" .
             "GROUP BY artists.name;");
-#    print "SQL(ARTISTS): $sql\n";
+    print "SQL(ARTISTS): $sql\n" if($self->{verbose});
     my @tagnames=$self->{db}->cmd_firstcol($sql);
-    print "ARTISTS: ", join(', ', @tagnames), "\n";
+    print("ARTISTS: ", join(', ', @tagnames), "\n") if($self->{verbose});
     return(@tagnames);
 }
 
@@ -625,9 +626,9 @@ sub albums
              "WHERE albums.name != ''\n" .
              "GROUP BY albums.name;");
     }
-#    print "SQL(ALBUMS): \n$sql\n";
+    print "SQL(ALBUMS): \n$sql\n" if($self->{verbose});
     my @names=$self->{db}->cmd_firstcol($sql);
-    print "ALBUMS: ", join(', ', @names), "\n";
+    print("ALBUMS: ", join(', ', @names), "\n") if($self->{verbose});
     return(@names);
 }
 
@@ -650,9 +651,9 @@ sub artist_albums
             "INNER JOIN artists ON artists.id=files.artists_id\n" .
             "WHERE artists.id=? and albums.name <> ''\n" .
             "GROUP BY albums.name\n");
-#    print "ARTIST_ALBUMS SQL: $sql\n";
+    print "ARTIST_ALBUMS SQL: $sql\n" if($self->{verbose});
     my @albums=$self->{db}->cmd_firstcol($sql, $artist_id);
-    print "ALBUMS: ", join(', ', @albums), "\n";
+    print("ALBUMS: ", join(', ', @albums), "\n") if($self->{verbose});
     return(@albums);
 }
 
@@ -675,9 +676,9 @@ sub artist_tracks
             "INNER JOIN albums  ON albums.id=files.albums_id\n" .
             "WHERE artists.id=? AND albums.name=''\n" .
             "GROUP BY files.name\n");
-#    print "ARTIST_TRACKS SQL: $sql\n";
+    print "ARTIST_TRACKS SQL: $sql\n" if($self->{verbose});
     my @names=$self->{db}->cmd_firstcol($sql, $artist_id);
-    print "ARTISTTRACKS: ", join(', ', @names), "\n";
+    print("ARTISTTRACKS: ", join(', ', @names), "\n") if($self->{verbose});
     return(@names);
 }
 
@@ -689,9 +690,9 @@ sub album_tracks
             "INNER JOIN artists ON artists.id=files.artists_id\n" .
             "WHERE artists.id=? AND albums.id=?\n" .
             "GROUP BY files.name\n");
-#    print "ALBUM_TRACKS SQL($artist_id, $album_id): $sql\n";
+    print "ALBUM_TRACKS SQL($artist_id, $album_id): $sql\n" if($self->{verbose});
     my @names=$self->{db}->cmd_firstcol($sql, $artist_id, $album_id);
-    print "TRACKS: ", join(', ', @names), "\n";
+    print("TRACKS: ", join(', ', @names), "\n") if($self->{verbose});
     return(@names);
 }
 
@@ -733,9 +734,9 @@ sub tracks
        $sql .= "WHERE artists.name =''\n";
     }
     $sql .= "GROUP BY files.name;";
-#    print "TRACKS SQL($self->{path}): $sql\n";
+    print "TRACKS SQL($self->{path}): $sql\n" if($self->{verbose});
     my @names=$self->{db}->cmd_firstcol($sql);
-    print "TRACKS: ", join(', ', @names), "\n";
+    print("TRACKS: ", join(', ', @names), "\n") if($self->{verbose});
     return(@names);
 }
 
@@ -750,7 +751,7 @@ sub filename
                 "INNER JOIN paths ON files.paths_id=paths.id\n" .
                 "WHERE files.id=?\n" .
                 "GROUP BY paths.name, files.name");
-#      print "FILENAME SQL: $sql\n";
+       print "FILENAME SQL: $sql\n" if($self->{verbose});
        my ($path, $name)=$self->{db}->cmd_onerow($sql, $id);
        my $id3fs_path=join('/', map { $_->{name}; }  @{$self->{elements}});
        return($self->{db}->relativise($path, $name, $mountpoint, $id3fs_path));
@@ -1034,7 +1035,7 @@ sub empty
     my($self, $dir, $maxdepth)=@_;
     return 1 unless($maxdepth);
 #    print "testing($maxdepth): $dir\n";
-    my $path=ID3FS::Path->new($self->{db}, $dir);
+    my $path=ID3FS::Path->new($self->{db}, $dir, $self->{verbose});
 #    print "PATH INVALID\n" unless($path->isvalid());
     return 1 unless($path->isvalid());
     my($subdirs,$subfiles)=$path->dirents();
index a5eae12..8331e13 100755 (executable)
@@ -17,8 +17,7 @@ my $dbpath=undef;
 
 Configure(qw(bundling no_ignore_case));
 my $optret=GetOptions(
-    "verbose|v"    => \$verbose,
-    "quiet|q"      => sub { $verbose=0; },
+    "verbose|v"    => sub { $verbose++; },
     "help|h"       => \$help,
     "database|f=s" => \$dbpath,
     );
@@ -37,8 +36,7 @@ $fuse->run();
 sub usage
 {
     die("Usage: $me [-vqh] [-f <dbfile>] [--] <sourcedir> <mountpoint>\n".
-       " -v\t\t\tVerbose\n".
-       " -q\t\t\tQuiet (default)\n".
+       " -v\t\t\tVerbose (repeat for more verbosity)\n".
        " -h\t\t\tThis help\n".
        " -f|--database=FILE\tPath to database file\n" .
        " --\t\t\tEnd of options\n");
@@ -52,7 +50,7 @@ id3fsd - FUSE filesystem for browsing id3 tags
 
 =head1 SYNOPSIS
 
-B<id3fsd> [B<-vqh>] S<B<[-f >I<dbfile>]> [B<-->] I<SOURCEDIR> I<MOUNTPOINT>
+B<id3fsd> [B<-vh>] S<B<[-f >I<dbfile>]> [B<-->] I<SOURCEDIR> I<MOUNTPOINT>
 
 =head1 DESCRIPTION
 
@@ -76,11 +74,7 @@ FIXME: better description, allow_others/fuse.conf, fstab, explain genre tag
 
 =item B<-v>
 
-Enable verbose operation.
-
-=item B<-q>
-
-Quiet (no output). This is the default.
+Enable verbose operation. Repeat for more verbosity.
 
 =item B<-h>