Mercurial > org-tools
annotate watch-org.pl @ 18:993b8d7d9bec
buggy garbage
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 02 Nov 2011 09:24:54 -0700 |
parents | |
children |
rev | line source |
---|---|
rlm@18 | 1 #!/usr/bin/perl |
rlm@18 | 2 |
rlm@18 | 3 use Linux::Inotify2; |
rlm@18 | 4 use WWW::Mechanize::Firefox; |
rlm@18 | 5 my $mech = WWW::Mechanize::Firefox->new(); |
rlm@18 | 6 |
rlm@18 | 7 my $inotify = new Linux::Inotify2 |
rlm@18 | 8 or die "unable to create new inotify object: $!"; |
rlm@18 | 9 |
rlm@18 | 10 $html_files = `find /home/r/proj/{cortex,aurellem,pokemon-types} -name "*.html" -print0`; |
rlm@18 | 11 @html_files = split /\0/, $html_files; |
rlm@18 | 12 |
rlm@18 | 13 |
rlm@18 | 14 #@org_files = glob("./org/*.org"); |
rlm@18 | 15 |
rlm@18 | 16 |
rlm@18 | 17 for $file(@html_files){print "$file\n";} |
rlm@18 | 18 |
rlm@18 | 19 $last_page = ""; |
rlm@18 | 20 |
rlm@18 | 21 foreach(@html_files){ |
rlm@18 | 22 $inotify->watch ($_, IN_MODIFY, sub |
rlm@18 | 23 { |
rlm@18 | 24 my $e = shift; |
rlm@18 | 25 my $name = $e->fullname; |
rlm@18 | 26 print "**************************\n"; |
rlm@18 | 27 print "$name was modified\n";## if $e->IN_MODIFY; |
rlm@18 | 28 |
rlm@18 | 29 $path = `readlink -f $name`; |
rlm@18 | 30 $path =~ s|/home/r/proj|http://aurellem.localhost|; |
rlm@18 | 31 #$path =~ s|org|html|g; |
rlm@18 | 32 |
rlm@18 | 33 if ($last_page eq $path){ |
rlm@18 | 34 print "reloading current page : $path\n"; |
rlm@18 | 35 $mech->reload(); |
rlm@18 | 36 } |
rlm@18 | 37 else { |
rlm@18 | 38 print "moving to new page : $path\n"; |
rlm@18 | 39 $last_page = $path; |
rlm@18 | 40 $mech->get($path); |
rlm@18 | 41 } |
rlm@18 | 42 }); |
rlm@18 | 43 } |
rlm@18 | 44 |
rlm@18 | 45 # manual event loop |
rlm@18 | 46 while (1){ |
rlm@18 | 47 print "I'm pollin'!"; |
rlm@18 | 48 $inotify->poll; |
rlm@18 | 49 |
rlm@18 | 50 } |