scripts/install-debugclients.py

branch
eric7
changeset 10300
60e8f2175b3b
parent 10170
6cf1ee737d8f
child 10403
ea3320d5e8e9
--- a/scripts/install-debugclients.py	Thu Nov 09 09:37:23 2023 +0100
+++ b/scripts/install-debugclients.py	Thu Nov 09 11:23:48 2023 +0100
@@ -11,10 +11,10 @@
 Installation script for the eric debug clients.
 """
 
+import argparse
 import compileall
 import contextlib
 import fnmatch
-import getopt
 import importlib
 import io
 import json
@@ -26,7 +26,6 @@
 import sysconfig
 
 # Define the globals.
-progName = None
 currDir = os.getcwd()
 modDir = None
 pyModDir = None
@@ -55,35 +54,6 @@
     sys.exit(rcode)
 
 
-def usage(rcode=2):
-    """
-    Display a usage message and exit.
-
-    @param rcode the return code passed back to the calling process.
-    """
-    global progName, modDir, distDir
-
-    print()
-    print("Usage:")
-    if sys.platform == "darwin":
-        print("    {0} [-chz] [-d dir] [-i dir]".format(progName))
-    elif sys.platform.startswith("win"):
-        print("    {0} [-chz] [-d dir]".format(progName))
-    else:
-        print("    {0} [-chz][-d dir] [-i dir]".format(progName))
-    print("where:")
-    print("    -h, --help display this help message")
-    print("    -d dir     where eric debug client files will be installed")
-    print("               (default: {0})".format(modDir))
-    if not sys.platform.startswith("win"):
-        print("    -i dir     temporary install prefix")
-        print("               (default: {0})".format(distDir))
-    print("    -c         don't cleanup old installation first")
-    print("    -z         don't compile the installed python files")
-
-    exit(rcode)
-
-
 def initGlobals():
     """
     Module function to set the values of globals that need more than a
@@ -350,8 +320,8 @@
         print("\n")
 
     # perform dependency checks
-    if sys.version_info < (3, 8, 0) or sys.version_info >= (3, 12, 0):
-        print("Sorry, you must have Python 3.8.0 or higher, but less 3.12.0.")
+    if sys.version_info < (3, 8, 0) or sys.version_info >= (3, 13, 0):
+        print("Sorry, you must have Python 3.8.0 or higher, but less 3.13.0.")
         print("Yours is {0}.".format(".".join(str(v) for v in sys.version_info[:3])))
         exit(5)
 
@@ -390,49 +360,71 @@
     print()
 
 
+def createArgumentParser():
+    """
+    Function to create an argument parser.
+
+    @return created argument parser object
+    @rtype argparse.ArgumentParser
+    """
+    parser = argparse.ArgumentParser(
+        description="Install eric7 debug clients from the source code tree."
+    )
+
+    parser.add_argument(
+        "-d",
+        metavar="dir",
+        default=modDir,
+        help="directory where eric debug client files will be installed"
+        " (default: {0})".format(modDir),
+    )
+    if not sys.platform.startswith(("win", "cygwin")):
+        parser.add_argument(
+            "-i",
+            metavar="dir",
+            default=distDir,
+            help="temporary install prefix (default: {0})".format(distDir),
+        )
+    parser.add_argument(
+        "-c",
+        action="store_false",
+        help="don't cleanup old installation first",
+    )
+    parser.add_argument(
+        "-z",
+        action="store_false",
+        help="don't compile the installed python files",
+    )
+
+    return parser
+
+
 def main(argv):
     """
     The main function of the script.
 
     @param argv the list of command line arguments.
     """
-    # Parse the command line.
-    global progName, modDir, doCleanup, doCompile, distDir
+    global modDir, doCleanup, doCompile, distDir
     global sourceDir, eric7SourceDir
 
     if sys.version_info < (3, 8, 0) or sys.version_info >= (4, 0, 0):
         print("Sorry, the eric debugger requires Python 3.8 or better for running.")
         exit(5)
 
-    progName = os.path.basename(argv[0])
-
     if os.path.dirname(argv[0]):
         os.chdir(os.path.dirname(argv[0]))
 
     initGlobals()
 
-    try:
-        if sys.platform.startswith("win"):
-            optlist, args = getopt.getopt(argv[1:], "chzd:", ["help"])
-        elif sys.platform == "darwin":
-            optlist, args = getopt.getopt(argv[1:], "chzd:i:", ["help"])
-        else:
-            optlist, args = getopt.getopt(argv[1:], "chzd:i:", ["help"])
-    except getopt.GetoptError as err:
-        print(err)
-        usage()
+    parser = createArgumentParser()
+    args = parser.parse_args()
 
-    for opt, arg in optlist:
-        if opt in ["-h", "--help"]:
-            usage(0)
-        elif opt == "-d":
-            modDir = arg
-        elif opt == "-i":
-            distDir = os.path.normpath(arg)
-        elif opt == "-c":
-            doCleanup = False
-        elif opt == "-z":
-            doCompile = False
+    modDir = args.d
+    doCleanup = args.c
+    doCompile = args.z
+    if not sys.platform.startswith(("win", "cygwin")) and args.i:
+        distDir = os.path.normpath(args.i)
 
     # check dependencies
     doDependancyChecks()

eric ide

mercurial