[rancid] [PATCH] nxrancid ShowEnvPower oscillating
heasley
heas at shrubbery.net
Fri Jun 15 16:00:21 UTC 2012
Fri, Jun 15, 2012 at 09:52:20AM -0400, John Jetmore:
> --- 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.
your patch isnt complete; mine removed all the filters to remove the
column and just blanked the data. so the column remains and there is
no issue with alignment. but, your regex is correct including that
WS, so in my method
> + if (/(.*) +(\d+ W)( +\d+ W.*)/) {
becomes
+ if (/(.* +)(\d+ W)( +\d+ W.*)/) {
> 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
> #######################
> 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