view auto-weave.pl @ 17:6da973a6b93d

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