[ovs-dev] [PATCH] ovsdb: In documentation, add commas to make large numbers easier to read.

Reid Price reid at nicira.com
Thu May 6 03:15:41 UTC 2010


I was going to suggest a non-recursive solution, but yours was faster than
my iterative ones anyway, and seems clear enough =)

On Wed, May 5, 2010 at 2:08 PM, Ben Pfaff <blp at nicira.com> wrote:

> ---
>  ovsdb/OVSDB.py |   20 ++++++++++++++++----
>  1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/ovsdb/OVSDB.py b/ovsdb/OVSDB.py
> index f01c45b..6e426e5 100644
> --- a/ovsdb/OVSDB.py
> +++ b/ovsdb/OVSDB.py
> @@ -193,6 +193,17 @@ class Atom:
>         elif self.type == 'uuid':
>             return self.value.value
>
> +# Returns integer x formatted in decimal with thousands set off by commas.
> +def commafy(x):
> +    return _commafy("%d" % x)
> +def _commafy(s):
> +    if s.startswith('-'):
> +        return '-' + _commafy(s[1:])
> +    elif len(s) <= 3:
> +        return s
> +    else:
> +        return _commafy(s[:-3]) + ',' + _commafy(s[-3:])
> +
>  class BaseType:
>     def __init__(self, type,
>                  enum=None,
> @@ -253,13 +264,14 @@ class BaseType:
>                                                  ', '.join(literals[1:-1]),
>                                                  literals[-1])
>         elif self.minInteger != None and self.maxInteger != None:
> -            return 'in range [%d,%d]' % (self.minInteger, self.maxInteger)
> +            return 'in range %s to %s' % (commafy(self.minInteger),
> +                                         commafy(self.maxInteger))
>         elif self.minInteger != None:
> -            return 'at least %d' % self.minInteger
> +            return 'at least %s' % commafy(self.minInteger)
>         elif self.maxInteger != None:
> -            return 'at most %d' % self.maxInteger
> +            return 'at most %s' % commafy(self.maxInteger)
>         elif self.minReal != None and self.maxReal != None:
> -            return 'in range [%g, %g]' % (self.minReal, self.maxReal)
> +            return 'in range %g to %g' % (self.minReal, self.maxReal)
>         elif self.minReal != None:
>             return 'at least %g' % self.minReal
>         elif self.maxReal != None:
> --
> 1.6.6.1
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20100505/941ded4c/attachment-0003.html>


More information about the dev mailing list