View previous topic :: View next topic |
Author |
Message |
Freed n00b
Joined: 19 Jan 2020 Posts: 39 Location: China
|
Posted: Wed Nov 27, 2024 3:49 pm Post subject: how to get ebuild package information from python? |
|
|
https://github.com/pkgcore/pkgcore/discussions/439
I am writing a language server for gentoo ebuild and hope to complete package name. For example, user input app-editors/n will complete app-editors/neovim and app-editors/nano . Is there a python API like get_ebuild_information('app-editors/n') and return a list like Code: | [{"name": "app-editors/neovim", "version": "0.10.0", "description": "XXX"}, ...] | ?
Not only pkgcore, portage or eix or gentoolkit or portageutils is OK if they provide enough API.
TIA! |
|
Back to top |
|
|
JimRockford74 n00b
Joined: 26 Nov 2024 Posts: 5
|
Posted: Wed Nov 27, 2024 4:45 pm Post subject: |
|
|
Here is a Portage implementation
Code: | import portage
def get_package_completions(partial_name):
db = portage.db[portage.root]["porttree"].dbapi
matches = db.cp_all()
# Filter matches based on partial name
filtered = [cp for cp in matches if cp.startswith(partial_name)]
results = []
for cp in filtered:
# Get the latest version
versions = db.cp_list(cp)
if versions:
latest = versions[-1]
metadata = db.aux_get(latest, ["DESCRIPTION"])
results.append({
"name": cp,
"version": portage.versions.cpv_getversion(latest),
"description": metadata[0]
})
return results
# Example usage:
completions = get_package_completions("app-editors/n") |
And here is a pkgcore[/i] implimentation
Code: | from pkgcore.config import load_config
from pkgcore.repository.util import get_virtual_repos
def get_package_completions_pkgcore(partial_name):
config = load_config()
repo = get_virtual_repos(config.objects["repo-stack"].repos)
results = []
for pkg in repo:
if pkg.key.startswith(partial_name):
results.append({
"name": pkg.key,
"version": str(pkg.version),
"description": pkg.description
})
return results
# Example usage:
completions = get_package_completions_pkgcore("app-editors/n") |
I would choose to use portage since 92% of it is in python and its always available on Gentoo systems, as for pkgcore, it tends to be faster but might need to be installed separately _________________ This is Jim Rockford. I'm either working a case or waiting for something to finish. If you're selling patience, I'm interested. $200 a day plus expenses. Leave your message at the tone. *beep* |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|