summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2025-02-06 02:38:08 +0000
committerV3n3RiX <venerix@koprulu.sector>2025-02-06 02:38:08 +0000
commit6c11506c5c38314d0204995752f7cd8b786b4521 (patch)
tree694c09afce624f1bb2b3b13020d3c8edcf2d0028 /src/backend
parent75d9eb580b6bd2ec01abecc6c884ce0963dc539b (diff)
backend : pkgadd, port to colorama API
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/pkgadd.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/backend/pkgadd.py b/src/backend/pkgadd.py
index a64196c..1a8e844 100644
--- a/src/backend/pkgadd.py
+++ b/src/backend/pkgadd.py
@@ -1,6 +1,7 @@
#!/usr/bin/python3
import atexit
+import colorama
import fcntl
import io
import os
@@ -13,11 +14,13 @@ import time
import sisyphus.checkenv
import sisyphus.depsolve
import sisyphus.dlbinpkg
-import sisyphus.getclr
import sisyphus.getfs
import sisyphus.syncdb
import sisyphus.syncall
import sisyphus.watchdog
+from colorama import Fore, Back, Style
+
+colorama.init()
def set_nonblocking(fd):
@@ -53,7 +56,7 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
nogo_args = ['--quiet', '--pretend', '--getbinpkg',
'--rebuilt-binaries', '--misspell-suggestion=n', '--fuzzy-search=n']
if not sisyphus.checkenv.root():
- print(f"{sisyphus.getclr.bright_red}\nRoot permissions are required for this operation.\n{sisyphus.getclr.reset}")
+ print(f"{Fore.RED}{Style.BRIGHT}\nRoot permissions are required for this operation.\n{Style.RESET_ALL}")
sys.exit()
else:
if gfx_ui:
@@ -106,22 +109,22 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
os.kill(os.getpid(), signal.SIGTERM) # kill GUI window
else:
- print(f"{sisyphus.getclr.bright_red}\nCannot proceed!\n{sisyphus.getclr.reset}{sisyphus.getclr.bright_yellow}Please apply the above changes to your portage configuration files and try again!{sisyphus.getclr.reset}")
+ print(f"{Fore.RED}{Style.BRIGHT}\nCannot proceed!\n{Style.RESET_ALL}{Fore.WHITE}{Style.BRIGHT}Please apply the above changes to your portage configuration files and try again!{Style.RESET_ALL}")
sys.exit()
else:
if len(bin_list) == 0 and len(src_list) == 0:
- print(f"{sisyphus.getclr.bright_red}\nOne or more of the selected packages cannot be located for installation.\n{sisyphus.getclr.reset}")
+ print(f"{Fore.RED}{Style.BRIGHT}\nOne or more of the selected packages cannot be located for installation.\n{Style.RESET_ALL}")
if ebuild: # ebuild mode
if len(bin_list) == 0 and len(src_list) != 0: # source mode, ignore aliens
print(
- f"\n{sisyphus.getclr.green}These are the source packages that would be merged, in order:{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}These are the source packages that would be merged, in order:{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.green}{', '.join(src_list)}{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}{', '.join(src_list)}{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.bright_white}Total: {len(src_list)} source package(s){sisyphus.getclr.reset}\n")
+ f"\n{Fore.WHITE}{Style.BRIGHT}Total: {len(src_list)} source package(s){Style.RESET_ALL}\n")
while True:
user_input = input(
- f"{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}] ")
+ f"{Fore.WHITE}{Style.BRIGHT}Would you like to proceed?{Style.RESET_ALL} [{Fore.GREEN}{Style.BRIGHT}Yes{Style.RESET_ALL}/{Fore.RED}{Style.BRIGHT}No{Style.RESET_ALL}] ")
if user_input.lower() in ['yes', 'y', '']:
p_exe = subprocess.Popen(['emerge'] + go_args + (['--nodeps'] if nodeps else [
'--with-bdeps=y']) + (['--oneshot'] if oneshot else []) + list(pkgname))
@@ -160,21 +163,21 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
continue
elif len(bin_list) != 0 and len(src_list) != 0: # hybrid mode, ignore aliens
print(
- f"\n{sisyphus.getclr.green}These are the binary packages that would be merged, in order:{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}These are the binary packages that would be merged, in order:{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.magenta}{', '.join(bin_list)}{sisyphus.getclr.reset}\n")
+ f"\n{Fore.MAGENTA}{', '.join(bin_list)}{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.bright_white}Total: {len(bin_list)} binary package(s){sisyphus.getclr.reset}\n")
+ f"\n{Fore.WHITE}{Style.BRIGHT}Total: {len(bin_list)} binary package(s){Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.green}These are the source packages that would be merged, in order:{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}These are the source packages that would be merged, in order:{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.green}{', '.join(src_list)}{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}{', '.join(src_list)}{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.bright_white}Total: {len(src_list)} source package(s){sisyphus.getclr.reset}\n")
+ f"\n{Fore.WHITE}{Style.BRIGHT}Total: {len(src_list)} source package(s){Style.RESET_ALL}\n")
while True:
user_input = input(
- f"{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}] ")
+ f"{Fore.WHITE}{Style.BRIGHT}Would you like to proceed?{Style.RESET_ALL} [{Fore.GREEN}{Style.BRIGHT}Yes{Style.RESET_ALL}/{Fore.RED}{Style.BRIGHT}No{Style.RESET_ALL}] ")
if user_input.lower() in ['yes', 'y', '']:
sisyphus.dlbinpkg.start(dl_world=False, gfx_ui=False)
os.chdir(sisyphus.getfs.p_cch_dir)
@@ -215,14 +218,14 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
continue
elif len(bin_list) != 0 and len(src_list) == 0: # binary mode, fallback
print(
- f"\n{sisyphus.getclr.green}These are the binary packages that would be merged, in order:{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}These are the binary packages that would be merged, in order:{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.magenta}{', '.join(bin_list)}{sisyphus.getclr.reset}\n")
+ f"\n{Fore.MAGENTA}{', '.join(bin_list)}{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.bright_white}Total: {len(bin_list)} binary package(s){sisyphus.getclr.reset}\n")
+ f"\n{Fore.WHITE}{Style.BRIGHT}Total: {len(bin_list)} binary package(s){Style.RESET_ALL}\n")
while True:
user_input = input(
- f"{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}] ")
+ f"{Fore.WHITE}{Style.BRIGHT}Would you like to proceed?{Style.RESET_ALL} [{Fore.GREEN}{Style.BRIGHT}Yes{Style.RESET_ALL}/{Fore.RED}{Style.BRIGHT}No{Style.RESET_ALL}] ")
if user_input.lower() in ['yes', 'y', '']:
sisyphus.dlbinpkg.start(dl_world=False, gfx_ui=False)
os.chdir(sisyphus.getfs.p_cch_dir)
@@ -275,8 +278,9 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
os.kill(os.getpid(), signal.SIGTERM) # kill GUI window
else:
print(
- f"{sisyphus.getclr.bright_red}\nSource package(s) found in the mix!\n{sisyphus.getclr.reset}")
- print(f"{sisyphus.getclr.bright_yellow}Use{sisyphus.getclr.reset} 'sisyphus install {' '.join(pkgname)} --ebuild' to perform the install; Aborting.")
+ f"{Fore.RED}{Style.BRIGHT}\nSource package(s) found in the mix!\n{Style.RESET_ALL}")
+ print(
+ f"{Fore.WHITE}{Style.BRIGHT}Use 'sisyphus install {' '.join(pkgname)} --ebuild' to perform the install; Aborting.{Style.RESET_ALL}")
sys.exit()
elif len(bin_list) != 0 and len(src_list) != 0: # hybrid mode (noop), catch aliens
if gfx_ui:
@@ -291,8 +295,9 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
os.kill(os.getpid(), signal.SIGTERM) # kill GUI window
else:
print(
- f"{sisyphus.getclr.bright_red}\nSource package(s) found in the mix!\n{sisyphus.getclr.reset}")
- print(f"{sisyphus.getclr.bright_yellow}Use{sisyphus.getclr.reset} 'sisyphus install {' '.join(pkgname)} --ebuild' to perform the install; Aborting.")
+ f"{Fore.RED}{Style.BRIGHT}\nSource package(s) found in the mix!\n{Style.RESET_ALL}")
+ print(
+ f"{Fore.WHITE}{Style.BRIGHT}Use 'sisyphus install {' '.join(pkgname)} --ebuild' to perform the install; Aborting.{Style.RESET_ALL}")
sys.exit()
elif len(bin_list) != 0 and len(src_list) == 0: # binary mode
if gfx_ui:
@@ -303,7 +308,8 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
sisyphus.dlbinpkg.start(dl_world=False, gfx_ui=True)
os.chdir(sisyphus.getfs.p_cch_dir)
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
+ # --nodeps && --oneshot are set to False in the graphical client
+ ['--nodeps'] if nodeps else ['--with-bdeps=y']) + (['--oneshot'] if oneshot else []) + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# kill portage if the program dies or it's terminated by the user
atexit.register(sisyphus.watchdog.start, p_exe)
@@ -314,14 +320,14 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False, nodeps=False):
sisyphus.syncdb.lcl_tbl()
else:
print(
- f"\n{sisyphus.getclr.green}These are the binary packages that would be merged, in order:{sisyphus.getclr.reset}\n")
+ f"\n{Fore.GREEN}These are the binary packages that would be merged, in order:{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.magenta}{', '.join(bin_list)}{sisyphus.getclr.reset}\n")
+ f"\n{Fore.MAGENTA}{', '.join(bin_list)}{Style.RESET_ALL}\n")
print(
- f"\n{sisyphus.getclr.bright_white}Total: {len(bin_list)} binary package(s){sisyphus.getclr.reset}\n")
+ f"\n{Fore.WHITE}{Style.BRIGHT}Total: {len(bin_list)} binary package(s){Style.RESET_ALL}\n")
while True:
user_input = input(
- f"{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}] ")
+ f"{Fore.WHITE}{Style.BRIGHT}Would you like to proceed?{Style.RESET_ALL} [{Fore.GREEN}{Style.BRIGHT}Yes{Style.RESET_ALL}/{Fore.RED}{Style.BRIGHT}No{Style.RESET_ALL}] ")
if user_input.lower() in ['yes', 'y', '']:
sisyphus.dlbinpkg.start(
dl_world=False, gfx_ui=False)