summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2025-02-06 02:25:26 +0000
committerV3n3RiX <venerix@koprulu.sector>2025-02-06 02:25:26 +0000
commit75d9eb580b6bd2ec01abecc6c884ce0963dc539b (patch)
tree6c43692fc5d43ec243392994ec4d375ad2678d73
parent3a39631583e48b75ada47b44b0b2ae162ef72794 (diff)
backend : searchdb, port to colorama API
-rw-r--r--src/backend/searchdb.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/backend/searchdb.py b/src/backend/searchdb.py
index 36e3cb6..91d632f 100644
--- a/src/backend/searchdb.py
+++ b/src/backend/searchdb.py
@@ -1,13 +1,16 @@
#!/usr/bin/python3
+import colorama
import signal
import sqlite3
import subprocess
import sisyphus.checkenv
-import sisyphus.getclr
import sisyphus.getfs
import sisyphus.querydb
import sisyphus.syncall
+from colorama import Fore, Back, Style
+
+colorama.init()
def sigint_handler(signal, frame):
@@ -35,54 +38,54 @@ def tosql(string):
def srch_rslt(filter, cat, pn, desc, single):
print(
- f"\nSearching {sisyphus.getclr.bright_yellow}{filter}{sisyphus.getclr.reset} packages...\n")
+ f"\nSearching {Fore.WHITE}{Style.BRIGHT}{filter}{Style.RESET_ALL} packages...\n")
pkglist = srch_db(filter, tosql(cat), tosql(pn), tosql(desc))
if len(pkglist) == 0:
print(
- f"{sisyphus.getclr.bright_red}No matching packages have been identified!{sisyphus.getclr.reset}")
- print(f"{sisyphus.getclr.bright_yellow}Use the '{'--ebuild'}' option to search source packages{sisyphus.getclr.reset}")
- print(f"{sisyphus.getclr.bright_yellow}Use '{'sisyphus search --help'}' for assistance{sisyphus.getclr.reset}")
+ f"{Fore.RED}{Style.BRIGHT}No matching packages have been identified!{Style.RESET_ALL}")
+ print(f"{Fore.WHITE}{Style.BRIGHT}Use the '{'--ebuild'}' option to search source packages{Style.RESET_ALL}")
+ print(f"{Fore.WHITE}{Style.BRIGHT}Use '{'sisyphus search --help'}' for assistance{Style.RESET_ALL}")
else:
if single:
- print(f"{sisyphus.getclr.green}{'Package category/name':<45} {'Installed version':<20} {'Latest available version':<30} {'Description'}{sisyphus.getclr.reset}")
+ print(f"{Fore.GREEN}{'Package category/name':<45} {'Installed version':<20} {'Latest available version':<30} {'Description'}{Style.RESET_ALL}")
for pkg in pkglist:
if not single:
print(
- f"{sisyphus.getclr.bright_green}*{sisyphus.getclr.reset}{sisyphus.getclr.bright_white} {pkg['cat']}/{pkg['pn']}{sisyphus.getclr.reset}")
+ f"{Fore.GREEN}{Style.BRIGHT}*{Style.RESET_ALL}{Fore.WHITE}{Style.BRIGHT} {pkg['cat']}/{pkg['pn']}{Style.RESET_ALL}")
print(
- f"{sisyphus.getclr.green}\tInstalled version: {sisyphus.getclr.reset}{pkg['iv']}")
+ f"{Fore.GREEN}\tInstalled version: {Style.RESET_ALL}{pkg['iv']}")
if pkg['av'] != 'alien':
print(
- f"{sisyphus.getclr.green}\tLatest available version: {sisyphus.getclr.reset}{pkg['av']}")
+ f"{Fore.GREEN}\tLatest available version: {Style.RESET_ALL}{pkg['av']}")
else:
print(
- f"{sisyphus.getclr.green}\tAlien package: {sisyphus.getclr.reset}Use 'sisyphus search --ebuild {pkg['pn']}' for available version!")
+ f"{Fore.GREEN}\tAlien package: {Style.RESET_ALL}Use 'sisyphus search --ebuild {pkg['pn']}' for available version!")
print(
- f"{sisyphus.getclr.green}\tDescription: {sisyphus.getclr.reset}{pkg['desc']}\n")
+ f"{Fore.GREEN}\tDescription: {Style.RESET_ALL}{pkg['desc']}\n")
else:
cpn = f"{pkg['cat']}/{pkg['pn']}"
print(
- f"{sisyphus.getclr.bright_white}{cpn:45}{sisyphus.getclr.reset} {str(pkg['iv']):<20} {str(pkg['av']):<30} {str(pkg['desc'])}")
+ f"{Fore.WHITE}{Style.BRIGHT}{cpn:45}{Style.RESET_ALL} {str(pkg['iv']):<20} {str(pkg['av']):<30} {str(pkg['desc'])}")
print(f"\n{len(pkglist)} matching packages have been identified.")
def start(filter, cat, pn, desc, single):
if sisyphus.checkenv.root():
- print(f"{sisyphus.getclr.bright_red}Searching as root allows database updates. {sisyphus.getclr.reset}\n{sisyphus.getclr.bright_yellow}Search results will be accurate.{sisyphus.getclr.reset}")
+ print(f"{Fore.RED}{Style.BRIGHT}Searching as root allows database updates. {Style.RESET_ALL}\n{Fore.WHITE}{Style.BRIGHT}Search results would be accurate.{Style.RESET_ALL}")
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.syncall.start(gfx_ui=False)
break
elif user_input.lower() in ['no', 'n']:
- print(f"{sisyphus.getclr.bright_red}Skipping database update; displaying search results.{sisyphus.getclr.reset}\n{sisyphus.getclr.bright_yellow}Search results may be inaccurate.{sisyphus.getclr.reset}")
+ print(f"{Fore.RED}{Style.BRIGHT}Skipping database update; displaying search results.{Style.RESET_ALL}\n{Fore.WHITE}{Style.BRIGHT}Search results may not be accurate.{Style.RESET_ALL}")
break
else:
continue
else:
- print(f"{sisyphus.getclr.bright_red}Searching as a user does not allow database updates.{sisyphus.getclr.reset}\n{sisyphus.getclr.bright_yellow}Search results may be inaccurate.{sisyphus.getclr.reset}")
+ print(f"{Fore.RED}{Style.BRIGHT}Searching as user does not allow database updates.{Style.RESET_ALL}\n{Fore.WHITE}{Style.BRIGHT}Search results may not be accurate.{Style.RESET_ALL}")
srch_rslt(filter, cat, pn, desc, single)