Commit 6505dcd1 authored by Jakub Ružička's avatar Jakub Ružička
Browse files

archive: drop atool requirement

Use standard shutil.unpack_archive which has a limited archive support
but can be extended to support arbitrary archive formats as needed.

Fixes: #42
parent dbddbcfb
Pipeline #80012 passed with stages
in 2 minutes and 28 seconds
......@@ -17,6 +17,7 @@ from apkg import ex
from apkg.log import getLogger
from apkg import parse
from import cd, run, sudo
from apkg.util.archive import unpack_archive
import apkg.util.shutil35 as shutil
......@@ -81,10 +82,8 @@ def build_srcpkg("building deb source package: %s", nv)"unpacking archive: %s", archive_path)
run('aunpack', '-X', build_path, archive_path)
if not source_path.exists():
# NOTE: if this happens oftern (it shouldn't), consider using
# atool's --save-outdir option above
unpack_path = unpack_archive(archive_path, build_path)
if unpack_path != source_path or not source_path.exists():
msg = "archive unpack didn't result in expected dir: %s" % source_path
raise ex.UnexpectedCommandOutput(msg=msg)
# render template
apkg archive (tarball) utils
from pathlib import Path
import apkg.util.shutil35 as shutil
from apkg import ex
from import run
def unpack_archive(archive_path, out_path):
......@@ -15,15 +14,12 @@ def unpack_archive(archive_path, out_path):
return path to extracted root dir
def root_dir(ps):
return Path(ps).parts[0]
out_path.mkdir(parents=True, exist_ok=True)
o = run('aunpack', '-X', out_path, archive_path)
shutil.unpack_archive(archive_path, out_path)
# parse output and make sure there's only a single root dir
root_dirs = set(map(root_dir, o.split("\n")))
n_root_files = len(root_dirs)
root_files = list(out_path.glob("*"))
n_root_files = len(root_files)
if n_root_files != 1:
fmt = "Expected a single root dir but insteat got %d files in root"
raise ex.InvalidArchiveFormat(fmt=fmt % n_root_files)
return out_path / root_dirs.pop()
return root_files[0]
......@@ -34,3 +34,10 @@ def rmtree(path, **kwargs):
def walk(top, **kwargs):
return os.walk(str(top), **kwargs)
def unpack_archive(filename, extract_dir=None, format=None):
# shutil supports pathlib starting with python 3.7
if extract_dir:
extract_dir = str(extract_dir)
return shutil.unpack_archive(str(filename), extract_dir, format)
......@@ -16,7 +16,7 @@ RUN apt-get install -y -qqq dpkg-dev debhelper dh-python python3-all python3-pip
# basic deps
RUN apt-get install -y -qqq python3-pbr python3-jinja2 python3-docopt python3-blessings python3-toml python3-packaging
# non-python deps
RUN apt-get install -y -qqq git atool
RUN apt-get install -y -qqq git
# deps not available in distro
RUN pip3 install distro htmllistparse
# testing deps
......@@ -16,7 +16,7 @@ RUN apt-get install -y -qqq dpkg-dev debhelper-compat dh-python python3-all pyth
# basic deps
RUN apt-get install -y -qqq python3-pbr python3-jinja2 python3-distro python3-docopt python3-blessings python3-requests python3-toml python3-cached-property
# non-python deps
RUN apt-get install -y -qqq git atool
RUN apt-get install -y -qqq git
# deps not available in distro
RUN pip3 install htmllistparse
# testing deps
......@@ -27,7 +27,6 @@ Summary: cross-distro packaging automation tool
BuildRequires: python3-devel
BuildRequires: python3-setuptools
Requires: atool
Requires: git-core
Requires: rpm-build
......@@ -16,7 +16,6 @@ Furthermore, `apkg` currently relies on following external tools available
from most distro repos:
* `git` to handle `git` repos
* `atool` to handle archives
Python modules needed to build `apkg` docs are listed in {{ 'doc-requirements.txt' | file_link }}:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment