Mercurial > org-tools
comparison auto-weave.pl @ 18:993b8d7d9bec
buggy garbage
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 02 Nov 2011 09:24:54 -0700 |
parents | 6da973a6b93d |
children | c14f3a4af7fd |
comparison
equal
deleted
inserted
replaced
17:6da973a6b93d | 18:993b8d7d9bec |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 | 2 |
3 use Linux::Inotify2; | 3 use Linux::Inotify2; |
4 use WWW::Mechanize::Firefox; | |
5 my $mech = WWW::Mechanize::Firefox->new(); | |
6 | 4 |
7 my $inotify = new Linux::Inotify2 | 5 my $inotify = new Linux::Inotify2 |
8 or die "unable to create new inotify object: $!"; | 6 or die "unable to create new inotify object: $!"; |
9 | 7 |
10 | |
11 $org_files = `find /home/r/proj -name "*.org" -print0`; | 8 $org_files = `find /home/r/proj -name "*.org" -print0`; |
12 @org_files = split /\0/, $org_files; | 9 @org_files = split /\0/, $org_files; |
13 | 10 |
14 #@org_files = glob("./org/*.org"); | |
15 | |
16 for $file(@org_files){print "$file\n";} | 11 for $file(@org_files){print "$file\n";} |
17 $ignore_next = 0; | 12 $ignore_next = 0; |
18 $last_page = ""; | 13 |
19 | 14 |
20 foreach(@org_files){ | 15 foreach(@org_files){ |
21 # add watchers | 16 # add watchers |
22 $inotify->watch ($_, IN_MODIFY, sub | 17 $inotify->watch ($_, IN_MODIFY, sub |
23 { | 18 { |
24 print ("IGNORE : $ignore_next\n"); | 19 print ("IGNORE : $ignore_next\n"); |
25 # ok, for some reason this gets called exactly | 20 # ok, for some reason this gets called exactly |
26 # twice every time the file is saved from emacs. | 21 # twice every time the file is saved from emacs. |
27 # so ignore every other invocation. | 22 # so ignore every other invocation. |
28 if ($ignore_next) { | 23 if ($ignore_next) { |
29 $ignore_next = 0; | 24 $ignore_next = 0; |
30 return; | 25 return; |
31 } | 26 } |
32 $ignore_next = 1; | 27 $ignore_next = 1; |
33 | 28 |
34 my $e = shift; | 29 my $e = shift; |
35 my $name = $e->fullname; | 30 my $name = $e->fullname; |
36 print "$name was modified\n" if $e->IN_MODIFY; | 31 print "$name was modified\n" if $e->IN_MODIFY; |
37 $output = `weave $name`; | 32 system "weave $name &"; |
38 $path = `readlink -f $name`; | 33 |
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 }); | 34 }); |
51 } | 35 } |
52 | 36 |
53 | |
54 # manual event loop | 37 # manual event loop |
55 1 while $inotify->poll; | 38 1 while $inotify->poll; |