From 8a5836b2f7874efd0f5b6111c236ba12fa249fac Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Tue, 23 Nov 2021 21:17:14 +0800 Subject: fix(script): Fix parameter check error Signed-off-by: KunoiSayami --- utils/aur/aur-check-update.py | 2 +- utils/aur/check-aur-dependencies.py | 78 +++++++++++++++++++++++++++++++++++++ utils/aur/check-aur.py | 78 ------------------------------------- utils/pkgbuild.sh | 2 +- 4 files changed, 80 insertions(+), 80 deletions(-) create mode 100755 utils/aur/check-aur-dependencies.py delete mode 100755 utils/aur/check-aur.py (limited to 'utils') diff --git a/utils/aur/aur-check-update.py b/utils/aur/aur-check-update.py index 3188aea..bc79cdc 100755 --- a/utils/aur/aur-check-update.py +++ b/utils/aur/aur-check-update.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (C) 2021 KunoiSayami +# Copyright (C) 2021 KunoiSayami and contributors # # This module is part of KunoiSayami/repos and is released under # the AGPL v3 License: https://www.gnu.org/licenses/agpl-3.0.txt diff --git a/utils/aur/check-aur-dependencies.py b/utils/aur/check-aur-dependencies.py new file mode 100755 index 0000000..6749f69 --- /dev/null +++ b/utils/aur/check-aur-dependencies.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# Copyright (C) 2021 KunoiSayami and contributors +# +# This module is part of KunoiSayami/repos and is released under +# the AGPL v3 License: https://www.gnu.org/licenses/agpl-3.0.txt +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +import argparse +import asyncio +import logging +import re +from pathlib import Path +from typing import Tuple + +import aiofiles +import aiohttp + + +async def check_pkg(session: aiohttp.ClientSession, num: int, pkg: str) -> Tuple[int, bool]: + logging.info(f'Checking {pkg}') + ret = await session.head(f'https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h={pkg}') + return num, ret.status == 200 + + +async def main() -> int: + parser = argparse.ArgumentParser(description='check-aur.py') + parser.add_argument('paths', metavar='sub_path', type=str, nargs='*', help='sub-path for repo root') + + args = parser.parse_args() + repo_dir = Path(*args.paths) + pkgbuild_file = repo_dir.joinpath('PKGBUILD') + if not pkgbuild_file.exists(): + logging.error("Can't locate PKGBUILD file, please specify directory in arguments or chdir to folder") + return 1 + + async with aiofiles.open(pkgbuild_file, 'r', encoding='utf-8') as f: + pkgbuild_text = await f.read() + + deps_match = re.search(r"makedepends=\((?P([^)]|\n)+)\)", pkgbuild_text, re.M) + if not deps_match: + logging.error("Can't found `makedepends' keyword, if you think this is mistake, please report issue") + return 2 + + deps = deps_match.group('DEPS').split() + + async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(10)) as session: + tasks = [asyncio.create_task(check_pkg(session, n, pkg)) for n, pkg in enumerate(deps)] + yay_dep_nums = [] + for task in asyncio.as_completed(tasks): + n, r = await task + if r: + yay_dep_nums.append(n) + + yaydeps_dir = repo_dir.parent.joinpath('.yaydeps') + + if len(yay_dep_nums) > 0: + async with aiofiles.open(yaydeps_dir.joinpath(repo_dir.stem), 'w', encoding='utf-8') as f: + await f.write('\n'.join([*(deps[n] for n in sorted(yay_dep_nums)), ''])) + + return 0 + + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s - %(levelname)s - %(funcName)s - %(lineno)d - %(message)s') + loop = asyncio.get_event_loop() + exit(loop.run_until_complete(main())) diff --git a/utils/aur/check-aur.py b/utils/aur/check-aur.py deleted file mode 100755 index 6749f69..0000000 --- a/utils/aur/check-aur.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (C) 2021 KunoiSayami and contributors -# -# This module is part of KunoiSayami/repos and is released under -# the AGPL v3 License: https://www.gnu.org/licenses/agpl-3.0.txt -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -import argparse -import asyncio -import logging -import re -from pathlib import Path -from typing import Tuple - -import aiofiles -import aiohttp - - -async def check_pkg(session: aiohttp.ClientSession, num: int, pkg: str) -> Tuple[int, bool]: - logging.info(f'Checking {pkg}') - ret = await session.head(f'https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h={pkg}') - return num, ret.status == 200 - - -async def main() -> int: - parser = argparse.ArgumentParser(description='check-aur.py') - parser.add_argument('paths', metavar='sub_path', type=str, nargs='*', help='sub-path for repo root') - - args = parser.parse_args() - repo_dir = Path(*args.paths) - pkgbuild_file = repo_dir.joinpath('PKGBUILD') - if not pkgbuild_file.exists(): - logging.error("Can't locate PKGBUILD file, please specify directory in arguments or chdir to folder") - return 1 - - async with aiofiles.open(pkgbuild_file, 'r', encoding='utf-8') as f: - pkgbuild_text = await f.read() - - deps_match = re.search(r"makedepends=\((?P([^)]|\n)+)\)", pkgbuild_text, re.M) - if not deps_match: - logging.error("Can't found `makedepends' keyword, if you think this is mistake, please report issue") - return 2 - - deps = deps_match.group('DEPS').split() - - async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(10)) as session: - tasks = [asyncio.create_task(check_pkg(session, n, pkg)) for n, pkg in enumerate(deps)] - yay_dep_nums = [] - for task in asyncio.as_completed(tasks): - n, r = await task - if r: - yay_dep_nums.append(n) - - yaydeps_dir = repo_dir.parent.joinpath('.yaydeps') - - if len(yay_dep_nums) > 0: - async with aiofiles.open(yaydeps_dir.joinpath(repo_dir.stem), 'w', encoding='utf-8') as f: - await f.write('\n'.join([*(deps[n] for n in sorted(yay_dep_nums)), ''])) - - return 0 - - -if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG, - format='%(asctime)s - %(levelname)s - %(funcName)s - %(lineno)d - %(message)s') - loop = asyncio.get_event_loop() - exit(loop.run_until_complete(main())) diff --git a/utils/pkgbuild.sh b/utils/pkgbuild.sh index 46d0285..16b13bd 100755 --- a/utils/pkgbuild.sh +++ b/utils/pkgbuild.sh @@ -152,7 +152,7 @@ popd date +%s > "$PKGDEST/LASTBUILD" if [ $UNSUCCESSFUL -eq 1 ]; then - if [ -n "$CI_DEFAULT_BRANCH" ] && [ -n "$CI_DEFAULT_BRANCH" ] && [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then + if [ -n "$CI_DEFAULT_BRANCH" ] && [ -n "$CI_COMMIT_BRANCH" ] && [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then touch .fail else echo -e "\033[0;31mExit due makepkg failed\033[0m" -- cgit v1.3.1