From ab3e6da829a466c2f873e52e3c6d677d67ad9205 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 25 Nov 2009 12:26:20 +0100 Subject: [PATCH] Revert "Get rid of utils.CommaJoin" This reverts commit 6915bc28fe053e92aa16cf2d974d205f1140219c based on thread on ganeti-devel. Conflicts: lib/cmdlib.py (due to the error code classification, trivial) Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cmdlib.py | 3 ++- lib/hypervisor/hv_base.py | 2 +- lib/utils.py | 10 ++++++++++ scripts/gnt-node | 3 ++- test/docs_unittest.py | 4 ++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 768d67bd7..2f475579c 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2015,7 +2015,8 @@ class LUSetClusterParams(LogicalUnit): invalid_hvs = set(self.hv_list) - constants.HYPER_TYPES if invalid_hvs: raise errors.OpPrereqError("Enabled hypervisors contains invalid" - " entries: %s" % " ,".join(invalid_hvs), + " entries: %s" % + utils.CommaJoin(invalid_hvs), errors.ECODE_INVAL) else: self.hv_list = cluster.enabled_hypervisors diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index 252e665e2..eacc0ecd1 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -82,7 +82,7 @@ def ParamInSet(required, my_set): """ fn = lambda x: x in my_set - err = ("The value must be one of: %s" % " ,".join(my_set)) + err = ("The value must be one of: %s" % utils.CommaJoin(my_set)) return (required, fn, err, None, None) diff --git a/lib/utils.py b/lib/utils.py index f10bcec7d..b2ffff9bf 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1884,6 +1884,16 @@ def SafeEncode(text): return resu +def CommaJoin(names): + """Nicely join a set of identifiers. + + @param names: set, list or tuple + @return: a string with the formatted results + + """ + return ", ".join(["'%s'" % val for val in names]) + + def BytesToMebibyte(value): """Converts bytes to mebibytes. diff --git a/scripts/gnt-node b/scripts/gnt-node index e44211054..0ca279425 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -98,7 +98,8 @@ _STORAGE_TYPE_OPT = \ choices=_USER_STORAGE_TYPE.keys(), default=None, metavar="STORAGE_TYPE", - help=("Storage type (%s)" % " ,".join(_USER_STORAGE_TYPE.keys()))) + help=("Storage type (%s)" % + utils.CommaJoin(_USER_STORAGE_TYPE.keys()))) _REPAIRABLE_STORAGE_TYPES = \ [st for st, so in constants.VALID_STORAGE_OPERATIONS.iteritems() diff --git a/test/docs_unittest.py b/test/docs_unittest.py index a3cb2b7a8..95d81a877 100755 --- a/test/docs_unittest.py +++ b/test/docs_unittest.py @@ -114,7 +114,7 @@ class TestDocs(unittest.TestCase): self.failIf(undocumented, msg=("Missing RAPI resource documentation for %s" % - " ,".join(undocumented))) + utils.CommaJoin(undocumented))) class TestManpages(unittest.TestCase): @@ -145,7 +145,7 @@ class TestManpages(unittest.TestCase): self.failIf(missing, msg=("Manpage for '%s' missing documentation for %s" % - (script, " ,".join(missing)))) + (script, utils.CommaJoin(missing)))) if __name__ == "__main__": -- GitLab