On Thu, Feb 06, 2014 at 05:24:10PM +0100, Santi Raffa wrote:
> We do not want public, private and secret parameters to have
> overlapping keys. This function implements this check.
> 
> Signed-off-by: Santi Raffa <[email protected]>
> ---
>  autotools/build-rpc |  3 +--
>  lib/utils/algo.py   | 26 ++++++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/autotools/build-rpc b/autotools/build-rpc
> index 2de71d5..353c2ff 100755
> --- a/autotools/build-rpc
> +++ b/autotools/build-rpc
> @@ -195,8 +195,7 @@ def main():
>      assert module.SINGLE == _SINGLE
>      assert module.MULTI == _MULTI
>  
> -    dups = utils.FindDuplicates(itertools.chain(*map(lambda value: 
> value.keys(),
> -                                                     module.CALLS.values())))
> +    dups = utils.GetRepeatedKeys(*module.CALLS.values())
>      if dups:
>        raise Exception("Found duplicate RPC definitions for '%s'" %
>                        utils.CommaJoin(sorted(dups)))
> diff --git a/lib/utils/algo.py b/lib/utils/algo.py
> index b436f5a..2d13626 100644
> --- a/lib/utils/algo.py
> +++ b/lib/utils/algo.py
> @@ -95,6 +95,32 @@ def FindDuplicates(seq):
>    return list(dup)
>  
>  
> +#pylint: disable=W0142

Please add an comment saying what this disables.

> +def GetRepeatedKeys(*dicts):
> +  """Return the set of keys defined multiple times in the given dicts.
> +
> +  >>> GetRepeatedKeys({"foo": 1, "bar": 2},
> +  ...                 {"foo": 5, "baz": 7}
> +  ...                )
> +  set("foo")
> +
> +  @type dicts: dict
> +  @param dicts: The dictionaries to check for duplicate keys.
> +  @rtype: set
> +  @return: Keys used more than once across all dicts
> +
> +  """
> +

Unnecessary newline.

Rest LGTM.

Thanks,
Jose

> +  if len(dicts) < 2:
> +    return set()
> +
> +  keys = []
> +  for dictionary in dicts:
> +    keys.extend(dictionary)
> +
> +  return set(FindDuplicates(keys))
> +
> +
>  def _NiceSortTryInt(val):
>    """Attempts to convert a string to an integer.
>  
> -- 
> 1.9.0.rc1.175.g0b1dcb5
> 

-- 
Jose Antonio Lopes
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370

Reply via email to