mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
cmds.distro.lib.dpkg: Add module
As with cmds.distro.lib.rpm, the dpkg module is a place for Python abstractions of the Debian package manager tools dpkg and friends. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
1bb3c166d6
commit
7f72d17f7a
1 changed files with 45 additions and 0 deletions
45
src/python/jw/pkg/cmds/distro/lib/dpkg.py
Normal file
45
src/python/jw/pkg/cmds/distro/lib/dpkg.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
|
from ....lib.util import run_cmd, run_sudo
|
||||||
|
|
||||||
|
from .Package import Package, meta_tags
|
||||||
|
|
||||||
|
_meta_map: dict[str, str]|None = None
|
||||||
|
|
||||||
|
def meta_map():
|
||||||
|
global _meta_map
|
||||||
|
if _meta_map is None:
|
||||||
|
_meta_map = Package.order_tags({
|
||||||
|
'name': 'binary:Package',
|
||||||
|
'vendor': None, # deb doesn't have vendor field
|
||||||
|
'packager': None, # -- packager --
|
||||||
|
'url': 'Homepage',
|
||||||
|
'maintainer': 'Maintainer',
|
||||||
|
})
|
||||||
|
return _meta_map
|
||||||
|
|
||||||
|
async def run_dpkg(args: list[str], sudo: bool=False): # export
|
||||||
|
cmd = ['/usr/bin/dpkg']
|
||||||
|
cmd.extend(args)
|
||||||
|
if sudo:
|
||||||
|
return await run_sudo(cmd)
|
||||||
|
return await run_cmd(cmd)
|
||||||
|
|
||||||
|
async def run_dpkg_query(args: list[str], sudo: bool=False): # export
|
||||||
|
cmd = ['/usr/bin/dpkg-query']
|
||||||
|
cmd.extend(args)
|
||||||
|
if sudo:
|
||||||
|
return await run_sudo(cmd)
|
||||||
|
return await run_cmd(cmd)
|
||||||
|
|
||||||
|
async def query_packages(names: Iterable[str] = []) -> Iterable[Package]: # export
|
||||||
|
fmt_str = '|'.join([(f'${{{tag}}}' if tag else '') for tag in meta_map().values()]) + r'\n'
|
||||||
|
# dpkg-query -W -f='${binary:Package}|${Maintainer}| ... \n'
|
||||||
|
specs, stderr, status = await run_dpkg_query(['-W', '-f=' + fmt_str, *names], sudo=False)
|
||||||
|
return Package.parse_specs_str(specs)
|
||||||
|
|
||||||
|
async def list_files(pkg: str) -> list[str]: # export
|
||||||
|
file_list_str, stderr, status = await run_dpkg(['-L', pkg], sudo=False)
|
||||||
|
return file_list_str.splitlines()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue