--- a/scripts/uninstall.py Thu Nov 09 09:37:23 2023 +0100 +++ b/scripts/uninstall.py Thu Nov 09 11:23:48 2023 +0100 @@ -10,8 +10,8 @@ Uninstallation script for the eric IDE and all eric related tools. """ +import argparse import contextlib -import getopt import glob import os import shutil @@ -19,7 +19,6 @@ import sysconfig # Define the globals. -progName = None currDir = os.getcwd() pyModDir = None progLanguages = ["MicroPython", "Python3", "QSS"] @@ -67,22 +66,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. @@ -342,9 +325,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 +471,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 +501,7 @@ if __name__ == "__main__": try: - main(sys.argv) + main() except SystemExit: raise except Exception: