Skip to content
Snippets Groups Projects
Commit 82e3d0ac authored by Gerhard Gonter's avatar Gerhard Gonter :speech_balloon:
Browse files

search function in test script

parent 01c4b19b
No related branches found
No related tags found
No related merge requests found
...@@ -24,13 +24,20 @@ $Data::Dumper::Indent= 1; ...@@ -24,13 +24,20 @@ $Data::Dumper::Indent= 1;
use Tomboy::Directory; use Tomboy::Directory;
my $toc_file= 'Tomboy-TOC.csv'; my $toc_file= 'Tomboy-TOC.csv';
my $note_dir= '~/Tomboy';
my $mode= 'scan';
my $start_tb= 0;
my @PAR= (); my @PAR= ();
while (my $arg= shift (@ARGV)) while (my $arg= shift (@ARGV))
{ {
if ($arg =~ /^-/) if ($arg =~ /^-/)
{ {
usage(); if ($arg eq '-f') { $mode= 'find'; }
elsif ($arg eq '-d') { $note_dir= shift (@ARGV); }
elsif ($arg eq '-e') { $start_tb= 1; }
else { usage(); }
} }
else else
{ {
...@@ -38,20 +45,143 @@ while (my $arg= shift (@ARGV)) ...@@ -38,20 +45,143 @@ while (my $arg= shift (@ARGV))
} }
} }
my $note_dir= shift (@PAR); my $bli= new bli('note_dir' => $note_dir, 'toc_file' => $toc_file);
die "no note dir specified" unless ($note_dir); print "bli: ", Dumper ($bli);
if ($mode eq 'scan')
{
$bli->scan_dir();
}
elsif ($mode eq 'find')
{
my %uuid;
foreach my $pattern (@PAR)
{
my @res= $bli->find ($pattern);
foreach my $res (@res) { $uuid{$res->{'uuid'}}= $res; } # TODO: count hits
}
foreach my $uuid (keys %uuid)
{
if ($start_tb)
{
start_tb ('uuid', $uuid);
}
else
{
print Dumper ($uuid{$uuid});
}
}
}
=begin comment
hmm... starting Tomboy does not work as expected. When tomboy is
already running, calling it is fine, otherwise, it has to be started
in the background and given some time before it can be called again.
Probably it would make sense to do something with D-Bus here...
=end comment
=cut
sub start_tb
{
my $what= shift;
my $par= shift;
if ($what eq 'uuid')
{
my @cmd= ('tomboy', '--open-note', 'note://tomboy/'. $par);
print ">>> ", join (' ', @cmd), "\n";
my $pid= fork();
if ($pid == 0) { exec @cmd; }
print "started pid=[$pid]\n";
}
}
exit (0);
package bli;
sub new
{
my $class= shift;
my $self= {};
bless $self, $class;
$self->set (@_);
$self;
}
sub set
{
my $self= shift;
my %par= @_;
foreach my $par (keys %par) { $self->{$par}= $par{$par}; }
}
sub find
{
my $self= shift;
my $pattern= shift;
print "find: pattern=[$pattern]\n";
my ($mode, $toc, $rows)= $self->load_toc();
my @res;
foreach my $row (@$rows)
{
next unless ($row->{'title'} =~ m#$pattern#i);
# print "row: ", main::Dumper ($row);
push (@res, $row);
}
@res;
}
sub scan_dir
{
my $self= shift;
print main::Dumper ($self);
my ($note_dir, $toc_file)= map { $self->{$_} } qw(note_dir toc_file);
$note_dir=~ s#/+$##; $note_dir=~ s#/+$##;
my $tb_d= new Tomboy::Directory (); my $tb_d= new Tomboy::Directory ();
print "tb_d: ", Dumper ($tb_d); # print "tb_d: ", Dumper ($tb_d);
print "scanning [$note_dir]\n";
my $toc= new Util::Simple_CSV ('UTF8' => 1, 'no_array' => 1, 'separator' => "\t", 'UTF8' => 1); my ($mode, $toc, $rows)= $self->load_toc();
my $toc_data= $tb_d->scan_dir ($note_dir, $rows, $mode);
# TODO: if verbose or so print "toc_data: ", Dumper ($toc_data);
$toc->{'data'}= $toc_data;
# TODO: optionally sort the returned values
$toc->sort ('uuid');
# print "toc: ", Dumper ($toc);
$toc->save_csv_file ('filename' => $toc_file, 'separator' => "\t", 'UTF8' => 1);
}
sub load_toc
{
my $self= shift;
my $mode= 0; my $mode= 0;
my $rows= []; my $toc;
print "load_toc\n";
return (1, $toc, $toc->{'data'}) if (defined ($toc= $self->{'_toc'}));
my ($toc_file)= map { $self->{$_} } qw(toc_file);
print "load_toc: toc_file=[$toc_file]\n";
my $toc= new Util::Simple_CSV ('UTF8' => 1, 'no_array' => 1, 'separator' => "\t", 'UTF8' => 1);
my $rows= [];
if (-f $toc_file) if (-f $toc_file)
{ {
print "loading $toc_file\n";
$toc->load_csv_file ($toc_file); $toc->load_csv_file ($toc_file);
$mode= 1; $mode= 1;
...@@ -63,20 +193,12 @@ if (-f $toc_file) ...@@ -63,20 +193,12 @@ if (-f $toc_file)
} }
else else
{ {
# $toc->define_columns (Tomboy::Directory::TB_attrs()); $toc->define_columns (Tomboy::Directory::TB_attrs());
$toc->define_columns ($tb_d->TB_attrs());
} }
$self->{'_toc'}= $toc;
my $toc_data= $tb_d->scan_dir ($note_dir, $rows, $mode); ($mode, $toc, $rows);
# TODO: if verbose or so print "toc_data: ", Dumper ($toc_data); }
$toc->{'data'}= $toc_data;
# TODO: optionally sort the returned values
$toc->sort ('uuid');
# print "toc: ", Dumper ($toc);
$toc->save_csv_file ('filename' => $toc_file, 'separator' => "\t", 'UTF8' => 1);
exit (0);
__END__ __END__
...@@ -86,6 +208,15 @@ __END__ ...@@ -86,6 +208,15 @@ __END__
* cache the data in ~/.gcache ?? check out how this is supposed to work * cache the data in ~/.gcache ?? check out how this is supposed to work
* optionally, integrate with version control for quick synchronization * optionally, integrate with version control for quick synchronization
=head1 NOTES
=head2 Directories used by Tomboy on Ubuntu
* ~/.cache/tomboy/ ... empty
* ~/.gconf/tomboy/
%gconf.xml
* ~/.config/tomboy/ ... various stuff
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment