view 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
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;