From 5a8384b21bb066ca44f6823871ad1d0aa1aa2c28 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Thu, 29 Feb 2024 03:48:08 +0000 Subject: bugfix : https://bugs.redcorelinux.org/show_bug.cgi?id=156 --- src/backend/rmpkgsrc.py | 242 ++++++++++++++++++++++++++------------------ src/backend/solverevdeps.py | 42 +++++++- 2 files changed, 179 insertions(+), 105 deletions(-) diff --git a/src/backend/rmpkgsrc.py b/src/backend/rmpkgsrc.py index 5502bc8..63343fc 100644 --- a/src/backend/rmpkgsrc.py +++ b/src/backend/rmpkgsrc.py @@ -63,64 +63,42 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): sisyphus.solverevdeps.start( pkgname, depclean=True, unmerge=False) - is_needed = pickle.load( - open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "rb")) - - if unmerge: - print("\n" + sisyphus.getclr.bright_white + "Selected packages are slated for" + sisyphus.getclr.reset + " " + sisyphus.getclr.green + - "'forced'" + sisyphus.getclr.reset + " " + sisyphus.getclr.bright_white + "removal." + sisyphus.getclr.reset + "\n") - while True: - user_input = input(sisyphus.getclr.bright_white + "Would you like to proceed?" + sisyphus.getclr.reset + " " + - "[" + sisyphus.getclr.bright_green + "Yes" + sisyphus.getclr.reset + "/" + sisyphus.getclr.bright_red + "No" + sisyphus.getclr.reset + "]" + " ") - if user_input.lower() in ['yes', 'y', '']: - while True: - confirmation_input = input(sisyphus.getclr.bright_white + "Are you sure you would like to proceed?" + sisyphus.getclr.reset + " " + - "[" + sisyphus.getclr.bright_green + "Yes" + sisyphus.getclr.reset + "/" + sisyphus.getclr.bright_red + "No" + sisyphus.getclr.reset + "]" + " ") - if confirmation_input.lower() in ['yes', 'y', '']: - p_exe = subprocess.Popen( - ['emerge', '--quiet', '--unmerge'] + list(pkgname)) - try: - set_nonblocking(sys.stdout.fileno()) - spinner_animation() - - sel = selectors.DefaultSelector() - sel.register(sys.stdin, selectors.EVENT_READ) - - while True: - events = sel.select(timeout=0.1) - for key, mask in events: - if key.fileobj == sys.stdin: - line = sys.stdin.readline().strip() - if line.lower() == 'q': - sys.exit() - if p_exe.poll() is not None: - break - except KeyboardInterrupt: - p_exe.terminate() - try: - p_exe.wait(1) - except subprocess.TimeoutExpired: - p_exe.kill() - sys.exit() - finally: - p_exe.wait() - sisyphus.syncdb.lcl_tbl() - break - elif confirmation_input.lower() in ['no', 'n']: - break - else: - print("\nSorry, response" + " " + "'" + - confirmation_input + "'" + " " + "not understood.\n") - continue - break - elif user_input.lower() in ['no', 'n']: - break + is_installed, is_needed, is_vague = pickle.load(open(os.path.join( + sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "rb")) + + if is_vague != 0: # catch ambiguous packages + if unmerge: + p_exe = subprocess.Popen( + ['emerge', '--unmerge', '--quiet', '--pretend', '--verbose'] + list(pkgname)) + try: + p_exe.wait() + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() + else: + if gfx_ui: + pass # GUI always calls /, no ambiguity else: - print("\nSorry, response" + " " + "'" + - user_input + "'" + " " + "not understood.\n") - continue - else: - if is_needed != 0: + p_exe = subprocess.Popen( + ['emerge', '--depclean', '--quiet', '--pretend', '--verbose'] + list(pkgname)) + try: + p_exe.wait() + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() + + elif is_needed != 0: + if unmerge: + pass + else: if gfx_ui: p_exe = subprocess.Popen(['emerge'] + args + ['--pretend', '--verbose'] + list( pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -131,7 +109,8 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): print(p_out.rstrip()) p_exe.wait() - print("\nWon't uninstall! Other packages depend on " + str(pkgname)) + print( + "\nUnable to proceed! There are other packages with dependencies that prevent removal.") else: p_exe = subprocess.Popen( ['emerge'] + args + ['--pretend', '--verbose'] + list(pkgname)) @@ -160,57 +139,64 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): sys.exit() finally: p_exe.wait() - print(sisyphus.getclr.bright_red + "\nWon't uninstall! Other packages depend on " + - sisyphus.getclr.reset + str(pkgname)) + print(sisyphus.getclr.bright_red + + "\nUnable to proceed! There are other packages with dependencies that prevent removal." + sisyphus.getclr.reset) print(sisyphus.getclr.bright_white + "Use the " + sisyphus.getclr.reset + sisyphus.getclr.green + "'--force'" + sisyphus.getclr.reset + sisyphus.getclr.bright_white + " option to override at your own risk!\n" + sisyphus.getclr.reset) - else: - if gfx_ui: - p_exe = subprocess.Popen( - ['emerge'] + args + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # kill portage if the program dies or it's terminated by the user - atexit.register(sisyphus.killemerge.start, p_exe) - - for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): - print(p_out.rstrip()) - p_exe.wait() - sisyphus.syncdb.lcl_tbl() - else: + else: + if is_installed == 0: + print(sisyphus.getclr.bright_red + + "\nUnable to proceed! One or more selected packages could not be located for removal.\n" + sisyphus.getclr.reset) + sys.exit() + else: + if unmerge: print("\n" + sisyphus.getclr.bright_white + "Selected packages are slated for" + sisyphus.getclr.reset + " " + sisyphus.getclr.green + - "'safe'" + sisyphus.getclr.reset + " " + sisyphus.getclr.bright_white + "removal." + sisyphus.getclr.reset + "\n") + "'forced'" + sisyphus.getclr.reset + " " + sisyphus.getclr.bright_white + "removal." + sisyphus.getclr.reset + "\n") while True: user_input = input(sisyphus.getclr.bright_white + "Would you like to proceed?" + sisyphus.getclr.reset + " " + "[" + sisyphus.getclr.bright_green + "Yes" + sisyphus.getclr.reset + "/" + sisyphus.getclr.bright_red + "No" + sisyphus.getclr.reset + "]" + " ") if user_input.lower() in ['yes', 'y', '']: - p_exe = subprocess.Popen( - ['emerge'] + args + list(pkgname)) - try: - set_nonblocking(sys.stdout.fileno()) - spinner_animation() - - sel = selectors.DefaultSelector() - sel.register(sys.stdin, selectors.EVENT_READ) - - while True: - events = sel.select(timeout=0.1) - for key, mask in events: - if key.fileobj == sys.stdin: - line = sys.stdin.readline().strip() - if line.lower() == 'q': - sys.exit() - if p_exe.poll() is not None: - break - except KeyboardInterrupt: - p_exe.terminate() - try: - p_exe.wait(1) - except subprocess.TimeoutExpired: - p_exe.kill() - sys.exit() - finally: - p_exe.wait() - sisyphus.syncdb.lcl_tbl() + while True: + confirmation_input = input(sisyphus.getclr.bright_white + "Are you sure you would like to proceed?" + sisyphus.getclr.reset + " " + + "[" + sisyphus.getclr.bright_green + "Yes" + sisyphus.getclr.reset + "/" + sisyphus.getclr.bright_red + "No" + sisyphus.getclr.reset + "]" + " ") + if confirmation_input.lower() in ['yes', 'y', '']: + p_exe = subprocess.Popen( + ['emerge', '--quiet', '--unmerge'] + list(pkgname)) + try: + set_nonblocking(sys.stdout.fileno()) + spinner_animation() + + sel = selectors.DefaultSelector() + sel.register( + sys.stdin, selectors.EVENT_READ) + + while True: + events = sel.select(timeout=0.1) + for key, mask in events: + if key.fileobj == sys.stdin: + line = sys.stdin.readline().strip() + if line.lower() == 'q': + sys.exit() + if p_exe.poll() is not None: + break + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() + finally: + p_exe.wait() + sisyphus.syncdb.lcl_tbl() + break + elif confirmation_input.lower() in ['no', 'n']: + break + else: + print("\nSorry, response" + " " + "'" + + confirmation_input + "'" + " " + "not understood.\n") + continue break elif user_input.lower() in ['no', 'n']: break @@ -218,3 +204,57 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): print("\nSorry, response" + " " + "'" + user_input + "'" + " " + "not understood.\n") continue + else: + if gfx_ui: + p_exe = subprocess.Popen( + ['emerge'] + args + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # kill portage if the program dies or it's terminated by the user + atexit.register(sisyphus.killemerge.start, p_exe) + + for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): + print(p_out.rstrip()) + + p_exe.wait() + sisyphus.syncdb.lcl_tbl() + else: + print("\n" + sisyphus.getclr.bright_white + "Selected packages are slated for" + sisyphus.getclr.reset + " " + sisyphus.getclr.green + + "'safe'" + sisyphus.getclr.reset + " " + sisyphus.getclr.bright_white + "removal." + sisyphus.getclr.reset + "\n") + while True: + user_input = input(sisyphus.getclr.bright_white + "Would you like to proceed?" + sisyphus.getclr.reset + " " + + "[" + sisyphus.getclr.bright_green + "Yes" + sisyphus.getclr.reset + "/" + sisyphus.getclr.bright_red + "No" + sisyphus.getclr.reset + "]" + " ") + if user_input.lower() in ['yes', 'y', '']: + p_exe = subprocess.Popen( + ['emerge'] + args + list(pkgname)) + try: + set_nonblocking(sys.stdout.fileno()) + spinner_animation() + + sel = selectors.DefaultSelector() + sel.register(sys.stdin, selectors.EVENT_READ) + + while True: + events = sel.select(timeout=0.1) + for key, mask in events: + if key.fileobj == sys.stdin: + line = sys.stdin.readline().strip() + if line.lower() == 'q': + sys.exit() + if p_exe.poll() is not None: + break + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() + finally: + p_exe.wait() + sisyphus.syncdb.lcl_tbl() + break + elif user_input.lower() in ['no', 'n']: + break + else: + print("\nSorry, response" + " " + "'" + + user_input + "'" + " " + "not understood.\n") + continue diff --git a/src/backend/solverevdeps.py b/src/backend/solverevdeps.py index 0400be9..12b4eb4 100644 --- a/src/backend/solverevdeps.py +++ b/src/backend/solverevdeps.py @@ -18,10 +18,33 @@ signal.signal(signal.SIGINT, sigint_handler) @animation.wait('resolving reverse dependencies') def start(pkgname=None, depclean=False, unmerge=False): + is_installed = int(1) is_needed = int(0) + is_vague = int(0) if unmerge: - pass # behave like portage and ignore reverse dependencies + is_needed = int(0) + try: + p_exe = subprocess.Popen(['emerge', '--unmerge', '--quiet', '--pretend', '--verbose'] + list( + pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + stdout, stderr = p_exe.communicate() + + for p_out in stderr.decode('utf-8').splitlines(): + if any(key in p_out for key in ["Couldn't find", + "to depclean."]): + is_installed = int(0) + + if any(key in p_out for key in ["short ebuild name", + "is ambiguous"]): + is_vague = int(1) + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() else: try: p_exe = subprocess.Popen(['emerge', '--depclean', '--quiet', '--pretend', @@ -30,11 +53,19 @@ def start(pkgname=None, depclean=False, unmerge=False): stdout, stderr = p_exe.communicate() for p_out in stdout.decode('utf-8').splitlines(): - if any(key in p_out for key in ["pulled in by:", "required"]): + if any(key in p_out for key in ["pulled in by:", + "required"]): is_needed = int(1) - pickle.dump(is_needed, open(os.path.join( - sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "wb")) + for p_out in stderr.decode('utf-8').splitlines(): + if any(key in p_out for key in ["Couldn't find", + "to depclean."]): + is_installed = int(0) + + if any(key in p_out for key in ["short ebuild name", + "is ambiguous"]): + is_vague = int(1) + except KeyboardInterrupt: p_exe.terminate() try: @@ -42,3 +73,6 @@ def start(pkgname=None, depclean=False, unmerge=False): except subprocess.TimeoutExpired: p_exe.kill() sys.exit() + + pickle.dump([is_installed, is_needed, is_vague], open(os.path.join( + sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "wb")) -- cgit v1.2.3