building a log by watching a file

B

Bil Kleb

I've been paying attention to some mind-numbing chores
I've been tasked to do lately, and I think Ruby might
be able to help. Let me know what you think.

We have *many* crusty Fortran (and FORTRAN) codes lying
around that do their job just fine, except they are
a pain to run.

One scenario might go like this,

$ ./code < input_deck
[edit a bunch of things in input_deck]

This two step is repeated ad nauseam until you're satisfied
with the output. The kicker is you do this once to find
the path to the solution, then you run 3,000 variations
on this central theme.

One burden is logging your sequence of input_deck
edits, so that you can replay them for the
next 3000 cases (adding logging to the crusty code
is unthinkable).

So, I was thinking of turning on a "watcher" that
would save off inputs decks every time an edit is
detected.

Anyone have a one-liner?

Thanks,
 
P

Phrogz

Bil said:
So, I was thinking of turning on a "watcher" that
would save off inputs decks every time an edit is
detected.

Anyone have a one-liner?

Definitely not a one-liner, but I can offer:
http://phrogz.net/RubyLibs/rdoc/files/DirectoryWatcher_rb.html

With that, it'd be as easy as:

edit_logger = Dir::DirectoryWatcher.new( 'directory/to/watch', 2 )

# Only look at certain files in the directory
edit_logger.name_regexp = /\.fortran$/

edit_logger.on_modify = Proc.new{ |the_file, stats_hash|
puts "Hey, #{the_file.inspect} just changed."
# Do something cool here.
}

edit_logger.start_watching
 
B

Bil Kleb

Christian said:
while true; do git commit -m "$(date)" input_deck; sleep 1; done

Excellent.

(Turns out, this is also my officemate's answer, although
he didn't supply the command to do it.)

Thanks,
 
B

Bil Kleb

Phrogz said:
edit_logger.on_modify = Proc.new{ |the_file, stats_hash|
puts "Hey, #{the_file.inspect} just changed."
# Do something cool here.
}

Thanks.

How would I inject a running index into the "Do something
cool here" part so I could save off input_deck.0,
input_deck.1, and so on?

Regards,
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top