def copyFile(source_path, dest_path): """Improved version of shutil.copy This handles errors with a chance to correct them, e.g. on Windows, files might be locked by running program or virus checkers. """ while 1: try: shutil.copyfile(source_path, dest_path) except PermissionError as e: if e.errno != errno.EACCES: raise general.warning("Problem copying file %s:" % e) try: reply = raw_input("Retry? (YES/no) ") or "yes" except EOFError: reply = "no" if reply.upper() == "YES": continue raise break
def getCachedDownload( url, binary, flatten, is_arch_specific, specificity, message, reject, assume_yes_for_downloads, ): # Many branches to deal with, pylint: disable=too-many-branches,too-many-statements nuitka_app_dir = getAppDir() nuitka_app_dir = os.path.join(nuitka_app_dir, os.path.basename(binary).replace(".exe", "")) if is_arch_specific: nuitka_app_dir = os.path.join(nuitka_app_dir, is_arch_specific) if specificity: nuitka_app_dir = os.path.join(nuitka_app_dir, specificity) download_path = os.path.join(nuitka_app_dir, os.path.basename(url)) exe_path = os.path.join(nuitka_app_dir, binary) makePath(nuitka_app_dir) if not os.path.isfile(download_path) and not os.path.isfile(exe_path): if assume_yes_for_downloads: reply = "y" else: Tracing.printLine("""\ %s Is it OK to download and put it in '%s'. No installer needed, cached, one time question. Proceed and download? [Yes]/No """ % (message, nuitka_app_dir)) Tracing.flushStandardOutputs() try: reply = raw_input() except EOFError: reply = "no" if reply.lower() in ("no", "n"): if reject is not None: Tracing.general.sysexit(reject) else: Tracing.general.info("Downloading '%s'." % url) try: urlretrieve(url, download_path) except Exception: # Any kind of error, pylint: disable=broad-except try: urlretrieve(url.replace("https://", "http://"), download_path) except Exception: # Any kind of error, pylint: disable=broad-except Tracing.general.sysexit( "Failed to download '%s'. Contents should manually be copied to '%s'." % (url, download_path)) if not os.path.isfile(exe_path) and os.path.isfile(download_path): Tracing.general.info("Extracting to '%s'" % exe_path) import zipfile try: # Not all Python versions support using it as a context manager, pylint: disable=consider-using-with zip_file = zipfile.ZipFile(download_path) for zip_info in zip_file.infolist(): if zip_info.filename[-1] == "/": continue if flatten: zip_info.filename = os.path.basename(zip_info.filename) zip_file.extract(zip_info, nuitka_app_dir) except Exception: # Catching anything zip throws, pylint: disable=broad-except Tracing.general.info( "Problem with the downloaded zip file, deleting it.") deleteFile(binary, must_exist=False) deleteFile(download_path, must_exist=True) Tracing.general.sysexit("Error, need %r as extracted from %r." % (binary, url)) # Check success here, and make sure it's executable. if os.path.isfile(exe_path): addFileExecutablePermission(exe_path) else: if reject: Tracing.general.sysexit(reject) exe_path = None return exe_path
def getDependsExePath(): """ Return the path of depends.exe (for Windows). Will prompt the user to download if not already cached in AppData directory for Nuitka. """ if Utils.getArchitecture() == "x86": depends_url = "http://dependencywalker.com/depends22_x86.zip" else: depends_url = "http://dependencywalker.com/depends22_x64.zip" if "APPDATA" not in os.environ: sys.exit("Error, standalone mode cannot find 'APPDATA' environment.") nuitka_app_dir = os.path.join(os.environ["APPDATA"], "nuitka") if not os.path.isdir(nuitka_app_dir): makePath(nuitka_app_dir) nuitka_depends_zip = os.path.join(nuitka_app_dir, os.path.basename(depends_url)) if not os.path.isfile(nuitka_depends_zip): Tracing.printLine("""\ Nuitka will make use of Dependency Walker (http://dependencywalker.com) tool to analyze the dependencies of Python extension modules. Is it OK to download and put it in APPDATA (no installer needed, cached, one time question).""") reply = raw_input("Proceed and download? [Yes]/No ") if reply.lower() in ("no", 'n'): sys.exit( "Nuitka does not work in --standalone on Windows without.") info("Downloading '%s'" % depends_url) urlretrieve(depends_url, nuitka_depends_zip) nuitka_depends_dir = os.path.join(nuitka_app_dir, Utils.getArchitecture()) if not os.path.isdir(nuitka_depends_dir): os.makedirs(nuitka_depends_dir) depends_exe = os.path.join(nuitka_depends_dir, "depends.exe") if not os.path.isfile(depends_exe): info("Extracting to '%s'" % depends_exe) import zipfile try: depends_zip = zipfile.ZipFile(nuitka_depends_zip) depends_zip.extractall(nuitka_depends_dir) except Exception: # Catching anything zip throws, pylint:disable=W0703 info("Problem with the downloaded zip file, deleting it.") deleteFile(depends_exe, must_exist=False) deleteFile(nuitka_depends_zip, must_exist=True) sys.exit("Error, need '%s' as extracted from '%s'." % (depends_exe, depends_url)) assert os.path.isfile(depends_exe) return depends_exe
def getDependsExePath(): """ Return the path of depends.exe (for Windows). Will prompt the user to download if not already cached in AppData directory for Nuitka. """ if Utils.getArchitecture() == "x86": depends_url = "http://dependencywalker.com/depends22_x86.zip" else: depends_url = "http://dependencywalker.com/depends22_x64.zip" nuitka_app_dir = getAppDir() nuitka_depends_dir = os.path.join(nuitka_app_dir, Utils.getArchitecture()) nuitka_depends_zip = os.path.join(nuitka_depends_dir, os.path.basename(depends_url)) depends_exe = os.path.join(nuitka_depends_dir, "depends.exe") makePath(nuitka_depends_dir) if not os.path.isfile(nuitka_depends_zip) and not os.path.isfile( depends_exe): if assumeYesForDownloads(): reply = "y" else: Tracing.printLine("""\ Nuitka will make use of Dependency Walker (http://dependencywalker.com) tool to analyze the dependencies of Python extension modules. Is it OK to download and put it in "%s". No installer needed, cached, one time question. Proceed and download? [Yes]/No """ % (nuitka_app_dir)) Tracing.flushStdout() reply = raw_input() if reply.lower() in ("no", "n"): sys.exit( "Nuitka does not work in --standalone on Windows without.") info("Downloading '%s'" % depends_url) try: urlretrieve(depends_url, nuitka_depends_zip) except Exception: # Any kind of error, pylint: disable=broad-except sys.exit("""Failed to download '%s'.\ Contents should manually be extracted to '%s'.""" % (depends_url, nuitka_depends_dir)) if not os.path.isfile(depends_exe): info("Extracting to '%s'" % depends_exe) import zipfile try: depends_zip = zipfile.ZipFile(nuitka_depends_zip) depends_zip.extractall(nuitka_depends_dir) except Exception: # Catching anything zip throws, pylint: disable=broad-except info("Problem with the downloaded zip file, deleting it.") deleteFile(depends_exe, must_exist=False) deleteFile(nuitka_depends_zip, must_exist=True) sys.exit("Error, need '%s' as extracted from '%s'." % (depends_exe, depends_url)) assert os.path.isfile(depends_exe) return depends_exe
def getDependsExePath(): """ Return the path of depends.exe (for Windows). Will prompt the user to download if not already cached in AppData directory for Nuitka. """ if Utils.getArchitecture() == "x86": depends_url = "http://dependencywalker.com/depends22_x86.zip" else: depends_url = "http://dependencywalker.com/depends22_x64.zip" if "APPDATA" not in os.environ: sys.exit("Error, standalone mode cannot find 'APPDATA' environment.") nuitka_app_dir = os.path.join(os.environ["APPDATA"], "nuitka") if not Utils.isDir(nuitka_app_dir): os.makedirs(nuitka_app_dir) nuitka_depends_zip = os.path.join( nuitka_app_dir, os.path.basename(depends_url) ) if not Utils.isFile(nuitka_depends_zip): Tracing.printLine("""\ Nuitka will make use of Dependency Walker (http://dependencywalker.com) tool to analyze the dependencies of Python extension modules. Is it OK to download and put it in APPDATA (no installer needed, cached, one time question).""") reply = raw_input("Proceed and download? [Yes]/No ") if reply.lower() in ("no", "n"): sys.exit("Nuitka does not work in --standalone on Windows without.") info("Downloading '%s'" % depends_url) urlretrieve( depends_url, nuitka_depends_zip ) nuitka_depends_dir = os.path.join( nuitka_app_dir, Utils.getArchitecture() ) if not Utils.isDir(nuitka_depends_dir): os.makedirs(nuitka_depends_dir) depends_exe = os.path.join( nuitka_depends_dir, "depends.exe" ) if not Utils.isFile(depends_exe): info("Extracting to '%s'" % depends_exe) import zipfile try: depends_zip = zipfile.ZipFile(nuitka_depends_zip) depends_zip.extractall(nuitka_depends_dir) except Exception: # Catching anything zip throws, pylint:disable=W0703 info("Problem with the downloaded zip file, deleting it.") Utils.deleteFile(depends_exe, must_exist = False) Utils.deleteFile(nuitka_depends_zip, must_exist = True) sys.exit( "Error, need '%s' as extracted from '%s'." % ( depends_exe, depends_url ) ) assert Utils.isFile(depends_exe) return depends_exe
def getDependsExePath(): """ Return the path of depends.exe (for Windows). Will prompt the user to download if not already cached in AppData directory for Nuitka. """ if Utils.getArchitecture() == "x86": depends_url = "http://dependencywalker.com/depends22_x86.zip" else: depends_url = "http://dependencywalker.com/depends22_x64.zip" nuitka_app_dir = getAppDir() nuitka_depends_dir = os.path.join(nuitka_app_dir, Utils.getArchitecture()) nuitka_depends_zip = os.path.join(nuitka_depends_dir, os.path.basename(depends_url)) depends_exe = os.path.join(nuitka_depends_dir, "depends.exe") makePath(nuitka_depends_dir) if not os.path.isfile(nuitka_depends_zip) and not os.path.isfile(depends_exe): if assumeYesForDownloads(): reply = "y" else: Tracing.printLine( """\ Nuitka will make use of Dependency Walker (http://dependencywalker.com) tool to analyze the dependencies of Python extension modules. Is it OK to download and put it in "%s". No installer needed, cached, one time question. Proceed and download? [Yes]/No """ % (nuitka_app_dir) ) Tracing.flushStdout() reply = raw_input() if reply.lower() in ("no", "n"): sys.exit("Nuitka does not work in --standalone on Windows without.") info("Downloading '%s'" % depends_url) try: urlretrieve(depends_url, nuitka_depends_zip) except Exception: # Any kind of error, pylint: disable=broad-except sys.exit( """Failed to download '%s'.\ Contents should manually be extracted to '%s'.""" % (depends_url, nuitka_depends_dir) ) if not os.path.isfile(depends_exe): info("Extracting to '%s'" % depends_exe) import zipfile try: depends_zip = zipfile.ZipFile(nuitka_depends_zip) depends_zip.extractall(nuitka_depends_dir) except Exception: # Catching anything zip throws, pylint:disable=W0703 info("Problem with the downloaded zip file, deleting it.") deleteFile(depends_exe, must_exist=False) deleteFile(nuitka_depends_zip, must_exist=True) sys.exit( "Error, need '%s' as extracted from '%s'." % (depends_exe, depends_url) ) assert os.path.isfile(depends_exe) return depends_exe