#!/usr/bin/python3 import os import sys import subprocess import hashlib def calculate_sha256(file_path): sha256_hash = hashlib.sha256() with open(file_path, "rb") as file: for byte_block in iter(lambda: file.read(4096), b""): sha256_hash.update(byte_block) return sha256_hash.hexdigest() def fetch_and_hash(url, output_dir): temp_file_path = "/tmp/temp" command = f"curl -o {temp_file_path} {url}" result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) if result.returncode == 0: sha256_hash = calculate_sha256(temp_file_path) os.remove(temp_file_path) return sha256_hash else: print(f"Error: Could not fetch URL. Please check if it's valid: {result.returncode}") sys.exit(1) def create_spm_file(package_name, package_info): template_lines = [ "[info]", f"name = {package_name}", "version = 0.0.1", "type = src", f"url = {package_info['url']}", f"sha256 = {package_info['sha256']}", "\n[description]", f"{package_info.get('description', '')}", "\n[makedeps]", *[f"{dep}" for dep in package_info.get('makedeps', [])], "\n[dependencies]", *[f"{dep}" for dep in package_info.get('dependencies', [])], "\n[download]", f"{package_info.get('download', '')}", "\n[install]", *[f"{step}" for step in package_info.get('install', [])] ] with open(f'{package_name}.ecmp', 'w') as file: file.write('\n'.join(template_lines)) if __name__ == "__main__": if len(sys.argv) < 3: print("Usage: mkspm ") sys.exit(1) package_name = sys.argv[1] package_url = sys.argv[2] package_info = { 'url': package_url, 'sha256': fetch_and_hash(package_url, "/tmp"), 'download': 'curl -L $URL | tar -xz', 'install': ['./configure', 'make', 'make DESTDIR=$BUILD_ROOT install'] } create_spm_file(package_name, package_info) print(f'Successfully created {package_name}.ecmp.')