annotate auto-weave.pl @ 16:f433fae15c50

made auto-weave work on all projects
author Robert McIntyre <rlm@mit.edu>
date Wed, 02 Nov 2011 05:01:57 -0700
parents 6ef9ccf7a17e
children 6da973a6b93d
rev   line source
rlm@6 1 #!/usr/bin/perl
rlm@6 2
rlm@6 3 use Linux::Inotify2;
rlm@11 4 use WWW::Mechanize::Firefox;
rlm@11 5 my $mech = WWW::Mechanize::Firefox->new();
rlm@6 6
rlm@6 7 my $inotify = new Linux::Inotify2
rlm@6 8 or die "unable to create new inotify object: $!";
rlm@6 9
rlm@6 10
rlm@16 11 $org_files = `find /home/r/proj -name "*.org" -print0`;
rlm@16 12 @org_files = split /\0/, $org_files;
rlm@6 13
rlm@16 14 #@org_files = glob("./org/*.org");
rlm@16 15
rlm@16 16 for $file(@org_files){print "$file\n";}
rlm@9 17 $ignore_next = 0;
rlm@9 18
rlm@6 19
rlm@6 20 foreach(@org_files){
rlm@6 21 # add watchers
rlm@6 22 $inotify->watch ($_, IN_MODIFY, sub
rlm@6 23 {
rlm@9 24 print ("IGNORE : $ignore_next\n");
rlm@15 25 # ok, for some reason this gets called exactly
rlm@9 26 # twice every time the file is saved from emacs.
rlm@9 27 # so ignore every other invocation.
rlm@9 28 if ($ignore_next) {
rlm@9 29 $ignore_next = 0;
rlm@9 30 return;
rlm@9 31 }
rlm@13 32 $ignore_next = 1;
rlm@9 33
rlm@9 34 my $e = shift;
rlm@9 35 my $name = $e->fullname;
rlm@9 36 print "$name was modified\n" if $e->IN_MODIFY;
rlm@9 37 $output = `weave $name`;
rlm@9 38 $path = `readlink -f $name`;
rlm@9 39 $path =~ s|/home/r/proj|http://aurellem.localhost|;
rlm@9 40 $path =~ s|org|html|g;
rlm@11 41 $mech->get($path);
rlm@6 42 });
rlm@6 43 }
rlm@6 44
rlm@6 45
rlm@13 46 # manual event loop
rlm@6 47 1 while $inotify->poll;