1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 5# 6# This is the uninstall script for the eric debug client. 7# 8 9""" 10Unnstallation script for the eric debug clients. 11""" 12 13import sys 14import os 15import shutil 16import distutils.sysconfig 17import contextlib 18 19# Define the globals. 20progName = None 21currDir = os.getcwd() 22modDir = None 23pyModDir = None 24installPackage = "eric6DebugClients" 25 26 27def exit(rcode=0): 28 """ 29 Exit the install script. 30 31 @param rcode result code to report back (integer) 32 """ 33 global currDir 34 35 if sys.platform.startswith("win"): 36 with contextlib.suppress(): 37 input("Press enter to continue...") # secok 38 39 os.chdir(currDir) 40 41 sys.exit(rcode) 42 43 44def usage(rcode=2): 45 """ 46 Display a usage message and exit. 47 48 @param rcode return code passed back to the calling process (integer) 49 """ 50 global progName 51 52 print("Usage:") 53 print(" {0} [-h]".format(progName)) 54 print("where:") 55 print(" -h display this help message") 56 57 exit(rcode) 58 59 60def initGlobals(): 61 """ 62 Module function to set the values of globals that need more than a 63 simple assignment. 64 """ 65 global modDir, pyModDir 66 67 modDir = distutils.sysconfig.get_python_lib(True) 68 pyModDir = modDir 69 70 71def uninstallEricDebugClients(): 72 """ 73 Uninstall the old eric debug client files. 74 """ 75 global pyModDir 76 77 try: 78 # Cleanup the install directories 79 dirname = os.path.join(pyModDir, installPackage) 80 if os.path.exists(dirname): 81 shutil.rmtree(dirname, True) 82 except OSError as msg: 83 sys.stderr.write( 84 'Error: {0}\nTry uninstall with admin rights.\n'.format(msg)) 85 exit(7) 86 87 88def main(argv): 89 """ 90 The main function of the script. 91 92 @param argv the list of command line arguments. 93 """ 94 import getopt 95 96 initGlobals() 97 98 # Parse the command line. 99 global progName 100 progName = os.path.basename(argv[0]) 101 102 try: 103 optlist, args = getopt.getopt(argv[1:], "hy") 104 except getopt.GetoptError: 105 usage() 106 107 for opt, _arg in optlist: 108 if opt in ["-h", "--help"]: 109 usage(0) 110 111 print("\nUninstalling eric debug clients ...") 112 uninstallEricDebugClients() 113 print("\nUninstallation complete.") 114 print() 115 116 exit(0) 117 118 119if __name__ == "__main__": 120 try: 121 main(sys.argv) 122 except SystemExit: 123 raise 124 except Exception: 125 print("""An internal error occured. Please report all the output""" 126 """ of the program,\nincluding the following traceback, to""" 127 """ eric-bugs@eric-ide.python-projects.org.\n""") 128 raise 129 130# 131# eflag: noqa = M801 132