From f28b67f3d6910f71e20da86367205f3c3660ff72 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Tue, 18 Aug 2020 11:18:29 +0100 Subject: fix imports in dbsearch (no need to import the whole thing), rename it so we have something uniform --- src/backend/__init__.py | 4 +- src/backend/dbsearch.py | 130 -------------------------------------- src/backend/search.py | 6 -- src/backend/searchbinary.py | 131 +++++++++++++++++++++++++++++++++++++++ src/backend/searchebuild.py | 6 ++ src/frontend/cli/sisyphus-cli.py | 4 +- 6 files changed, 141 insertions(+), 140 deletions(-) delete mode 100644 src/backend/dbsearch.py delete mode 100644 src/backend/search.py create mode 100644 src/backend/searchbinary.py create mode 100644 src/backend/searchebuild.py diff --git a/src/backend/__init__.py b/src/backend/__init__.py index c13a513..59c927c 100644 --- a/src/backend/__init__.py +++ b/src/backend/__init__.py @@ -6,7 +6,6 @@ from .cache import * from .check import * from .csvfiles import * from .database import * -from .dbsearch import * from .filesystem import * from .installbinary import * from .installebuild import * @@ -14,7 +13,8 @@ from .killportage import * from .metadata import * from .mirror import * from .rescue import * -from .search import * +from .searchbinary import * +from .searchebuild import * from .setjobs import * from .setprofile import * from .solvedeps import * diff --git a/src/backend/dbsearch.py b/src/backend/dbsearch.py deleted file mode 100644 index 6e954b0..0000000 --- a/src/backend/dbsearch.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/python3 - -import sisyphus -import sqlite3 -import os - -def searchDB(filter, cat = '', pn = '', desc = ''): - NOVIRT = "AND cat NOT LIKE 'virtual'" - SELECTS = { - 'any': f'''SELECT - i.category AS cat, - i.name as pn, - i.version as iv, - IFNULL(a.version, 'alien') AS av, - d.description AS desc - FROM local_packages AS i LEFT OUTER JOIN remote_packages as a - ON i.category = a.category - AND i.name = a.name - AND i.slot = a.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - UNION - SELECT - a.category AS cat, - a.name as pn, - IFNULL(i.version, 'None') AS iv, - a.version as av, - d.description AS desc - FROM remote_packages AS a LEFT OUTER JOIN local_packages AS i - ON a.category = i.category - AND a.name = i.name - AND a.slot = i.slot - LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', - 'installed': f'''SELECT - i.category AS cat, - i.name AS pn, - i.version AS iv, - a.version as av, - d.description AS desc - FROM local_packages AS i - LEFT JOIN remote_packages AS a - ON i.category = a.category - AND i.name = a.name - AND i.slot = a.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', - 'alien': f'''SELECT - i.category AS cat, - i.name AS pn, - i.version as iv, - IFNULL(a.version, 'alien') AS av, - d.description AS desc - FROM local_packages AS i - LEFT JOIN remote_packages AS a - ON a.category = i.category - AND a.name = i.name - AND a.slot = i.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - AND av IS 'alien' ''', - 'remote': f'''SELECT - a.category AS cat, - a.name AS pn, - i.version as iv, - a.version AS av, - d.description AS desc - FROM remote_packages AS a - LEFT JOIN local_packages AS i - ON a.category = i.category - AND a.name = i.name - AND a.slot = i.slot - LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - AND iv IS NULL''', - 'upgrade': f'''SELECT - i.category AS cat, - i.name AS pn, - i.version as iv, - a.version AS av, - d.description AS desc - FROM local_packages AS i - INNER JOIN remote_packages AS a - ON i.category = a.category - AND i.name = a.name - AND i.slot = a.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - AND iv <> av''' - } - - with sqlite3.connect(sisyphus.filesystem.localDatabase) as db: - db.row_factory = sqlite3.Row - cursor = db.cursor() - cursor.execute(SELECTS[filter]) - rows = cursor.fetchall() - - return rows - -def tosql(string): - return '%%' if string == '' else string.replace('*', '%').replace('?', '_') - -def showSearch(filter, cat, pn, desc, single = False): - if os.getuid() == 0: - sisyphus.update.start() - else: - print('You are not root, cannot fetch updates.\nSearch result may be inaccurate!') - print(f"Looking for {filter} matching packages ...\n") - pkglist = searchDB(filter, tosql(cat), tosql(pn), tosql(desc)) - - if len(pkglist) == 0: - print("No binary package found!") - else: - if single: - print(f"{'Package':45} {'Installed':20} Available") - for pkg in pkglist: - if not single: - print(f"* {pkg['cat']}/{pkg['pn']}") - print(f"\tInstalled version: {pkg['iv']}") - if pkg['av'] != 'alien': - print(f"\tLatest available version: {pkg['av']}") - else: - print(f"\tAlien package, use `sisyphus search --ebuild {pkg['pn']}` for available version") - print(f"\tDescription: {pkg['desc']}\n") - else: - cpn = f"{pkg['cat']}/{pkg['pn']}" - print(f"{cpn:45} {str(pkg['iv']):20} {str(pkg['av'])}") - print(f"\nFound {len(pkglist)} binary package(s)") - - print("To search for source packages, use the '--ebuild' option.") diff --git a/src/backend/search.py b/src/backend/search.py deleted file mode 100644 index c9b5862..0000000 --- a/src/backend/search.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/python3 - -import subprocess - -def start(pkgname): - subprocess.call(['emerge', '--search', '--getbinpkg'] + list(pkgname)) diff --git a/src/backend/searchbinary.py b/src/backend/searchbinary.py new file mode 100644 index 0000000..0305a14 --- /dev/null +++ b/src/backend/searchbinary.py @@ -0,0 +1,131 @@ +#!/usr/bin/python3 + +import os +import sisyphus.filesystem +import sisyphus.update +import sqlite3 + +def searchDB(filter, cat = '', pn = '', desc = ''): + NOVIRT = "AND cat NOT LIKE 'virtual'" + SELECTS = { + 'any': f'''SELECT + i.category AS cat, + i.name as pn, + i.version as iv, + IFNULL(a.version, 'alien') AS av, + d.description AS desc + FROM local_packages AS i LEFT OUTER JOIN remote_packages as a + ON i.category = a.category + AND i.name = a.name + AND i.slot = a.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + UNION + SELECT + a.category AS cat, + a.name as pn, + IFNULL(i.version, 'None') AS iv, + a.version as av, + d.description AS desc + FROM remote_packages AS a LEFT OUTER JOIN local_packages AS i + ON a.category = i.category + AND a.name = i.name + AND a.slot = i.slot + LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', + 'installed': f'''SELECT + i.category AS cat, + i.name AS pn, + i.version AS iv, + a.version as av, + d.description AS desc + FROM local_packages AS i + LEFT JOIN remote_packages AS a + ON i.category = a.category + AND i.name = a.name + AND i.slot = a.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', + 'alien': f'''SELECT + i.category AS cat, + i.name AS pn, + i.version as iv, + IFNULL(a.version, 'alien') AS av, + d.description AS desc + FROM local_packages AS i + LEFT JOIN remote_packages AS a + ON a.category = i.category + AND a.name = i.name + AND a.slot = i.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + AND av IS 'alien' ''', + 'remote': f'''SELECT + a.category AS cat, + a.name AS pn, + i.version as iv, + a.version AS av, + d.description AS desc + FROM remote_packages AS a + LEFT JOIN local_packages AS i + ON a.category = i.category + AND a.name = i.name + AND a.slot = i.slot + LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + AND iv IS NULL''', + 'upgrade': f'''SELECT + i.category AS cat, + i.name AS pn, + i.version as iv, + a.version AS av, + d.description AS desc + FROM local_packages AS i + INNER JOIN remote_packages AS a + ON i.category = a.category + AND i.name = a.name + AND i.slot = a.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + AND iv <> av''' + } + + with sqlite3.connect(sisyphus.filesystem.localDatabase) as db: + db.row_factory = sqlite3.Row + cursor = db.cursor() + cursor.execute(SELECTS[filter]) + rows = cursor.fetchall() + + return rows + +def tosql(string): + return '%%' if string == '' else string.replace('*', '%').replace('?', '_') + +def start(filter, cat, pn, desc, single = False): + if os.getuid() == 0: + sisyphus.update.start() + else: + print('You are not root, cannot fetch updates.\nSearch result may be inaccurate!') + print(f"Looking for {filter} matching packages ...\n") + pkglist = searchDB(filter, tosql(cat), tosql(pn), tosql(desc)) + + if len(pkglist) == 0: + print("No binary package found!") + else: + if single: + print(f"{'Package':45} {'Installed':20} Available") + for pkg in pkglist: + if not single: + print(f"* {pkg['cat']}/{pkg['pn']}") + print(f"\tInstalled version: {pkg['iv']}") + if pkg['av'] != 'alien': + print(f"\tLatest available version: {pkg['av']}") + else: + print(f"\tAlien package, use `sisyphus search --ebuild {pkg['pn']}` for available version") + print(f"\tDescription: {pkg['desc']}\n") + else: + cpn = f"{pkg['cat']}/{pkg['pn']}" + print(f"{cpn:45} {str(pkg['iv']):20} {str(pkg['av'])}") + print(f"\nFound {len(pkglist)} binary package(s)") + + print("To search for source packages, use the '--ebuild' option.") diff --git a/src/backend/searchebuild.py b/src/backend/searchebuild.py new file mode 100644 index 0000000..c9b5862 --- /dev/null +++ b/src/backend/searchebuild.py @@ -0,0 +1,6 @@ +#!/usr/bin/python3 + +import subprocess + +def start(pkgname): + subprocess.call(['emerge', '--search', '--getbinpkg'] + list(pkgname)) diff --git a/src/frontend/cli/sisyphus-cli.py b/src/frontend/cli/sisyphus-cli.py index c5c6f25..33a2233 100755 --- a/src/frontend/cli/sisyphus-cli.py +++ b/src/frontend/cli/sisyphus-cli.py @@ -97,12 +97,12 @@ def search(package: List[str] = typer.Argument(...), cat, pn = package[0].split('/') else: cat, pn = '', package[0] - sisyphus.dbsearch.showSearch(filter.value, cat, pn, desc, quiet) + sisyphus.searchbinary.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.start(package) + sisyphus.searchebuild.start(package) @app.command("install") def install(pkgname: List[str], ebuild: bool = typer.Option(False, "--ebuild", "-e")): -- cgit v1.2.3