[rancid] [PATCH] nxrancid ShowEnvPower oscillating
John Jetmore
jj33 at pobox.com
Fri Jun 15 13:52:20 UTC 2012
On Thu, Jun 14, 2012 at 8:29 PM, heasley <heas at shrubbery.net> 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
-------------- next part --------------
#######################
un-modified output:
Actual Power
Module Model Draw Allocated Status
(Watts ) (Watts )
------- ------------------- ----------- ----------- --------------
Xb4 xbar N/A 60 W Absent
Xb5 xbar N/A 60 W Absent
fan1 N7K-C7010-FAN-S 116 W 720 W Powered-Up
fan2 N7K-C7010-FAN-S 116 W 720 W Powered-Up
fan3 N7K-C7010-FAN-F 11 W 120 W Powered-Up
fan4 N7K-C7010-FAN-F 11 W 120 W Powered-Up
############################
original code:
!Env: Power
!Env: Module Model Allocated Status
!Env: (Watts )
!Env: ------- ------------------- ----------- --------------
!Env: Xb4 xbar 60 W Absent
!Env: Xb5 xbar 60 W Absent
!Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
!Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
############################
jetmore's original patch:
!Env: Power
!Env: Module Model Allocated Status
!Env: (Watts )
!Env: ------- ------------------- ----------- --------------
!Env: Xb4 xbar 60 W Absent
!Env: Xb5 xbar 60 W Absent
!Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
!Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
################################
heasley's patch:
!Env: Power
!Env: Module Model Allocated Status
!Env: (Watts )
!Env: ------- ------------------- ----------- --------------
!Env: Xb4 xbar 60 W Absent
!Env: Xb5 xbar 60 W Absent
!Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
!Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
##################################
jetmore's new patch:
!Env: Power
!Env: Module Model Allocated Status
!Env: (Watts )
!Env: ------- ------------------- ----------- --------------
!Env: Xb4 xbar 60 W Absent
!Env: Xb5 xbar 60 W Absent
!Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
!Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
More information about the Rancid-discuss
mailing list