From 1ee2b79257a52ebbfd70f193fc518c3a9089af63 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Mon, 17 Jun 2024 12:00:00 +0200 Subject: [PATCH 1/2] shell.py: Fix warning caused by overwriting cmd with str and whitespace Signed-off-by: Bernhard Kaindl --- pyproject.toml | 1 - scripts/examples/python/shell.py | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2730c0ac018..6912a211e27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -256,7 +256,6 @@ expected_to_fail = [ "scripts/examples/python/exportimport.py", # Other fixes needed: "scripts/examples/python/monitor-unwanted-domains.py", - "scripts/examples/python/shell.py", "scripts/static-vdis", "scripts/plugins/extauth-hook-AD.py", ] diff --git a/scripts/examples/python/shell.py b/scripts/examples/python/shell.py index 6e5e4f8ff27..0fa226d798f 100644 --- a/scripts/examples/python/shell.py +++ b/scripts/examples/python/shell.py @@ -71,7 +71,7 @@ def munge_types (str): return True elif str == "False": return False - + try: return int(str) except: @@ -81,12 +81,12 @@ def munge_types (str): if len(sys.argv) < 2: print("Usage:") print(sys.argv[0], " ") - sys.exit(1) + sys.exit(1) if sys.argv[1] != "-" and len(sys.argv) < 4: print("Usage:") print(sys.argv[0], " ") - sys.exit(1) + sys.exit(1) if sys.argv[1] != "-": url = sys.argv[1] @@ -103,10 +103,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) From c2b2cf9dfb39e4aa12b9b3311a62065b32b14dd2 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Mon, 17 Jun 2024 12:00:00 +0200 Subject: [PATCH 2/2] shell.py: Fix warning caused by overwriting built-in str Signed-off-by: Bernhard Kaindl --- scripts/examples/python/shell.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/examples/python/shell.py b/scripts/examples/python/shell.py index 0fa226d798f..3cfdde757db 100644 --- a/scripts/examples/python/shell.py +++ b/scripts/examples/python/shell.py @@ -66,16 +66,18 @@ 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: