--- a/scripts/uninstall.py Tue Oct 31 09:23:05 2023 +0100 +++ b/scripts/uninstall.py Wed Nov 29 14:23:36 2023 +0100 @@ -10,16 +10,16 @@ Uninstallation script for the eric IDE and all eric related tools. """ +import argparse import contextlib -import getopt import glob +import importlib import os import shutil import sys import sysconfig # Define the globals. -progName = None currDir = os.getcwd() pyModDir = None progLanguages = ["MicroPython", "Python3", "QSS"] @@ -67,22 +67,6 @@ exit(1) -def usage(rcode=2): - """ - Display a usage message and exit. - - @param rcode return code passed back to the calling process (integer) - """ - global progName - - print("Usage:") - print(" {0} [-h]".format(progName)) - print("where:") - print(" -h display this help message") - - exit(rcode) - - def initGlobals(): """ Set the values of globals that need more than a simple assignment. @@ -125,7 +109,7 @@ global pyModDir # Remove the menu entry for Linux systems - if sys.platform.startswith("linux"): + if sys.platform.startswith(("linux", "freebsd")): uninstallLinuxSpecifics() # Remove the Desktop and Start Menu entries for Windows systems elif sys.platform.startswith(("win", "cygwin")): @@ -254,9 +238,7 @@ """ Clean up the Desktop and Start Menu entries for Windows. """ - try: - from pywintypes import com_error # __IGNORE_WARNING__ - except ImportError: + if importlib.util.find_spec("pywintypes") is None: # links were not created by install.py return @@ -342,9 +324,7 @@ macAppBundleName = getConfig("macAppBundleName") except AttributeError: macAppBundlePath = ( - defaultMacAppBundlePath - if os.getpid() == 0 - else defaultMacUserAppBundlePath + defaultMacAppBundlePath if os.getpid() == 0 else defaultMacUserAppBundlePath ) macAppBundleName = defaultMacAppBundleName for bundlePath in [ @@ -490,28 +470,25 @@ return "eric7 (Python {0}.{1})".format(majorVersion, minorVersion) -def main(argv): +def createArgumentParser(): + """ + Function to create an argument parser. + + @return created argument parser object + @rtype argparse.ArgumentParser + """ + parser = argparse.ArgumentParser(description="Uninstall eric7.") + return parser + + +def main(): """ The main function of the script. - - @param argv list of command line arguments """ initGlobals() - # Parse the command line. - global progName - progName = os.path.basename(argv[0]) - - try: - optlist, args = getopt.getopt(argv[1:], "hy") - except getopt.GetoptError: - usage() - - global platBinDir - - for opt, _arg in optlist: - if opt == "-h": - usage(0) + parser = createArgumentParser() + parser.parse_args() print("\nUninstalling eric ...") uninstallEric() @@ -523,7 +500,7 @@ if __name__ == "__main__": try: - main(sys.argv) + main() except SystemExit: raise except Exception: