retire_rpm_git_repo.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/env python
  2. from __future__ import print_function
  3. import argparse
  4. import os
  5. import subprocess
  6. from github import Github
  7. def main():
  8. parser = argparse.ArgumentParser(description='Retires a RPM source git repository that is not needed anymore')
  9. parser.add_argument('name', help='name of repository')
  10. parser.add_argument('version', help='version of XCP-ng in which the package was retired, in form X.Y, e.g. 8.0')
  11. parser.add_argument('reason', help='reason for retirement. Start with lowercase letter, no ending dot.')
  12. parser.add_argument('token_file',
  13. help='file containing github authentication token',
  14. nargs='?',
  15. default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'github.txt'))
  16. args = parser.parse_args()
  17. name = args.name
  18. version = args.version
  19. reason = args.reason
  20. # authenticate to Github
  21. token = open(args.token_file).read().strip()
  22. g = Github(token)
  23. org = g.get_organization('xcp-ng-rpms')
  24. repo = org.get_repo(args.name)
  25. readme = """RPM sources for the %s package in XCP-ng (https://xcp-ng.org/).
  26. **This package has been retired in XCP-ng %s.**
  27. Reason: %s.
  28. """ % (name, version, reason)
  29. os.chdir(args.name)
  30. subprocess.check_call(['git', 'checkout', 'master'])
  31. subprocess.check_call(['git', 'pull'])
  32. subprocess.check_call(['git', 'rm', '*'])
  33. open('README.md', 'w').write(readme)
  34. subprocess.check_call(['git', 'add', 'README.md'])
  35. open('.retired', 'w').close()
  36. subprocess.check_call(['git', 'add', '.retired'])
  37. subprocess.check_call(['git', 'commit', '-m', 'This package has been retired in XCP-ng %s' % version])
  38. subprocess.check_call(['git', 'push'])
  39. # update repository description
  40. repo.edit(name, description="[retired in %s] %s" % (version, repo.description))
  41. if __name__ == "__main__":
  42. main()