retire_rpm_git_repo.py 1.8 KB

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