File setup.py of Package uget

import re
import sys

def read_version_from_spec(spec_file):
    """Read the version from the uget.spec file."""
    with open(spec_file, 'r') as f:
        content = f.read()    
    match = re.search(r'^Version:\s*(\S+)', content, re.MULTILINE)
    if match:
        return match.group(1)
    else:
        raise ValueError("Version not found in uget.spec")

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():
    spec_file = sys.argv[1]
    obsinfo_file = sys.argv[2]
    dest = sys.argv[3]
    try:
        # Step 1: Get version from uget.spec
        version = read_version_from_spec(spec_file)
        # Step 2: Update uget.obsinfo with the extracted version
        update_version_in_obsinfo(obsinfo_file, version, dest)
    except Exception as e:
        print(f"Error: {e}")

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