From aeae774a41e06efcefc9905f6f9d9904f90cae01 Mon Sep 17 00:00:00 2001 From: Ashwinh Date: Thu, 4 Jul 2024 13:50:45 +0000 Subject: [PATCH] CP-49926: Removed shell.py from scripts/examples/python Signed-off-by: Ashwinh --- scripts/Makefile | 1 - scripts/examples/python/shell.py | 120 ------------------------------- 2 files changed, 121 deletions(-) delete mode 100644 scripts/examples/python/shell.py diff --git a/scripts/Makefile b/scripts/Makefile index 7d5e13ce954..6e4fe678471 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -149,7 +149,6 @@ endif $(IDATA) examples/python/XenAPIPlugin.py $(DESTDIR)$(SITE3_DIR)/ sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/' $(DESTDIR)$(SITE3_DIR)/XenAPIPlugin.py $(IDATA) examples/python/XenAPI/XenAPI.py $(DESTDIR)$(SITE3_DIR)/ - $(IPROG) examples/python/shell.py $(DESTDIR)$(LIBEXECDIR)/shell.py # YUM plugins $(IPROG) yum-plugins/accesstoken.py $(DESTDIR)$(YUMPLUGINDIR) $(IDATA) yum-plugins/accesstoken.conf $(DESTDIR)$(YUMPLUGINCONFDIR) diff --git a/scripts/examples/python/shell.py b/scripts/examples/python/shell.py deleted file mode 100644 index 3cfdde757db..00000000000 --- a/scripts/examples/python/shell.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2006-2008 Citrix Systems. -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -from __future__ import print_function -import atexit -import cmd -import pprint -import readline -import shlex -import string -import sys - -import XenAPI - -def logout(): - try: - session.xenapi.session.logout() - except: - pass -atexit.register(logout) - -class Shell(cmd.Cmd): - def __init__(self): - cmd.Cmd.__init__(self) - self.identchars = string.ascii_letters + string.digits + '_.' - self.prompt = "xe> " - - def preloop(self): - cmd.Cmd.preloop(self) - readline.set_completer_delims(' ') - - def default(self, line): - words = shlex.split(line) - if len(words) > 0: - res = session.xenapi_request(words[0], tuple(words[1:])) - if res is not None and res != '': - pprint.pprint(res) - return False - - def completedefault(self, text, line, begidx, endidx): - words = shlex.split(line[:begidx]) - clas, func = words[0].split('.') - if len(words) > 1 or \ - func.startswith('get_by_') or \ - func == 'get_all': - return [] - uuids = session.xenapi_request('%s.get_all' % clas, ()) - return [u + " " for u in uuids if u.startswith(text)] - - def emptyline(self): - pass - - def do_EOF(self, line): - print() - sys.exit(0) - - -def munge_types(var): - if var == "True": - return True - if var == "False": - return False - - try: - return int(var) - except: - return var - - -if __name__ == "__main__": - if len(sys.argv) < 2: - print("Usage:") - print(sys.argv[0], " ") - sys.exit(1) - - if sys.argv[1] != "-" and len(sys.argv) < 4: - print("Usage:") - print(sys.argv[0], " ") - sys.exit(1) - - if sys.argv[1] != "-": - url = sys.argv[1] - username = sys.argv[2] - password = sys.argv[3] - session = XenAPI.Session(url) - session.xenapi.login_with_password(username, password, "1.0", "xen-api-scripts-shell.py") - cmdAt = 4 - else: - session = XenAPI.xapi_local() - session.xenapi.login_with_password("", "", "1.0", "xen-api-scripts-shell.py") - cmdAt = 2 - - # We want to support directly executing the cmd line, - # where appropriate - if len(sys.argv) > cmdAt: - command = sys.argv[cmdAt] - params = [munge_types(x) for x in sys.argv[(cmdAt + 1):]] - try: - print(session.xenapi_request(command, tuple(params)), file=sys.stdout) - except XenAPI.Failure as x: - print(x, file=sys.stderr) - sys.exit(2) - except Exception as e: - print(e, file=sys.stderr) - sys.exit(3) - sys.exit(0) - else: - Shell().cmdloop('Welcome to the XenServer shell. (Try "VM.get_all")')