create_user_target.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. import argparse
  3. import subprocess
  4. import logging
  5. import sys
  6. def setup_logger():
  7. logging.basicConfig(
  8. format="%(asctime)s - %(levelname)s - %(message)s",
  9. datefmt="%Y-%m-%dT%H:%M:%S",
  10. level=logging.INFO
  11. )
  12. def run_command(command):
  13. logging.info(f"Executing: {' '.join(command)}")
  14. try:
  15. result = subprocess.run(command, check=True, text=True, capture_output=True)
  16. logging.info(result.stdout.strip())
  17. except subprocess.CalledProcessError as e:
  18. logging.error(f"Command failed: {' '.join(command)}", exc_info=True)
  19. logging.error(e.stderr.strip())
  20. sys.exit(1)
  21. def main():
  22. parser = argparse.ArgumentParser(description="Create a user tag and the corresponding target in Koji.")
  23. parser.add_argument("PARENT", help="Parent tag")
  24. parser.add_argument("TARGET", help="Tag and target name (the same name is used for the tag and the target)")
  25. args = parser.parse_args()
  26. setup_logger()
  27. run_command(["koji", "add-tag", args.TARGET, f"--parent={args.PARENT}", "--arches=x86_64"])
  28. run_command(["koji", "add-target", args.TARGET, args.TARGET, args.TARGET])
  29. if __name__ == "__main__":
  30. main()