From: Dobrica Pavlinusic Date: Tue, 26 Apr 2005 20:17:14 +0000 (+0000) Subject: added examples for Strix portal (www.strix-portal.com) X-Git-Url: http://git.rot13.org/?p=Fuse-DBI;a=commitdiff_plain;h=eee0ed86b45c442607a99cf0da11aa1d8ffead87 added examples for Strix portal (strix-portal.com) git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@56 17f4e80c-d0e0-0310-8903-bfc3ae804c12 --- diff --git a/examples/strix-multi_static.pl b/examples/strix-multi_static.pl new file mode 100755 index 0000000..5a22ab8 --- /dev/null +++ b/examples/strix-multi_static.pl @@ -0,0 +1,116 @@ +#!/usr/bin/perl -w + +use strict; +use blib; +use Fuse::DBI; +use blib; + +=head1 NAME + +strix.pl - mount Strix database as filesystem + +=head1 SYNOPSIS + + strix.pl database /mnt + +=head1 DESCRIPTION + +With this script, you can utilize C and C modules to mount +content from Strix - knowledge owl portal and edit them using command-line +utilities (like C or C). + +=cut + +my ($database,$mount) = @ARGV; + +unless ($database && $mount) { + print STDERR <<_USAGE_; +usage: $0 database /mnt + +For more information see perldoc $0 +_USAGE_ + exit 1; +} + +system "fusermount -u $mount" unless (-w $mount); + +unless (-w $mount) { + print STDERR "Current user doesn't have permission on mount point $mount: $!"; + exit 1; +} + +my $sql = { + 'filenames' => q{ + select + id as id, + id||'-'||title||'.html' as filename, + length(content) as size, + true as writable + from multistatic + }, + 'read' => q{ + select content + from multistatic + where id = ?; + }, + 'update' => q{ + update multistatic + set content = ? + where id = ?; + }, +}; + +my $dsn = 'DBI:Pg:dbname='.$database; +my $db; + +print "using database '$dsn', mountpoint $mount\n"; + +my $mnt = Fuse::DBI->mount({ + filenames => $sql->{'filenames'}, + read => $sql->{'read'}, + update => $sql->{'update'}, + dsn => $dsn, + user => '', + password => '', + mount => $mount, + fork => 1, +# invalidate => sub { +# print STDERR "invalidating content in $template_dir\n"; +# opendir(DIR, $template_dir) || die "can't opendir $template_dir: $!"; +# map { unlink "$template_dir/$_" || warn "can't remove $template_dir/$_: $!" } grep { !/^\./ && -f "$template_dir/$_" } readdir(DIR); +# closedir DIR; +# }, +}); + +if (! $mnt) { + print STDERR "can't mount filesystem!"; + exit 1; +} + +print "Press enter to exit..."; +my $foo = ; + +$mnt->umount; + +=head1 SEE ALSO + +C website +L + +C website +L + +=head1 AUTHOR + +Dobrica Pavlinusic, Edpavlin@rot13.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2004 by Dobrica Pavlinusic + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.4 or, +at your option, any later version of Perl 5 you may have available. + +=cut + diff --git a/examples/strix-static3.pl b/examples/strix-static3.pl new file mode 100755 index 0000000..f49c947 --- /dev/null +++ b/examples/strix-static3.pl @@ -0,0 +1,116 @@ +#!/usr/bin/perl -w + +use strict; +use blib; +use Fuse::DBI; +use blib; + +=head1 NAME + +strix.pl - mount Strix database as filesystem + +=head1 SYNOPSIS + + strix.pl database /mnt + +=head1 DESCRIPTION + +With this script, you can utilize C and C modules to mount +content from Strix - knowledge owl portal and edit them using command-line +utilities (like C or C). + +=cut + +my ($database,$mount) = @ARGV; + +unless ($database && $mount) { + print STDERR <<_USAGE_; +usage: $0 database /mnt + +For more information see perldoc $0 +_USAGE_ + exit 1; +} + +system "fusermount -u $mount" unless (-w $mount); + +unless (-w $mount) { + print STDERR "Current user doesn't have permission on mount point $mount: $!"; + exit 1; +} + +my $sql = { + 'filenames' => q{ + select + layout_id as id, + layout_id||'-'||title||'.html' as filename, + length(content) as size, + true as writable + from static3 + }, + 'read' => q{ + select content + from static3 + where layout_id = ?; + }, + 'update' => q{ + update static3 + set content = ? + where layout_id = ?; + }, +}; + +my $dsn = 'DBI:Pg:dbname='.$database; +my $db; + +print "using database '$dsn', mountpoint $mount\n"; + +my $mnt = Fuse::DBI->mount({ + filenames => $sql->{'filenames'}, + read => $sql->{'read'}, + update => $sql->{'update'}, + dsn => $dsn, + user => '', + password => '', + mount => $mount, + fork => 1, +# invalidate => sub { +# print STDERR "invalidating content in $template_dir\n"; +# opendir(DIR, $template_dir) || die "can't opendir $template_dir: $!"; +# map { unlink "$template_dir/$_" || warn "can't remove $template_dir/$_: $!" } grep { !/^\./ && -f "$template_dir/$_" } readdir(DIR); +# closedir DIR; +# }, +}); + +if (! $mnt) { + print STDERR "can't mount filesystem!"; + exit 1; +} + +print "Press enter to exit..."; +my $foo = ; + +$mnt->umount; + +=head1 SEE ALSO + +C website +L + +C website +L + +=head1 AUTHOR + +Dobrica Pavlinusic, Edpavlin@rot13.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2004 by Dobrica Pavlinusic + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.4 or, +at your option, any later version of Perl 5 you may have available. + +=cut +