Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell.py: Fix warnings caused by overwriting cmd with str, and str too. #5697

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ expected_to_fail = [
"scripts/backup-sr-metadata.py",
"scripts/restore-sr-metadata.py",
# Other fixes needed:
"scripts/examples/python/shell.py",
"scripts/static-vdis",
"scripts/plugins/extauth-hook-AD.py",
]
Expand Down
22 changes: 12 additions & 10 deletions scripts/examples/python/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,29 @@ def do_EOF(self, line):
print()
sys.exit(0)

def munge_types (str):
if str == "True":

def munge_types(var):
if var == "True":
return True
elif str == "False":
if var == "False":
return False

try:
return int(str)
return int(var)
except:
return str
return var


if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage:")
print(sys.argv[0], " <url> <username> <password>")
sys.exit(1)
sys.exit(1)

if sys.argv[1] != "-" and len(sys.argv) < 4:
print("Usage:")
print(sys.argv[0], " <url> <username> <password>")
sys.exit(1)
sys.exit(1)

if sys.argv[1] != "-":
url = sys.argv[1]
Expand All @@ -103,10 +105,10 @@ def munge_types (str):
# We want to support directly executing the cmd line,
# where appropriate
if len(sys.argv) > cmdAt:
cmd = sys.argv[cmdAt]
command = sys.argv[cmdAt]
params = [munge_types(x) for x in sys.argv[(cmdAt + 1):]]
try:
print(session.xenapi_request(cmd, tuple(params)), file=sys.stdout)
print(session.xenapi_request(command, tuple(params)), file=sys.stdout)
except XenAPI.Failure as x:
print(x, file=sys.stderr)
sys.exit(2)
Expand Down
Loading