From 44cef2dce90b96a0afdea8f1f9b3161e9766aae8 Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Sat, 1 Aug 2020 09:15:37 +0200 Subject: [PATCH] WIP: Use package-specific archive and subdir When a repo contains multiple released packages, each individual package can be downloaded as a standalone repo from the release repository. This commit prefers downloading from the release repository and downloads a package-only archive as source archive. This source archive contains (from my understanding) only one directory containing the corresponding package, so we can use this as the _dir directly. This is implemented quite hacky ATM and should serve as a PoC only. --- aurci/general.py | 18 ++++++++++++++---- aurci/update.py | 13 +++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/aurci/general.py b/aurci/general.py index cd5151f..9c79211 100644 --- a/aurci/general.py +++ b/aurci/general.py @@ -32,10 +32,10 @@ def build_metainfo_dict(): for repo in rosdistro: #Go through distro, and make entry for each package in a repository d = rosdistro[repo] - if 'source' in d: - src = d['source']['url'] - elif 'release' in d: + if 'release' in d: src = d['release']['url'] + elif 'source' in d: + src = d['source']['url'] target = re.sub(r'\.git', '', src.split('/')[3] + '/' + src.split('/')[4]) pkgver = d.get('release', {'version': None}).get('version', None) if pkgver: @@ -49,9 +49,19 @@ def build_metainfo_dict(): pkg_list = d.get('release', {'packages': [repo]}).get('packages', [repo]) for pkg in pkg_list: siblings = len(pkg_list)-1 + # TODO: Replace hard-coded melodic pkgname = 'ros-melodic-{}'.format(re.sub('_', '-', pkg)) + pkg_url = '/'.join([re.sub(r'\.git', '', src), + 'archive/release/melodic', + pkg, + '${pkgver}.tar.gz']) + pkg_dl = '/'.join([re.sub(r'\.git', '', src), + 'archive/release/melodic', + pkg, + str(pkgver)]) + '.tar.gz' ros_dict[pkgname] = {'repo': repo, 'siblings': siblings, 'orig_name': pkg, - 'pkgname': pkgname, 'src': src, 'pkgver': pkgver, 'dl': dl, 'url': url} + 'pkgname': pkgname, 'src': src, 'pkgver': pkgver, 'dl': pkg_dl, + 'url': pkg_url} return ros_dict @staticmethod diff --git a/aurci/update.py b/aurci/update.py index 2fb306f..c67c665 100644 --- a/aurci/update.py +++ b/aurci/update.py @@ -3,6 +3,7 @@ import sys import re import subprocess +import tarfile import urllib @@ -43,8 +44,6 @@ def update_pkgbuild(self): Maybe diffrent quotes than needed for regex?") new_pkgver = "pkgver='{}'".format(self.package_info['pkgver']) - new_dir = '_dir="{}-${{pkgver}}/{}"'.format(self.package_info['repo'], - '{}'.format(self.get_nested_package_path()) if self.package_info['siblings'] else '') new_src = 'source=("${{pkgname}}-${{pkgver}}.tar.gz"::"{}"'.format(self.package_info['url']) if old_pkgver == new_pkgver and old_dir == new_dir and old_src == new_src: @@ -61,6 +60,16 @@ def update_pkgbuild(self): sha256 = subprocess.run(['sha256sum', fname], check=True, capture_output=True) new_sha = "sha256sums=('{}'".format(sha256.stdout.decode('utf-8').split(' ')[0]) + + # TODO: + # - Error checking + # - Probably use with ...: notation + # - Check, whether main_dir is only one string (should be) + archive = tarfile.open(fname, "r:gz") + main_dir = os.path.commonprefix(archive.getnames()) + new_dir = '_dir="{}"'.format(main_dir) + archive.close() + os.remove(fname) with open('PKGBUILD', 'r') as f: