--- a/scripts/install-debugclients.py Wed Jul 13 11:16:20 2022 +0200 +++ b/scripts/install-debugclients.py Wed Jul 13 14:55:47 2022 +0200 @@ -36,17 +36,17 @@ def exit(rcode=0): """ Exit the install script. - + @param rcode result code to report back (integer) """ global currDir - + if sys.platform.startswith("win"): with contextlib.suppress(): - input("Press enter to continue...") # secok - + input("Press enter to continue...") # secok + os.chdir(currDir) - + sys.exit(rcode) @@ -85,17 +85,17 @@ simple assignment. """ global modDir, pyModDir - + import sysconfig - modDir = sysconfig.get_path('platlib') + modDir = sysconfig.get_path("platlib") pyModDir = modDir def copyTree(src, dst, filters, excludeDirs=None, excludePatterns=None): """ Copy files of a directory tree. - + @param src name of the source directory @param dst name of the destination directory @param filters list of filter pattern determining the files to be copied @@ -112,7 +112,7 @@ except OSError: # ignore missing directories return - + for name in names: skipIt = False for excludePattern in excludePatterns: @@ -131,24 +131,22 @@ break else: if os.path.isdir(srcname) and srcname not in excludeDirs: - copyTree(srcname, dstname, filters, - excludePatterns=excludePatterns) + copyTree(srcname, dstname, filters, excludePatterns=excludePatterns) def cleanupSource(dirName): """ Cleanup the sources directory to get rid of leftover files and directories. - + @param dirName name of the directory to prune (string) """ # step 1: delete the __pycache__ directory and all *.pyc files if os.path.exists(os.path.join(dirName, "__pycache__")): shutil.rmtree(os.path.join(dirName, "__pycache__")) - for name in [f for f in os.listdir(dirName) - if fnmatch.fnmatch(f, "*.pyc")]: + for name in [f for f in os.listdir(dirName) if fnmatch.fnmatch(f, "*.pyc")]: os.remove(os.path.join(dirName, name)) - + # step 2: descent into subdirectories and delete them if empty for name in os.listdir(dirName): name = os.path.join(dirName, name) @@ -163,22 +161,21 @@ Uninstall the old eric debug client files. """ global pyModDir, installPackage - + try: # Cleanup the install directories dirname = os.path.join(pyModDir, installPackage) if os.path.exists(dirname): shutil.rmtree(dirname, True) except OSError as msg: - sys.stderr.write( - 'Error: {0}\nTry install with admin rights.\n'.format(msg)) + sys.stderr.write("Error: {0}\nTry install with admin rights.\n".format(msg)) exit(7) def shutilCopy(src, dst, perm=0o644): """ Wrapper function around shutil.copy() to ensure the permissions. - + @param src source file name (string) @param dst destination file name or directory name (string) @param perm permissions to be set (integer) @@ -192,35 +189,35 @@ def installEricDebugClients(): """ Actually perform the installation steps. - + @return result code (integer) """ global distDir, doCleanup, sourceDir, modDir - + # set install prefix, if not None targetDir = ( os.path.normpath(os.path.join(distDir, installPackage)) - if distDir else - os.path.join(modDir, installPackage) + if distDir + else os.path.join(modDir, installPackage) ) - + try: # Install the files # copy the various parts of eric debug clients copyTree( os.path.join(eric7SourceDir, "DebugClients"), targetDir, - ['*.py', '*.pyc', '*.pyo', '*.pyw'], - excludePatterns=["eric7config.py*"]) - + ["*.py", "*.pyc", "*.pyo", "*.pyw"], + excludePatterns=["eric7config.py*"], + ) + # copy the license file shutilCopy(os.path.join(sourceDir, "docs", "LICENSE.GPL3"), targetDir) - + except OSError as msg: - sys.stderr.write( - 'Error: {0}\nTry install with admin rights.\n'.format(msg)) - return(7) - + sys.stderr.write("Error: {0}\nTry install with admin rights.\n".format(msg)) + return 7 + return 0 @@ -235,29 +232,25 @@ # Parse the command line. global progName, modDir, doCleanup, doCompile, distDir global sourceDir, eric7SourceDir - + if sys.version_info < (3, 7, 0) or sys.version_info >= (4, 0, 0): - print('Sorry, the eric debugger requires Python 3.7 or better' - ' for running.') + print("Sorry, the eric debugger requires Python 3.7 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"]) + optlist, args = getopt.getopt(argv[1:], "chzd:", ["help"]) elif sys.platform == "darwin": - optlist, args = getopt.getopt( - argv[1:], "chzd:i:", ["help"]) + optlist, args = getopt.getopt(argv[1:], "chzd:i:", ["help"]) else: - optlist, args = getopt.getopt( - argv[1:], "chzd:i:", ["help"]) + optlist, args = getopt.getopt(argv[1:], "chzd:i:", ["help"]) except getopt.GetoptError as err: print(err) usage() @@ -273,23 +266,23 @@ doCleanup = False elif opt == "-z": doCompile = False - + installFromSource = not os.path.isdir(sourceDir) if installFromSource: sourceDir = os.path.abspath("..") - + eric7SourceDir = ( os.path.join(sourceDir, "eric7") - if os.path.exists(os.path.join(sourceDir, "eric7")) else - os.path.join(sourceDir, "src", "eric7") + if os.path.exists(os.path.join(sourceDir, "eric7")) + else os.path.join(sourceDir, "src", "eric7") ) - + # cleanup source if installing from source if installFromSource: print("Cleaning up source ...") cleanupSource(os.path.join(eric7SourceDir, "DebugClients")) print() - + # cleanup old installation try: if doCleanup: @@ -299,7 +292,7 @@ else: cleanUp() except OSError as msg: - sys.stderr.write('Error: {0}\nTry install as root.\n'.format(msg)) + sys.stderr.write("Error: {0}\nTry install as root.\n".format(msg)) exit(7) if doCompile: @@ -311,32 +304,36 @@ os.path.join(eric7SourceDir, "DebugClients"), ddir=os.path.join(distDir, modDir, installPackage), rx=skipRe, - quiet=True) + quiet=True, + ) else: compileall.compile_dir( os.path.join(eric7SourceDir, "DebugClients"), ddir=os.path.join(modDir, installPackage), rx=skipRe, - quiet=True) + quiet=True, + ) sys.stdout = sys.__stdout__ print("\nInstalling eric debug clients ...") res = installEricDebugClients() - + print("\nInstallation complete.") print() - + exit(res) - - + + if __name__ == "__main__": try: main(sys.argv) except SystemExit: raise except Exception: - print("""An internal error occured. Please report all the output""" - """ of the program,\nincluding the following traceback, to""" - """ eric-bugs@eric-ide.python-projects.org.\n""") + print( + """An internal error occured. Please report all the output""" + """ of the program,\nincluding the following traceback, to""" + """ eric-bugs@eric-ide.python-projects.org.\n""" + ) raise #