[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

building a log by watching a file

Bil Kleb

8/15/2006 6:09:00 PM

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
http://fun3d.lar...

4 Answers

Gavin Kistner

8/15/2006 6:33:00 PM

0

Bil Kleb 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/DirectoryWatch...

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 Neukirchen

8/16/2006 10:39:00 AM

0

Bil Kleb <Bil.Kleb@NASA.gov> writes:

> 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?

What I'd do:

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

Ought to work with any reasonable VCS.

> Thanks,
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Bil Kleb

8/16/2006 11:29:00 AM

0

Christian Neukirchen wrote:
> Bil Kleb <Bil.Kleb@NASA.gov> 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
http://fun3d.lar...

Bil Kleb

8/16/2006 11:32:00 AM

0

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,
--
Bil
http://fun3d.lar...