Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions s5cmdUrls.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
# Checksum copied from "s5cmd_checksums.txt" associated with the s5cmd GitHub release

set(version "2.2.2")
# The section below is auto-generated by scripts/update_s5cmdUrls.cmake.py
# Do not edit this section directly.

set(linux32_filename "s5cmd_${version}_Linux-32bit.tar.gz")
set(linux32_sha256 "dc9ebe570fb5abcf5781511901d93425879022d56e73ab44dd32c45b2bfbc04b")
set(version "2.3.0")

set(linux64_filename "s5cmd_${version}_Linux-64bit.tar.gz")
set(linux64_sha256 "a15f83d2a6dc091e43b2a120f29f8f6c86d146c381766c0197ec75d7985af2b6")
set(linux32_filename "s5cmd_${version}_Linux-32bit.tar.gz")
set(linux32_sha256 "33e73005f183e5758161b32440ec65b15c934eb60c3b42795fb335418ca110ac")

set(linuxarm64_filename "s5cmd_${version}_Linux-arm64.tar.gz")
set(linuxarm64_sha256 "eabf18082398c332d33c692d383a889be204b1e7716f820e014bf11474ad345b")
set(linux64_filename "s5cmd_${version}_Linux-64bit.tar.gz")
set(linux64_sha256 "de0fdbfa3aceae55e069ba81a0fc17b2026567637603734a387b2fca06c299b4")

set(linuxarm64_filename "s5cmd_${version}_Linux-arm64.tar.gz")
set(linuxarm64_sha256 "1439f0d00ecedcd2a2f1f2c6749bbb0152b2257bf5086f29646ec8ae38798e24")

set(linuxppc64le_filename "s5cmd_${version}_Linux-ppc64le.tar.gz")
set(linuxppc64le_sha256 "90e5f0b774745a93795a04add18f63b5f96e61bcd5d36d7dc26cfec38412cd23")
set(linuxppc64le_sha256 "cb9f6926f94787f635f0a9de9242fca24b1461befd9a14b8a1084b04f76dbb45")

set(macos64_filename "s5cmd_${version}_macOS-64bit.tar.gz")
set(macos64_sha256 "df6f76f6d317c4d051ad083219ed36eb8d8e5ebc55ceeeb91f5e66cdc3ac71fb")

set(macos64_filename "s5cmd_${version}_macOS-64bit.tar.gz")
set(macos64_sha256 "5503a3308e239f081e5238e0af57958ae618e0de8b9c71142fe80f38be77e1c7")
set(macosarm64_filename "s5cmd_${version}_macOS-arm64.tar.gz")
set(macosarm64_sha256 "ae007bc96276f498ae3c1fb017e57630cf93ef260cfe7e97b365522e240c973f")

set(macosarm64_filename "s5cmd_${version}_macOS-arm64.tar.gz")
set(macosarm64_sha256 "fa3ae7e093fd6ac8a5236a000d5373779eb403c57ee955fc7da9549668644e38")
set(win32_filename "s5cmd_${version}_Windows-32bit.zip")
set(win32_sha256 "a5ff4e82f679dbd45310a0d57519fcfe66c1df2703d883ff9f40a20db7e65fe8")

set(win32_filename "s5cmd_${version}_Windows-32bit.zip")
set(win32_sha256 "ee667eb01b955a7dda588456bd102982f8344bed393a8b63b5d4c9c325e01349")
set(win64_filename "s5cmd_${version}_Windows-64bit.zip")
set(win64_sha256 "9d8a98c1d9f6284c6d54aeec3daeb5f1412fd101850ae756c1e70dd8ffe52166")

set(win64_filename "s5cmd_${version}_Windows-64bit.zip")
set(win64_sha256 "f7c311907c78efa56e27a25fba1f87520754c402bbe1cb4901d3522f12a75497")
set(winarm64_filename "s5cmd_${version}_Windows-arm64.zip")
set(winarm64_sha256 "0d99ce0cbf4a266e7fd9b3cd2682384fb7b432754eb52f17f9a9f7cbe6bcca55")

set(winarm64_filename "s5cmd_${version}_Windows-arm64.zip")
set(winarm64_sha256 "61e0adf3635334fa62714a5cf221e03f3549392e9613f9a7591a03d8e6fe0d64")
# The section above is auto-generated by scripts/update_s5cmdUrls.cmake.py
# Do not edit this section directly.

