diff --git a/perl/Gnome-Tomboy/.gitignore b/perl/Gnome-Tomboy/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..dd6181faeb01a0d23f8a6527457c32a1e890c08f --- /dev/null +++ b/perl/Gnome-Tomboy/.gitignore @@ -0,0 +1 @@ +Tomboy-TOC.csv diff --git a/perl/Gnome-Tomboy/lib/Tomboy/Directory.pm b/perl/Gnome-Tomboy/lib/Tomboy/Directory.pm new file mode 100644 index 0000000000000000000000000000000000000000..30264191a56652297a0402f4c7241a05f6bc7fb3 --- /dev/null +++ b/perl/Gnome-Tomboy/lib/Tomboy/Directory.pm @@ -0,0 +1,89 @@ +# +# scan directory with note files in Tomboy format +# + +=head1 NAME + + Tomboy::Directory; + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +process a directory containing note files in Tomboy format + +=cut + +package Tomboy::Directory; + +use strict; + +use Tomboy::Note::Simple; + +my @TB_note_attrs= qw(title create-date last-change-date last-metadata-change-date); +my @TB_meta_attrs= qw(uid notebook); +sub TB_attrs { return (@TB_meta_attrs, @TB_note_attrs) } + +sub new +{ + my $class= shift; + my %par= @_; + + my $obj= {}; + bless $obj, $class; + + foreach my $par (keys %par) + { + $obj->{$par}= $par{$par}; + if ($par eq 'dir') { $obj->scan_dir ($par{$par}) } + } + + $obj; +} + +sub scan_dir +{ + my $obj= shift; + my $dir= shift; + + unless (opendir (DIR, $dir)) + { + print "ATTN: can't read directory [$dir]\n"; + return undef; + } + + my @res= (); + NOTE: while (my $e= readdir (DIR)) + { + next NOTE if ($e eq '.' || $e eq '..'); + next NOTE unless ($e =~ /(.+)\.note$/); + my $uid= $1; + + my $fp= join ('/', $dir, $e); + # print "reading note [$fp]\n"; # TODO: if verbose... + my $n= parse Tomboy::Note::Simple ($fp); + + unless (defined ($n)) + { + print "ATTN: parsing [$fp] returned undefined note!\n"; + next NOTE; + } + + my %rec= map { $_ => $n->{$_} } @TB_note_attrs; + $rec{'uid'}= $uid; + + foreach my $tag (@{$n->{'tags'}}) + { + if ($tag =~ m#system:notebook:(.+)#) { $rec{'notebook'}= $1 } + } + + push (@res, \%rec); + } + + closedir (DIR); + + (wantarray) ? @res : \@res; +} + +1; + diff --git a/perl/Gnome-Tomboy/lib/Tomboy/Note/Simple.pm b/perl/Gnome-Tomboy/lib/Tomboy/Note/Simple.pm index b6c96a8a7d797644432f3adb964e2fbe4651723e..048bc7fd009f4d491d8e37046084034738db0890 100755 --- a/perl/Gnome-Tomboy/lib/Tomboy/Note/Simple.pm +++ b/perl/Gnome-Tomboy/lib/Tomboy/Note/Simple.pm @@ -88,10 +88,11 @@ sub parse my $fnm= shift; my $note; + if (ref ($c) eq 'Tomboy::Note::Simple') { $note= $c; } elsif (ref ($c) eq '') { - print "create new c=[$c]\n"; + # print "create new c=[$c]\n"; $note= new Tomboy::Note::Simple; } else @@ -99,6 +100,7 @@ sub parse print "unknown c=[$c] r=[", ref ($c), "]\n"; } # print "note=[$note]\n"; + $note->{'fnm'}= $fnm; my $p= new XML::Parser (Style => 'Tree'); @@ -170,4 +172,9 @@ __END__ Gerhard Gonter <ggonter@gmail.com> +=head1 BUGS + +* XML::Parser throws exceptions, these are currently not handled. + =cut + diff --git a/perl/Gnome-Tomboy/s2.pl b/perl/Gnome-Tomboy/s2.pl new file mode 100755 index 0000000000000000000000000000000000000000..8158829446d73e8fd6f27f84201327cf18fbfc8e --- /dev/null +++ b/perl/Gnome-Tomboy/s2.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use strict; + +use lib 'lib'; + +use Util::Simple_CSV; +use Data::Dumper; +$Data::Dumper::Indent= 1; + +# use Tomboy::Note::Simple; +use Tomboy::Directory; + +my $note_dir= shift (@ARGV); +my $toc_file= 'Tomboy-TOC.csv'; + +die "no note dir specified" unless ($note_dir); + +my $tb_d= new Tomboy::Directory ('dir' => $note_dir); + +print "tb_d: ", Dumper ($tb_d); + +my $toc_data= $tb_d->scan_dir ($note_dir); +# TODO: if verbose or so print "toc_data: ", Dumper ($toc_data); + +my $toc= new Util::Simple_CSV ('UTF8' => 1, 'no_hash' => 1); +$toc->define_columns (Tomboy::Directory::TB_attrs()); +$toc->{'data'}= $toc_data; +$toc->save_csv_file ('filename' => $toc_file); + +exit (0); +