annotate auto-weave.pl @ 23:88d986bf127b

change perms.
author Robert McIntyre <rlm@mit.edu>
date Thu, 13 Jun 2013 22:00:59 -0400
parents c14f3a4af7fd
children
rev   line source
rlm@6 1 #!/usr/bin/perl
rlm@6 2
rlm@6 3 use Linux::Inotify2;
rlm@19 4 use WWW::Mechanize::Firefox;
rlm@19 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@19 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@19 14 #@org_files = glob("./org/*.org");
rlm@19 15
rlm@16 16 for $file(@org_files){print "$file\n";}
rlm@9 17 $ignore_next = 0;
rlm@19 18 $last_page = "";
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@19 29 $ignore_next = 0;
rlm@19 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@19 37 $output = `weave $name`;
rlm@19 38 $path = `readlink -f $name`;
rlm@19 39 $path =~ s|/home/r/proj|http://aurellem.localhost|;
rlm@19 40 $path =~ s|org|html|g;
rlm@19 41 if ($last_page eq $path){
rlm@19 42 print "reloading current page : $path\n";
rlm@19 43 $mech->reload();
rlm@19 44 }
rlm@19 45 else {
rlm@19 46 print "moving to new page : $path\n";
rlm@19 47 $last_page = $path;
rlm@19 48 $mech->get($path);
rlm@19 49 }
rlm@6 50 });
rlm@6 51 }
rlm@6 52
rlm@19 53
rlm@13 54 # manual event loop
rlm@6 55 1 while $inotify->poll;