cmake_host_system_information(RESULT is_64bit QUERY IS_64BIT)

Expand Down
126 changes: 126 additions & 0 deletions scripts/update_s5cmdUrls.cmake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!usr/bin/env python3
from __future__ import annotations

import argparse
import re
from pathlib import Path
from urllib.request import urlopen

FILENAME_LOOKUP = {
"linux32": "Linux-32bit.tar.gz",
"linux64": "Linux-64bit.tar.gz",
"linuxarm64": "Linux-arm64.tar.gz",
"linuxppc64le": "Linux-ppc64le.tar.gz",
"macos64": "macOS-64bit.tar.gz",
"macosarm64": "macOS-arm64.tar.gz",
"win32": "Windows-32bit.zip",
"win64": "Windows-64bit.zip",
"winarm64": "Windows-arm64.zip",
}
VERSION_RE = r"^s5cmd_([\d\.]+)_"
TEXT_RE = r"\# The section.+\n\# Do not edit this[\S\s]+\# The section.+\n\# Do not edit this.+\n"


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Update s5cmd files and hashes in `s5cmdUrls.cmake`.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

parser.add_argument(
"-c",
"--checksum-file",
type=str,
help="Path or URL to the checksum file",
required=True,
)
parser.add_argument(
"-s",
"--s5cmd-file",
type=str,
help="Path to the s5cmd file",
default=Path(__file__).parents[1].joinpath("s5cmdUrls.cmake").as_posix(),
)
return parser.parse_args()


def read_checksum_text(path: str) -> str:
if path.startswith("http"):
response = urlopen(path)
return response.read().decode("utf-8")

_path = Path(path)
if not _path.exists() or not _path.is_file():
msg = f"Checksum file `{_path}` does not exist."
raise FileNotFoundError(msg)
return _path.read_text(encoding="utf-8")


def generate_cmake_text(text: str) -> str:
checksums = [line.split() for line in text.rstrip("\n").split("\n")]

version = re.search(VERSION_RE, checksums[0][1]).group(1)
if version is None:
msg = f"Cannot find version in {checksums[0][1]}"
raise ValueError(msg)

output_lines = [
"# The section below is auto-generated by scripts/update_s5cmdUrls.cmake.py",
"# Do not edit this section directly.",
"",
f'set(version "{version}")',
"",
]

for shortname, postfix in FILENAME_LOOKUP.items():
hash_ = None
for c in checksums:
_filename = f"s5cmd_{version}_{postfix}"
if _filename == c[1]:
hash_ = c[0]
break
if hash_ is None:
msg = f"Cannot find hash for `{_filename}` in {checksums}"
raise ValueError(msg)

output_lines.append(
f"set({shortname}_filename".ljust(26) + f'"s5cmd_${{version}}_{postfix}")'
)
output_lines.append(f"set({shortname}_sha256".ljust(26) + f'"{hash_}")')
output_lines.append("")

output_lines.append(
"# The section above is auto-generated by scripts/update_s5cmdUrls.cmake.py"
)
output_lines.append("# Do not edit this section directly.")
output_lines.append("")

return "\n".join(output_lines)


def overwrite_cmake_file(text: str, path: str) -> None:
_path = Path(path)
if not _path.exists() or not _path.is_file():
msg = f"File `{_path}` does not exist."
raise FileNotFoundError(msg)

cmake_text = _path.read_text(encoding="utf-8")
if not re.search(TEXT_RE, cmake_text):
msg = f"Unable to find text in `{_path}`. Please check the regex."
raise ValueError(msg)

replaced_text = re.sub(TEXT_RE, text, cmake_text)
_path.write_text(replaced_text, encoding="utf-8")

print(f"Checksum file `{_path}` updated.") # noqa: T201


def main():
args = parse_args()
text = read_checksum_text(args.checksum_file)
cmake_text = generate_cmake_text(text)
overwrite_cmake_file(cmake_text, args.s5cmd_file)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion tests/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_scripts():

@all_tools
def test_package_script(tool):
expected_version = "2.2.2"
expected_version = "2.3.0"
scripts = [script for script in _get_scripts() if script.stem == tool]
assert len(scripts) == 1
output = subprocess.check_output([str(scripts[0]), "version"]).decode("ascii")
Expand Down
Loading