From f5ce7613263451340edbd385ca5b1a600de03a4b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 20 Jul 2012 22:14:40 +0200 Subject: [PATCH] Ensure a stable content of the bash completion file Currently, the order of commands in the bash completion file is random, because the sub-commands are not sorted. This makes it harder to investigate the differences in packaged Ganeti or in installed Ganeti, since chunks in this file will have a random order. To fix this, we sort the subcommands based on the first subcommand in a given group ('first' also in sorted order); this results in a stable contents of file, as tested by building it many times and checking for differences. The patch also does a few other minor changes to the file (e.g. updating copyright years, etc.). Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- autotools/build-bash-completion | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion index 6eb0dbe75..365dad98a 100755 --- a/autotools/build-bash-completion +++ b/autotools/build-bash-completion @@ -1,7 +1,7 @@ #!/usr/bin/python # -# Copyright (C) 2009 Google Inc. +# Copyright (C) 2009, 2010, 2011, 2012 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -319,7 +319,7 @@ class CompletionWriter: wrote_opt = False - for (suggest, allnames) in values.iteritems(): + for (suggest, allnames) in values.items(): longnames = [i for i in allnames if i.startswith("--")] if wrote_opt: @@ -551,14 +551,16 @@ def WriteCompletion(sw, scriptname, funcname, # Group commands by arguments and options grouped_cmds = {} - for cmd, (_, argdef, optdef, _, _) in commands.iteritems(): + for cmd, (_, argdef, optdef, _, _) in commands.items(): if not (argdef or optdef): continue grouped_cmds.setdefault((tuple(argdef), tuple(optdef)), set()).add(cmd) # We're doing options and arguments to commands sw.Write("""case "${COMP_WORDS[1]}" in""") - for ((argdef, optdef), cmds) in grouped_cmds.items(): + sort_grouped = sorted(grouped_cmds.items(), + key=lambda (_, y): sorted(y)[0]) + for ((argdef, optdef), cmds) in sort_grouped: assert argdef or optdef sw.Write("%s)", "|".join(map(utils.ShellQuote, sorted(cmds)))) sw.IncIndent() @@ -610,7 +612,7 @@ def GetCommands(filename, module): aliases = getattr(module, "aliases", {}) if aliases: commands = commands.copy() - for name, target in aliases.iteritems(): + for name, target in aliases.items(): commands[name] = commands[target] return commands -- GitLab