view 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
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;
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 $mech->get($path);
42 });
43 }
46 # manual event loop
47 1 while $inotify->poll;