Building a log by watching a file

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,

Bil K. wrote:

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

Christian N. wrote:

Bil K. [email protected] writes:

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

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,

Bil K. remov[email protected] writes:

$ ./code < input_deck
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?

What I’d do:

while true; do git commit -m “$(date)” input_deck; sleep 1; done

Ought to work with any reasonable VCS.

Phrogz wrote:

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,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs