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

Merge branch 'content-disp' into 'master'

get-archive: respect HTTP Content-Disposition

See merge request !51
parents d3ee3c58 3663fa82
Pipeline #81636 passed with stage
in 5 minutes and 36 seconds
......@@ -2,6 +2,7 @@
apkg lib for handling source archives
"""
from pathlib import Path
import re
import requests
from apkg import ex
......@@ -108,20 +109,30 @@ def get_archive(
return cached
log.info('downloading archive: %s', archive_url)
_, _, archive_fn = archive_url.rpartition('/')
if result_dir:
ar_base_path = Path(result_dir)
else:
ar_base_path = proj.upstream_archive_path
r = requests.get(archive_url, allow_redirects=True)
if r.status_code != 200:
raise ex.FileDownloadFailed(code=r.status_code, url=archive_url)
content_type = r.headers['content-type']
content_type = r.headers.get('content-type', '')
if not content_type.startswith('application/'):
msg = 'Failed to download archive - invalid content-type "%s":\n\n%s'
raise ex.FileDownloadFailed(
msg=msg % (content_type, archive_url))
if result_dir:
ar_base_path = Path(result_dir)
else:
ar_base_path = proj.upstream_archive_path
_, _, archive_fn = archive_url.rpartition('/')
content_disp = r.headers.get('content-disposition')
if content_disp:
m = re.search(r'filename=(.+)', content_disp)
if m:
archive_fn = m.group(1).strip(' "')
log.verbose("archive file name from HTTP Content-Disposition: %s",
archive_fn)
archive_path = ar_base_path / archive_fn
log.info('saving archive to: %s', archive_path)
ar_base_path.mkdir(parents=True, exist_ok=True)
......
......@@ -6,6 +6,6 @@ make_archive_script = "scripts/make-dev-archive.sh"
[upstream]
# needed for get-archive
archive_url = "https://gitlab.nic.cz/packaging/{{ project.name }}/-/archive/v{{ version }}/{{ project.name }}-{{ version }}.tar.gz"
archive_url = "https://gitlab.nic.cz/packaging/apkg/-/archive/v{{ version }}/apkg-v{{ version }}.tar.gz"
# script to check latest upstream version
version_script = "scripts/upstream-version.py"
......@@ -12,13 +12,11 @@ depends=('python-docopt'
'python-toml'
'python-blessings')
#checkdepends=('python-pytest')
source=("${pkgname}-${pkgver}.tar.gz")
source=("${pkgname}-v${pkgver}.tar.gz")
sha256sums=('SKIP')
export PBR_VERSION=$pkgver
build() {
cd apkg-$pkgver
cd apkg-v$pkgver
python setup.py build
}
......@@ -28,6 +26,6 @@ build() {
#}
package() {
cd apkg-$pkgver
cd apkg-v$pkgver
python setup.py install --root="$pkgdir" --optimize=1
}
......@@ -5,7 +5,7 @@ Summary: cross-distro packaging automation tool
License: GPL 3.0
URL: https://gitlab.nic.cz/packaging/apkg
Source0: %{name}-%{version}.tar.gz
Source0: %{name}-v%{version}.tar.gz
BuildArch: noarch
......@@ -45,10 +45,7 @@ This package contains apkg module for Python 3.
%prep
%autosetup -n %{name}-%{version} -S git
# We handle requirements ourselves, pkg_resources only bring pain
rm -rf requirements.txt test-requirements.txt
%autosetup -n %{name}-v%{version} -S git
%build
%py3_build
......
#!/bin/bash
#
# Create apkg archive and print path to it.
# create archive from current source using git
set -e
DISTDIR=dist
VERSION=$(python3 -m apkg --version)
if [ -z "$VERSION" ]; then
echo "failed to retrieve current apkg version :("
exit 1
fi
NAMEVER=apkg-v$VERSION
ARCHIVE=$NAMEVER.tar.gz
rm -rf "$DISTDIR"
python3 -m build --sdist
ls dist/apkg-*.tar.gz
git archive --format tgz --output $ARCHIVE --prefix $NAMEVER/ HEAD
# apkg expects stdout to list archive files
echo $ARCHIVE
......@@ -76,12 +76,12 @@ def test_apkg_make_archive_cache(repo_path, caplog):
def test_apkg_get_archive_manual(repo_path, capsys):
VERSION = '0.0.2'
VERSION = '0.0.4'
with cd(repo_path):
assert apkg('get-archive', '--version', VERSION) == 0
out, _ = capsys.readouterr()
# first stdout line should be downloaded archive
assert out.startswith("pkg/archives/upstream/apkg-%s.tar.gz" % VERSION)
assert out.startswith("pkg/archives/upstream/apkg-v%s.tar.gz" % VERSION)
def test_apkg_get_archive_auto(repo_path, capsys):
......
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