summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2024-01-20 22:52:36 +0000
committerV3n3RiX <venerix@koprulu.sector>2024-01-20 22:52:36 +0000
commit5cf564d3b5109c2a9e4b5917eb7d834f8b911d3b (patch)
tree1a237d98fdd45a123b1175c35bf068ec6c42ed54
parenta513187d4842758e63fda6abd90c86d4f9d19928 (diff)
don't silently fail while attempting to uninstall a package with reverse dependenciesv6.2401.0
-rw-r--r--src/backend/__init__.py3
-rw-r--r--src/backend/searchdb.py (renamed from src/backend/search.py)0
-rw-r--r--src/backend/solverdeps.py37
-rw-r--r--src/backend/uninstall.py71
-rwxr-xr-xsrc/frontend/cli/sisyphus-cli.py4
5 files changed, 94 insertions, 21 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()
diff --git a/src/frontend/cli/sisyphus-cli.py b/src/frontend/cli/sisyphus-cli.py
index 93928c4..82773d3 100755
--- a/src/frontend/cli/sisyphus-cli.py
+++ b/src/frontend/cli/sisyphus-cli.py
@@ -89,13 +89,13 @@ def search(package: List[str] = typer.Argument(...),
cat, pn = package[0].split('/')
else:
cat, pn = '', package[0]
- sisyphus.search.start(filter.value, cat, pn, desc, quiet)
+ sisyphus.searchdb.start(filter.value, cat, pn, desc, quiet)
else:
if not package:
raise typer.Exit(
'No search term provided, try: sisyphus search --help')
else:
- sisyphus.search.estart(package)
+ sisyphus.searchdb.estart(package)
@app.command("install")