File setup.py of Package waydroid-helper

import re
import sys
from pathlib import Path
import subprocess
import shutil

def read_version_from_pkgbuild():
    return subprocess.check_output(['bash', '-c', 'source PKGBUILD; echo $pkgver']).decode().strip()

def update_version_in_obsinfo(obsinfo_file, version, dest):
    """Update the version in uget.obsinfo file."""
    with open(obsinfo_file, 'r') as f:
        content = f.read()
    match = re.search(r'version: (.*)', content)
    if match:
        updated_content = content.replace(match.group(1), version)
    else:
        raise ValueError("Version tag not found in uget.obsinfo")
    with open(dest, 'w') as f:
        f.write(updated_content)

def main():
    name = sys.argv[1]
    outdir = sys.argv[2]
    spec_file = name + ".spec"
    obsinfo_file = name + ".obsinfo"
    pkg_file = "PKGBUILD"
    dest = outdir + '/' + obsinfo_file
    dest_spec = outdir + '/' + spec_file
    dest_pkg = outdir + "/" + pkg_file
    spec_path = Path(spec_file)
    text = spec_path.read_text()
    version = read_version_from_pkgbuild()
    update_version_in_obsinfo(obsinfo_file, version, dest)        

    text = text.replace("{{{ git_dir_pack }}}", "%{name}-%{version}.tar.gz")
    text = text.replace("%autosetup -n %{name}", "%autosetup -n %{name}-%{version}")
    
    spec_path = Path(dest_spec)
    spec_path.write_text(text)
    
    spec_path = Path(pkg_file)
    text = spec_path.read_text()
    text = text + f"\nsource=({name}-{version}.tar.gz)\n"
    text = text + f"\nsha256sums=(SKIP)\n"
    spec_path = Path(dest_pkg)
    spec_path.write_text(text)
    for i in ['control', 'rules', 'changelog']:
      shutil.copy(i, f'debian.{i}')

if __name__ == "__main__":
    main()
openSUSE Build Service is sponsored by