From 94113c65c8bfbd4edb442a08a4ef6b6a95f8a013 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Tue, 24 Dec 2024 22:39:38 +0000 Subject: rename some backend parts --- src/backend/__init__.py | 6 ++-- src/backend/depsolve.py | 73 +++++++++++++++++++++++++++++++++++++++++++++ src/backend/dlbinpkg.py | 4 +-- src/backend/killemerge.py | 4 --- src/backend/pkgadd.py | 12 ++++---- src/backend/pkgremove.py | 14 ++++----- src/backend/revdepsolve.py | 66 ++++++++++++++++++++++++++++++++++++++++ src/backend/solvedeps.py | 73 --------------------------------------------- src/backend/solverevdeps.py | 66 ---------------------------------------- src/backend/sysclean.py | 10 +++---- src/backend/sysupgrade.py | 10 +++---- src/backend/watchdog.py | 4 +++ 12 files changed, 171 insertions(+), 171 deletions(-) create mode 100644 src/backend/depsolve.py delete mode 100644 src/backend/killemerge.py create mode 100644 src/backend/revdepsolve.py delete mode 100644 src/backend/solvedeps.py delete mode 100644 src/backend/solverevdeps.py create mode 100644 src/backend/watchdog.py (limited to 'src') diff --git a/src/backend/__init__.py b/src/backend/__init__.py index 21dec83..6c7da46 100644 --- a/src/backend/__init__.py +++ b/src/backend/__init__.py @@ -1,17 +1,16 @@ from .checkenv import * +from .depsolve import * from .dlbinpkg import * from .getclr import * from .getenv import * from .getfs import * from .getnews import * -from .killemerge import * from .pkgadd import * from .pkgremove import * from .purgeenv import * from .querydb import * from .recoverdb import * -from .solvedeps import * -from .solverevdeps import * +from .revdepsolve import * from .searchdb import * from .setbranch import * from .setjobs import * @@ -24,3 +23,4 @@ from .syncspm import * from .sysclean import * from .sysinfo import * from .sysupgrade import * +from .watchdog import * diff --git a/src/backend/depsolve.py b/src/backend/depsolve.py new file mode 100644 index 0000000..34d70b8 --- /dev/null +++ b/src/backend/depsolve.py @@ -0,0 +1,73 @@ +#!/usr/bin/python3 + +import animation +import os +import pickle +import signal +import subprocess +import sys +import sisyphus.getfs + + +def sigint_handler(signal, frame): + sys.exit(0) + + +signal.signal(signal.SIGINT, sigint_handler) + + +@animation.wait('resolving dependencies') +def start(pkgname=None, nodeps=False): + bin_list = [] + src_list = [] + is_vague = int() + need_cfg = int() + + if pkgname: + args = ['--quiet', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--misspell-suggestion=n', + '--fuzzy-search=n'] + (['--nodeps'] if nodeps else ['--with-bdeps=y']) + list(pkgname) + else: + args = ['--quiet', '--update', '--deep', '--newuse', '--pretend', '--getbinpkg', '--rebuilt-binaries', + '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'] + + p_exe = subprocess.Popen( + ['emerge'] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + try: + stdout, stderr = p_exe.communicate() + + for p_out in stderr.decode('utf-8').splitlines(): + if pkgname: + if any(key in p_out for key in ["short ebuild name", + "is ambiguous", + "there are no ebuilds to satisfy"]): # likely very fragile + is_vague = int(1) + + if any(key in p_out for key in ["The following keyword changes are necessary to proceed:", + "The following mask changes are necessary to proceed:", + "The following USE changes are necessary to proceed:", + "The following REQUIRED_USE flag constraints are unsatisfied:", + "One of the following masked packages is required to complete your request:"]): # likely very fragile + need_cfg = int(1) + + for p_out in stdout.decode('utf-8').splitlines(): + if "[binary" in p_out: + is_bin = p_out.split("]")[1].split("[")[0].strip(" ") + bin_list.append(is_bin) + + if "[ebuild" in p_out: + is_src = p_out.split("]")[1].split("[")[0].strip(" ") + src_list.append(is_src) + + if pkgname: + pickle.dump([bin_list, src_list, is_vague, need_cfg], open( + os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle"), "wb")) + else: + pickle.dump([bin_list, src_list, is_vague, need_cfg], open( + os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle"), "wb")) + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() diff --git a/src/backend/dlbinpkg.py b/src/backend/dlbinpkg.py index ce089ad..f579b59 100644 --- a/src/backend/dlbinpkg.py +++ b/src/backend/dlbinpkg.py @@ -8,7 +8,7 @@ import subprocess import sys import pickle import sisyphus.getfs -import sisyphus.killemerge +import sisyphus.watchdog def sigint_handler(signal, frame): @@ -40,7 +40,7 @@ def start(dl_world=False, gfx_ui=False): p_exe = subprocess.Popen( ['emerge'] + args, 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) + atexit.register(sisyphus.watchdog.start, p_exe) for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): print(p_out.rstrip()) diff --git a/src/backend/killemerge.py b/src/backend/killemerge.py deleted file mode 100644 index f01af6b..0000000 --- a/src/backend/killemerge.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/python3 - -def start(portageCmd): - portageCmd.terminate() diff --git a/src/backend/pkgadd.py b/src/backend/pkgadd.py index 60ecce8..a64196c 100644 --- a/src/backend/pkgadd.py +++ b/src/backend/pkgadd.py @@ -11,13 +11,13 @@ import subprocess import sys import time import sisyphus.checkenv +import sisyphus.depsolve import sisyphus.dlbinpkg import sisyphus.getclr import sisyphus.getfs -import sisyphus.killemerge -import sisyphus.solvedeps import sisyphus.syncdb import sisyphus.syncall +import sisyphus.watchdog def set_nonblocking(fd): @@ -57,14 +57,14 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False): sys.exit() else: if gfx_ui: - sisyphus.solvedeps.start.__wrapped__( + sisyphus.depsolve.start.__wrapped__( pkgname, nodeps=False) # undecorate else: sisyphus.syncall.start(gfx_ui=False) if nodeps: - sisyphus.solvedeps.start(pkgname, nodeps=True) + sisyphus.depsolve.start(pkgname, nodeps=True) else: - sisyphus.solvedeps.start(pkgname, nodeps=False) + sisyphus.depsolve.start(pkgname, nodeps=False) bin_list, src_list, is_vague, need_cfg = pickle.load( open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle"), "rb")) @@ -305,7 +305,7 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False): p_exe = subprocess.Popen(['emerge'] + go_args + ['--usepkg', '--usepkgonly', '--rebuilt-binaries'] + ( ['--nodeps'] if nodeps else ['--with-bdeps=y']) + (['--oneshot'] if oneshot else []) + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # --nodeps && --oneshot are set to False in the graphical client # kill portage if the program dies or it's terminated by the user - atexit.register(sisyphus.killemerge.start, p_exe) + atexit.register(sisyphus.watchdog.start, p_exe) for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): print(p_out.rstrip()) diff --git a/src/backend/pkgremove.py b/src/backend/pkgremove.py index ad953d5..e9b36b8 100644 --- a/src/backend/pkgremove.py +++ b/src/backend/pkgremove.py @@ -13,9 +13,9 @@ import time import sisyphus.checkenv import sisyphus.getclr import sisyphus.getfs -import sisyphus.killemerge -import sisyphus.solverevdeps +import sisyphus.revdepsolve import sisyphus.syncdb +import sisyphus.watchdog def set_nonblocking(fd): @@ -53,14 +53,14 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): sys.exit() else: if gfx_ui: - sisyphus.solverevdeps.start.__wrapped__( + sisyphus.revdepsolve.start.__wrapped__( pkgname, depclean=True, unmerge=False) else: if unmerge: - sisyphus.solverevdeps.start.__wrapped__( + sisyphus.revdepsolve.start.__wrapped__( pkgname, depclean=False, unmerge=True) else: - sisyphus.solverevdeps.start( + sisyphus.revdepsolve.start( pkgname, depclean=True, unmerge=False) is_installed, is_needed, is_vague, rm_list = pickle.load( @@ -103,7 +103,7 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): 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) + atexit.register(sisyphus.watchdog.start, p_exe) for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): print(p_out.rstrip()) @@ -223,7 +223,7 @@ def start(pkgname, depclean=False, gfx_ui=False, unmerge=False): 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) + atexit.register(sisyphus.watchdog.start, p_exe) for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): print(p_out.rstrip()) diff --git a/src/backend/revdepsolve.py b/src/backend/revdepsolve.py new file mode 100644 index 0000000..bba3932 --- /dev/null +++ b/src/backend/revdepsolve.py @@ -0,0 +1,66 @@ +#!/usr/bin/python3 + +import animation +import os +import pickle +import re +import signal +import subprocess +import sys +import sisyphus.getfs + + +def sigint_handler(signal, frame): + sys.exit(0) + + +signal.signal(signal.SIGINT, sigint_handler) + + +@animation.wait('resolving reverse dependencies') +def start(pkgname=None, depclean=False, unmerge=False): + pattern = r'(\b[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+):\s+([0-9]+(\.[0-9]+){0,4})' + rm_list = [] + + args = ['--quiet', '--pretend', '--verbose'] + args += ['--unmerge'] if unmerge else ['--depclean'] + if pkgname: + args += list(pkgname) + + is_installed = int(1) + is_needed = int(0) + is_vague = int(0) + + try: + p_exe = subprocess.Popen( + ['emerge'] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + + stdout, stderr = p_exe.communicate() + + for p_out in stdout.decode('utf-8').splitlines(): + match = re.search(pattern, p_out) + if match: + to_remove = f"{match.group(1)}-{match.group(2)}" + rm_list.append(to_remove) + + if any(key in p_out for key in ["pulled in by:", "required"]): + is_needed = int(1) + + 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() + + pickle.dump([is_installed, is_needed, is_vague, rm_list], open( + os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "wb")) diff --git a/src/backend/solvedeps.py b/src/backend/solvedeps.py deleted file mode 100644 index 34d70b8..0000000 --- a/src/backend/solvedeps.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/python3 - -import animation -import os -import pickle -import signal -import subprocess -import sys -import sisyphus.getfs - - -def sigint_handler(signal, frame): - sys.exit(0) - - -signal.signal(signal.SIGINT, sigint_handler) - - -@animation.wait('resolving dependencies') -def start(pkgname=None, nodeps=False): - bin_list = [] - src_list = [] - is_vague = int() - need_cfg = int() - - if pkgname: - args = ['--quiet', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--misspell-suggestion=n', - '--fuzzy-search=n'] + (['--nodeps'] if nodeps else ['--with-bdeps=y']) + list(pkgname) - else: - args = ['--quiet', '--update', '--deep', '--newuse', '--pretend', '--getbinpkg', '--rebuilt-binaries', - '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'] - - p_exe = subprocess.Popen( - ['emerge'] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - try: - stdout, stderr = p_exe.communicate() - - for p_out in stderr.decode('utf-8').splitlines(): - if pkgname: - if any(key in p_out for key in ["short ebuild name", - "is ambiguous", - "there are no ebuilds to satisfy"]): # likely very fragile - is_vague = int(1) - - if any(key in p_out for key in ["The following keyword changes are necessary to proceed:", - "The following mask changes are necessary to proceed:", - "The following USE changes are necessary to proceed:", - "The following REQUIRED_USE flag constraints are unsatisfied:", - "One of the following masked packages is required to complete your request:"]): # likely very fragile - need_cfg = int(1) - - for p_out in stdout.decode('utf-8').splitlines(): - if "[binary" in p_out: - is_bin = p_out.split("]")[1].split("[")[0].strip(" ") - bin_list.append(is_bin) - - if "[ebuild" in p_out: - is_src = p_out.split("]")[1].split("[")[0].strip(" ") - src_list.append(is_src) - - if pkgname: - pickle.dump([bin_list, src_list, is_vague, need_cfg], open( - os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle"), "wb")) - else: - pickle.dump([bin_list, src_list, is_vague, need_cfg], open( - os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle"), "wb")) - except KeyboardInterrupt: - p_exe.terminate() - try: - p_exe.wait(1) - except subprocess.TimeoutExpired: - p_exe.kill() - sys.exit() diff --git a/src/backend/solverevdeps.py b/src/backend/solverevdeps.py deleted file mode 100644 index bba3932..0000000 --- a/src/backend/solverevdeps.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python3 - -import animation -import os -import pickle -import re -import signal -import subprocess -import sys -import sisyphus.getfs - - -def sigint_handler(signal, frame): - sys.exit(0) - - -signal.signal(signal.SIGINT, sigint_handler) - - -@animation.wait('resolving reverse dependencies') -def start(pkgname=None, depclean=False, unmerge=False): - pattern = r'(\b[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+):\s+([0-9]+(\.[0-9]+){0,4})' - rm_list = [] - - args = ['--quiet', '--pretend', '--verbose'] - args += ['--unmerge'] if unmerge else ['--depclean'] - if pkgname: - args += list(pkgname) - - is_installed = int(1) - is_needed = int(0) - is_vague = int(0) - - try: - p_exe = subprocess.Popen( - ['emerge'] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - - stdout, stderr = p_exe.communicate() - - for p_out in stdout.decode('utf-8').splitlines(): - match = re.search(pattern, p_out) - if match: - to_remove = f"{match.group(1)}-{match.group(2)}" - rm_list.append(to_remove) - - if any(key in p_out for key in ["pulled in by:", "required"]): - is_needed = int(1) - - 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() - - pickle.dump([is_installed, is_needed, is_vague, rm_list], open( - os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "wb")) diff --git a/src/backend/sysclean.py b/src/backend/sysclean.py index ee58db5..77fa370 100644 --- a/src/backend/sysclean.py +++ b/src/backend/sysclean.py @@ -11,9 +11,9 @@ import subprocess import sys import sisyphus.checkenv import sisyphus.getclr -import sisyphus.killemerge -import sisyphus.solverevdeps +import sisyphus.revdepsolve import sisyphus.syncdb +import sisyphus.watchdog def set_nonblocking(fd): @@ -51,9 +51,9 @@ def start(depclean=False, gfx_ui=False): sys.exit() else: if gfx_ui: - sisyphus.solverevdeps.start.__wrapped__(depclean=True) + sisyphus.revdepsolve.start.__wrapped__(depclean=True) else: - sisyphus.solverevdeps.start(depclean=True) + sisyphus.revdepsolve.start(depclean=True) is_installed, is_needed, is_vague, rm_list = pickle.load( open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgrevdeps.pickle"), "rb")) @@ -62,7 +62,7 @@ def start(depclean=False, gfx_ui=False): p_exe = subprocess.Popen( ['emerge'] + args, 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) + atexit.register(sisyphus.watchdog.start, p_exe) for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): print(p_out.rstrip()) diff --git a/src/backend/sysupgrade.py b/src/backend/sysupgrade.py index c773366..32476c8 100644 --- a/src/backend/sysupgrade.py +++ b/src/backend/sysupgrade.py @@ -11,13 +11,13 @@ import subprocess import sys import time import sisyphus.checkenv +import sisyphus.depsolve import sisyphus.dlbinpkg import sisyphus.getclr import sisyphus.getfs -import sisyphus.killemerge -import sisyphus.solvedeps import sisyphus.syncdb import sisyphus.syncall +import sisyphus.watchdog def set_nonblocking(fd): @@ -57,10 +57,10 @@ def start(ebuild=False, gfx_ui=False): sys.exit() else: if gfx_ui: - sisyphus.solvedeps.start.__wrapped__() # undecorate + sisyphus.depsolve.start.__wrapped__() # undecorate else: sisyphus.syncall.start(gfx_ui=False) - sisyphus.solvedeps.start() + sisyphus.depsolve.start() bin_list, src_list, is_vague, need_cfg = pickle.load( open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle"), "rb")) @@ -291,7 +291,7 @@ def start(ebuild=False, gfx_ui=False): p_exe = subprocess.Popen(['emerge'] + go_args + ['--usepkg', '--usepkgonly', '--rebuilt-binaries', '@world'], 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) + atexit.register(sisyphus.watchdog.start, p_exe) for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): print(p_out.rstrip()) diff --git a/src/backend/watchdog.py b/src/backend/watchdog.py new file mode 100644 index 0000000..f01af6b --- /dev/null +++ b/src/backend/watchdog.py @@ -0,0 +1,4 @@ +#!/usr/bin/python3 + +def start(portageCmd): + portageCmd.terminate() -- cgit v1.2.3