|
|
Subject: Re: file diff? - msg#00106
List: sysutils.puppet.user
On Mon, Dec 18, 2006 at 02:13:52PM -0600, Luke Kanies wrote:
> be too hard. I don't think Ruby comes with a diff library by
> default, but I could try to load one and use it if it's available.
I've used Algorithm::Diff a little bit in the past. It wasn't *fantastic*,
but it'd do the job without a massive amount of pain and suffering.
> I figured (for some reason) you were talking about approving the
> diffs when they happen, but I see what you mean now.
Making the diff just a standard part of --dry-run would probably be pretty
cool.
- Matt
--
Judging by this particular thread, many people in this group spent their
school years taking illogical, pointless orders from morons and having their
will to live systematically crushed. And people say school doesn't prepare
kids for the real world. -- Rayner, in the Monastery
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
Re: file diff?
On Dec 18, 2006, at 2:03 PM, Christopher McCrory wrote:
> What my existing tool does is basically replace 'cp' with 'diff -u'
>
> <setup>
> CP="/bin/cp"
> if $DEBUG then CP="diff -u"
> ...
> CP /SOURCE/PATH/some.conf /PATH/some.conf
> <repeat x 300>
>
> so my process is not interactive, but the implementation was easy.
So are you just talking about printing a diff during the replacement,
not viewing the diff interactively or anything? Hmm. That shouldn't
be too hard. I don't think Ruby comes with a diff library by
default, but I could try to load one and use it if it's available.
I figured (for some reason) you were talking about approving the
diffs when they happen, but I see what you mean now.
> Would doing something similar within puppet be as easy?
Not quite, but it could be close.
> My ruby skills are non-existant. Can you point me to the parts of the
> puppet code where I can start hacking something similar?
You'd need to make two changes:
First you'd have to create a 'diff' feature, so Puppet could tell
whether the diff library were available. This would be a simple ruby
snippet that returned true if the library loaded successfully, and
false otherwise; see the other features in lib/puppet/features/ for
examples.
Then, in the two states that manage entire files (content and
source), modify the the 'change_to_s' method (which is responsible
for producing the change long) to test for the diff feature; if it's
absent, behaviour should be like it is now, and if it's present, it
should print a diff of the files.
For the content state, this should be very easy; for the 'source'
state, it'd be a little more difficult, since the new file contents
aren't actually available until after the change_to_s method is
called, so you'd need to do a bit of refactoring internally so the
content was available during this method for diffing.
> Thanks for the response. If I cannot hack something together
> myself, are
> you open to sponsorship?
Definitely -- I prefer custom development projects over just about
any other kind of work. Do you mean community or corporate
sponsorship? I've only done corporate development contracts, not any
kind of community sponsorship (yet).
--
Men will wrangle for religion; write for it; fight for it; die for it;
anything but live for it. --Charles Caleb Colton
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
Next Message by Date:
click to view message preview
Re: file diff?
On Dec 18, 2006, at 3:13 PM, Matthew Palmer wrote:
>
> I've used Algorithm::Diff a little bit in the past. It wasn't
> *fantastic*,
> but it'd do the job without a massive amount of pain and suffering.
Ah, that comes with ruby? I didn't realize.
> Making the diff just a standard part of --dry-run would probably be
> pretty
> cool.
Yeah, I agree. I've been wanting something like that, but haven't
known exactly what to do.
I'll keep thinking about it, and maybe I'll have a chance to take a
crack at it. Given a quick look at the bug list, though, it seems
unlikely to happen any time soon. Ugh.
If someone would open this as a feature request, that would be great.
--
The optimist proclaims that we live in the best of all possible
worlds,
and the pessimist fears that this is true.
-- James Branch Cabell 1879-1958
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
Previous Message by Thread:
click to view message preview
Re: file diff?
On Dec 18, 2006, at 2:03 PM, Christopher McCrory wrote:
> What my existing tool does is basically replace 'cp' with 'diff -u'
>
> <setup>
> CP="/bin/cp"
> if $DEBUG then CP="diff -u"
> ...
> CP /SOURCE/PATH/some.conf /PATH/some.conf
> <repeat x 300>
>
> so my process is not interactive, but the implementation was easy.
So are you just talking about printing a diff during the replacement,
not viewing the diff interactively or anything? Hmm. That shouldn't
be too hard. I don't think Ruby comes with a diff library by
default, but I could try to load one and use it if it's available.
I figured (for some reason) you were talking about approving the
diffs when they happen, but I see what you mean now.
> Would doing something similar within puppet be as easy?
Not quite, but it could be close.
> My ruby skills are non-existant. Can you point me to the parts of the
> puppet code where I can start hacking something similar?
You'd need to make two changes:
First you'd have to create a 'diff' feature, so Puppet could tell
whether the diff library were available. This would be a simple ruby
snippet that returned true if the library loaded successfully, and
false otherwise; see the other features in lib/puppet/features/ for
examples.
Then, in the two states that manage entire files (content and
source), modify the the 'change_to_s' method (which is responsible
for producing the change long) to test for the diff feature; if it's
absent, behaviour should be like it is now, and if it's present, it
should print a diff of the files.
For the content state, this should be very easy; for the 'source'
state, it'd be a little more difficult, since the new file contents
aren't actually available until after the change_to_s method is
called, so you'd need to do a bit of refactoring internally so the
content was available during this method for diffing.
> Thanks for the response. If I cannot hack something together
> myself, are
> you open to sponsorship?
Definitely -- I prefer custom development projects over just about
any other kind of work. Do you mean community or corporate
sponsorship? I've only done corporate development contracts, not any
kind of community sponsorship (yet).
--
Men will wrangle for religion; write for it; fight for it; die for it;
anything but live for it. --Charles Caleb Colton
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
Next Message by Thread:
click to view message preview
Re: file diff?
On Dec 18, 2006, at 3:13 PM, Matthew Palmer wrote:
>
> I've used Algorithm::Diff a little bit in the past. It wasn't
> *fantastic*,
> but it'd do the job without a massive amount of pain and suffering.
Ah, that comes with ruby? I didn't realize.
> Making the diff just a standard part of --dry-run would probably be
> pretty
> cool.
Yeah, I agree. I've been wanting something like that, but haven't
known exactly what to do.
I'll keep thinking about it, and maybe I'll have a chance to take a
crack at it. Given a quick look at the bug list, though, it seems
unlikely to happen any time soon. Ugh.
If someone would open this as a feature request, that would be great.
--
The optimist proclaims that we live in the best of all possible
worlds,
and the pessimist fears that this is true.
-- James Branch Cabell 1879-1958
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
|
|