
jj33 at pobox
Jun 15, 2012, 6:52 AM
Post #4 of 7
(421 views)
Permalink
|
|
Re: [PATCH] nxrancid ShowEnvPower oscillating
[In reply to]
|
|
On Thu, Jun 14, 2012 at 8:29 PM, heasley <heas [at] shrubbery> wrote: > How about the following instead: > > Index: nxrancid.in > =================================================================== > --- nxrancid.in (revision 2494) > +++ nxrancid.in (working copy) > @@ -375,14 +375,8 @@ > #------- ------------------- ----------- ----------- -------------- > #2 NURBURGRING N/A 573 W Powered-Up > #fan1 N/A 720 W Powered-Up > - if (/Actual +Total/ || > - /Actual +Power/ || > - /Draw +Allocated/ || > - /Output +Capacity/ || > - /(\(Watts \)) +\g{-1}/ || > - /(-----------) +\g{-1}/ || > - /(\d+ W|N\/A) +\d+ W/) { > - substr($_, 30, 13, ""); > + if ( /(.*) +(\d+ W)( +\d+ W.*)/) { > + $_ = sprintf("%s%-". length($2)."s%s\n", $1, "", $3); > } > > /actual draw/ && next; # Drop changing total power output. > Here's a version of your patch that applies against 238 (it looks like the version above was applied against a copy already patched with Zenon's solution): ################ --- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500 +++ nxrancid-238-heasley 2012-06-15 08:22:37.000000000 -0500 @@ -379,8 +379,10 @@ s/ \(Watts \) / /; s/ Draw / /; s/ ----------- / /; - s/ N\/A / / || - s/ \d+ W / /; # Does not chop enough to line up. + s/ N\/A / /; + if (/(.*) +(\d+ W)( +\d+ W.*)/) { + $_ = sprintf("%s%-". length($2)."s%s\n", $1, "", $3); + } /actual draw/ && next; # Drop changing total power output. ################# Second, I like what you are doing here, your solution solves my major concern with my patch, which was that I was matching [\s\d]{9}, but not strictly requiring that it be all spaces and then all digits. This left a small hole where, if there was somehow another number added immediately in front of the actual wattage, we would swallow it. My only problem with this solution is that it still leaves the \d+\sW lines out of alignment with the lines around it. I'm attaching a .txt of the different patch outputs so they can be easily viewed in a monospace font. Here is my version of your patch which solves all of the issues: 1) prevents line oscillation when the number of figits in the actual draw changes 2) stricter regexp, should only parse the line as we expect. 3) fixes alignment so all "show env power" output columns match ###################### --- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500 +++ nxrancid-238-jetmore-2 2012-06-15 08:40:29.000000000 -0500 @@ -379,8 +379,10 @@ s/ \(Watts \) / /; s/ Draw / /; s/ ----------- / /; - s/ N\/A / / || - s/ \d+ W / /; # Does not chop enough to line up. + s/ N\/A / /; + if (/(.*?)(\s+\d+ W)( +\d+ W.*)/) { + $_ = sprintf("%s%-".(length($2)-11)."s%s\n", $1, "", $3); + } /actual draw/ && next; # Drop changing total power output. ########################## Thanks for your consideration, --John
|