#!/usr/bin/env python3
import subprocess
import argparse
import os
import os.path

from common import PROJECT


def delete_package_from_project(name: str):
    p = subprocess.run(["osc", "rdelete", PROJECT, name, "-m \"Deleted via delete_package.py\"" ], stdout=subprocess.PIPE)
    print(p.stdout)
    print(p.stderr)
    p.check_returncode()


def delete_package(package_name: str):
    if "/" in package_name:
        print("invalid package name")
        os.exit(1)

    delete_package_from_project(package_name)


def main():
    parser = argparse.ArgumentParser(prog="delete_package")
    parser.add_argument("package")

    args = parser.parse_args()

    delete_package(args.package)

    print("Package deleted in OBS, you can now push the modified workflow file")


if __name__ == '__main__':
    main()
