changeset 19:c14f3a4af7fd

make weave-all check for existence of org directory
author Robert McIntyre <rlm@mit.edu>
date Thu, 01 Mar 2012 06:33:12 -0700
parents 993b8d7d9bec
children 5423d5aaa56a
files auto-weave.pl weave-all.sh
diffstat 2 files changed, 28 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/auto-weave.pl	Wed Nov 02 09:24:54 2011 -0700
     1.2 +++ b/auto-weave.pl	Thu Mar 01 06:33:12 2012 -0700
     1.3 @@ -1,16 +1,21 @@
     1.4  #!/usr/bin/perl
     1.5  
     1.6  use Linux::Inotify2;
     1.7 +use WWW::Mechanize::Firefox;
     1.8 +my $mech = WWW::Mechanize::Firefox->new();
     1.9  
    1.10  my $inotify = new Linux::Inotify2
    1.11    or die "unable to create new inotify object: $!";
    1.12  
    1.13 +
    1.14  $org_files = `find /home/r/proj -name "*.org" -print0`;
    1.15  @org_files = split /\0/, $org_files;
    1.16  
    1.17 +#@org_files =  glob("./org/*.org");
    1.18 +
    1.19  for $file(@org_files){print "$file\n";}
    1.20  $ignore_next = 0;
    1.21 -
    1.22 +$last_page = "";
    1.23  
    1.24  foreach(@org_files){
    1.25  # add watchers
    1.26 @@ -21,18 +26,30 @@
    1.27      # twice every time the file is saved from emacs.
    1.28      # so ignore every other invocation.
    1.29      if ($ignore_next) {
    1.30 -    	$ignore_next = 0;
    1.31 -    	return;
    1.32 +	$ignore_next = 0;
    1.33 +	return;
    1.34      }
    1.35      $ignore_next = 1;
    1.36  
    1.37      my $e = shift;
    1.38      my $name = $e->fullname;
    1.39      print "$name was modified\n" if $e->IN_MODIFY;
    1.40 -    system "weave $name &";
    1.41 -
    1.42 +    $output = `weave $name`;
    1.43 +    $path = `readlink -f $name`;
    1.44 +    $path =~ s|/home/r/proj|http://aurellem.localhost|;
    1.45 +    $path =~ s|org|html|g;
    1.46 +    if ($last_page eq $path){
    1.47 +	print "reloading current page : $path\n";
    1.48 +	$mech->reload();
    1.49 +    }
    1.50 +    else {
    1.51 +	print "moving to new page : $path\n";
    1.52 +	$last_page = $path;
    1.53 +	$mech->get($path);
    1.54 +    }
    1.55  });
    1.56  }
    1.57  
    1.58 +
    1.59  # manual event loop
    1.60  1 while $inotify->poll;
     2.1 --- a/weave-all.sh	Wed Nov 02 09:24:54 2011 -0700
     2.2 +++ b/weave-all.sh	Thu Mar 01 06:33:12 2012 -0700
     2.3 @@ -5,6 +5,12 @@
     2.4  
     2.5  #target=$(readlink -f $1)
     2.6  
     2.7 +if [ ! -d "./org" ]; then
     2.8 +    echo "no org directory"
     2.9 +    exit
    2.10 +fi
    2.11 +
    2.12 +
    2.13  dir=`pwd`
    2.14  
    2.15  emacs  \