Source code for utah.commandstr
# Ubuntu Testing Automation Harness
# Copyright 2012 Canonical Ltd.
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Provide stringification for commands used by timeout and retry."""
[docs]def commandstr(command, *args, **kw):
"""Provide a user-oriented command display.
i.e. commandstr(command, arg1, arg2, kw1=1, kw2=2)
should return 'command(arg1, arg2, kw1=1, kw2=2)'
"""
msg = '{}('.format(command.__name__)
for arg in args:
try:
msg += arg.__name__
except (AttributeError, SyntaxError):
msg += str(arg)
msg += ', '
for arg in kw:
try:
msg += arg.__name__
except (AttributeError, SyntaxError):
msg += str(arg)
msg += '='
try:
msg += kw[arg].__name__
except (AttributeError, SyntaxError):
msg += str(kw[arg])
msg += ', '
msg = msg.rstrip(', ')
msg += ')'
return msg