diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/__init__.py | 3 | ||||
-rw-r--r-- | src/backend/searchdb.py (renamed from src/backend/search.py) | 0 | ||||
-rw-r--r-- | src/backend/solverdeps.py | 37 | ||||
-rw-r--r-- | src/backend/uninstall.py | 71 |
4 files changed, 92 insertions, 19 deletions
diff --git a/src/backend/__init__.py b/src/backend/__init__.py index 9c38585..d6dc4c7 100644 --- a/src/backend/__init__.py +++ b/src/backend/__init__.py @@ -10,7 +10,8 @@ from .mirrors import * from .purgeenv import * from .recoverdb import * from .solvedeps import * -from .search import * +from .solverdeps import * +from .searchdb import * from .setbranch import * from .setjobs import * from .setprofile import * diff --git a/src/backend/search.py b/src/backend/searchdb.py index 22bd4ba..22bd4ba 100644 --- a/src/backend/search.py +++ b/src/backend/searchdb.py diff --git a/src/backend/solverdeps.py b/src/backend/solverdeps.py new file mode 100644 index 0000000..b866cc8 --- /dev/null +++ b/src/backend/solverdeps.py @@ -0,0 +1,37 @@ +#!/usr/bin/python3 + +import animation +import signal +import subprocess +import sys + + +def sigint_handler(signal, frame): + sys.exit(0) + + +signal.signal(signal.SIGINT, sigint_handler) + + +@animation.wait('resolving reverse dependencies') +def start(pkgname=None): + is_needed = int(0) + + p_exe = subprocess.Popen( + ['emerge', '--depclean', '--quiet', '--pretend', '--verbose'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + try: + 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"]): + is_needed = int(1) + + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() + return is_needed diff --git a/src/backend/uninstall.py b/src/backend/uninstall.py index 70150f9..ede3947 100644 --- a/src/backend/uninstall.py +++ b/src/backend/uninstall.py @@ -8,6 +8,7 @@ import sys import sisyphus.checkenv import sisyphus.getcolor import sisyphus.killemerge +import sisyphus.solverdeps import sisyphus.syncdb @@ -25,24 +26,16 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): print(sisyphus.getcolor.bright_red + "\nYou need root permissions to do this!\n" + sisyphus.getcolor.reset) sys.exit() + else: + if gfx_ui: + is_needed = sisyphus.solverdeps.start.__wrapped__(pkgname) + else: + is_needed = sisyphus.solverdeps.start(pkgname) - if unmerge: - p_exe = subprocess.Popen( - ['emerge', '--quiet', '--unmerge', '--ask'] + list(pkgname)) - try: - p_exe.wait() - sisyphus.syncdb.lcl_tbl() - except KeyboardInterrupt: - p_exe.terminate() - try: - p_exe.wait(1) - except subprocess.TimeoutExpired: - p_exe.kill() - sys.exit() - elif depclean: + if is_needed != 0: if gfx_ui: - p_exe = subprocess.Popen( - ['emerge'] + args + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p_exe = subprocess.Popen(['emerge'] + args + ['--pretend', '--verbose'] + list( + 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) @@ -50,10 +43,27 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): print(p_out.rstrip()) p_exe.wait() - sisyphus.syncdb.lcl_tbl() + print("\nWon't uninstall! Other packages depend on " + str(pkgname)) else: p_exe = subprocess.Popen( - ['emerge'] + args + ['--ask'] + list(pkgname)) + ['emerge'] + args + ['--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() + print(sisyphus.getcolor.bright_red + + "\nWon't uninstall! Other packages depend on " + sisyphus.getcolor.reset + str(pkgname)) + print(sisyphus.getcolor.bright_red + "Use the " + sisyphus.getcolor.reset + sisyphus.getcolor.green + "'--force'" + + sisyphus.getcolor.reset + sisyphus.getcolor.bright_red + " option to override at your own risk!\n" + sisyphus.getcolor.reset) + else: + if unmerge: + p_exe = subprocess.Popen( + ['emerge', '--quiet', '--unmerge', '--ask'] + list(pkgname)) try: p_exe.wait() sisyphus.syncdb.lcl_tbl() @@ -64,3 +74,28 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): except subprocess.TimeoutExpired: p_exe.kill() sys.exit() + elif depclean: + 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: + p_exe = subprocess.Popen( + ['emerge'] + args + ['--ask'] + list(pkgname)) + try: + p_exe.wait() + sisyphus.syncdb.lcl_tbl() + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() |