mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
cmds.posix.Tar: Add command
Add a "jw-pkg posix tar" command. Currently the only thing that can be done with it is extracting. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
a5e7647026
commit
7357092576
4 changed files with 77 additions and 0 deletions
18
src/python/jw/pkg/cmds/posix/CmdTar.py
Normal file
18
src/python/jw/pkg/cmds/posix/CmdTar.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from .Cmd import Cmd
|
||||||
|
from ..CmdPosix import CmdPosix
|
||||||
|
|
||||||
|
class CmdTar(Cmd): # export
|
||||||
|
|
||||||
|
def __init__(self, parent: CmdPosix) -> None:
|
||||||
|
super().__init__(parent, 'tar', help='Handle tar archives')
|
||||||
|
self._add_subcommands()
|
||||||
|
|
||||||
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
super().add_arguments(parser)
|
||||||
|
|
||||||
|
async def _run(self, args: Namespace) -> None:
|
||||||
|
return await super()._run(args)
|
||||||
27
src/python/jw/pkg/cmds/posix/tar/Cmd.py
Normal file
27
src/python/jw/pkg/cmds/posix/tar/Cmd.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from argparse import Namespace, ArgumentParser
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
|
from ..Cmd import Cmd as Base
|
||||||
|
from ..CmdTar import CmdTar as Parent
|
||||||
|
|
||||||
|
from ....lib.TarIo import TarIo
|
||||||
|
from ....lib.ProcFilterGpg import ProcFilterGpg
|
||||||
|
from ....lib.FileContext import FileContext
|
||||||
|
|
||||||
|
class Cmd(Base): # export
|
||||||
|
|
||||||
|
def __init__(self, parent: Parent, name: str, help: str) -> None:
|
||||||
|
super().__init__(parent, name, help)
|
||||||
|
self.__tar_io: None = None
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def ctx(self, **kwargs) -> TarIo:
|
||||||
|
async with TarIo.create(src_uri=self.app.args.archive_path, **kwargs) as ret:
|
||||||
|
ret.src.add_proc_filter(FileContext.Direction.In, ProcFilterGpg(ec=self.app.exec_context))
|
||||||
|
yield ret
|
||||||
|
|
||||||
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
super().add_arguments(parser)
|
||||||
|
parser.add_argument('-f', '--archive-path', required=True, help='Archive path')
|
||||||
27
src/python/jw/pkg/cmds/posix/tar/CmdExtract.py
Normal file
27
src/python/jw/pkg/cmds/posix/tar/CmdExtract.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from .Cmd import Cmd
|
||||||
|
from ..CmdTar import CmdTar
|
||||||
|
|
||||||
|
from ....lib.FileContext import FileContext
|
||||||
|
|
||||||
|
class CmdExtract(Cmd): # export
|
||||||
|
|
||||||
|
def __init__(self, parent: CmdTar) -> None:
|
||||||
|
super().__init__(parent, 'x', help="Extract a tar archive")
|
||||||
|
|
||||||
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
super().add_arguments(parser)
|
||||||
|
parser.add_argument('dst', help='Destination root URI')
|
||||||
|
|
||||||
|
async def _run(self, args: Namespace) -> None:
|
||||||
|
async with self.ctx(
|
||||||
|
dst_uri = args.dst,
|
||||||
|
) as ctx:
|
||||||
|
await ctx.extract(ctx.dst.root)
|
||||||
5
src/python/jw/pkg/cmds/posix/tar/Makefile
Normal file
5
src/python/jw/pkg/cmds/posix/tar/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
TOPDIR = ../../../../../../..
|
||||||
|
#PY_UPDATE_INIT_PY = false
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/py-mod.mk
|
||||||
Loading…
Add table
Add a link
Reference in a new issue