create_rpm_git_repo.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  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='Creates a git repository in current directory for RPM spec file and sources')
  9. parser.add_argument('name', help='name of repository')
  10. parser.add_argument('token_file',
  11. help='file containing github authentication token',
  12. nargs='?',
  13. default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'github.txt'))
  14. args = parser.parse_args()
  15. # authenticate to Github
  16. token = open(args.token_file).read().strip()
  17. g = Github(token)
  18. # create repository
  19. org = g.get_organization('xcp-ng-rpms')
  20. org.create_repo(args.name, "RPM sources for %s" % args.name)
  21. # initial commit to master
  22. gitignore = """BUILD
  23. BUILDROOT
  24. RPMS
  25. SRPMS
  26. """
  27. readme = """RPM sources for the %s package in XCP-ng (https://xcp-ng.org/).
  28. Make sure to have `git-lfs` installed before cloning. It is used for handling source archives separately.
  29. Branches:
  30. * `master` contains sources for the next `x.y` release of XCP-ng.
  31. * `x.y` (e.g. `7.5`) contains sources for the `x.y` release of XCP-ng, with their bugfix and/or security updates.
  32. * `XS-x.y` (e.g. `XS-7.5`), when they exist, contain sources from the `x.y` release of XenServer, with trademarked or copyrighted material stripped if needed.
  33. Built RPMs and source RPMs are available on https://updates.xcp-ng.org.
  34. """ % args.name
  35. subprocess.check_call(['git', 'clone', 'https://github.com/xcp-ng-rpms/%s.git' % args.name])
  36. os.chdir(args.name)
  37. subprocess.check_call(['git', 'config', '--local', 'remote.origin.pushurl',
  38. 'git@github.com:xcp-ng-rpms/%s.git' % args.name])
  39. open('.gitignore', 'w').write(gitignore)
  40. subprocess.check_call(['git', 'add', '.gitignore'])
  41. open('README.md', 'w').write(readme)
  42. subprocess.check_call(['git', 'add', 'README.md'])
  43. subprocess.check_call(['git', 'lfs', 'install'])
  44. subprocess.check_call(['git', 'lfs', 'track', '*.gz'])
  45. subprocess.check_call(['git', 'lfs', 'track', '*.bz2'])
  46. subprocess.check_call(['git', 'lfs', 'track', '*.xz'])
  47. subprocess.check_call(['git', 'lfs', 'track', '*.zip'])
  48. subprocess.check_call(['git', 'lfs', 'track', '*.tar'])
  49. subprocess.check_call(['git', 'lfs', 'track', '*.tgz'])
  50. subprocess.check_call(['git', 'lfs', 'track', '*.tbz'])
  51. subprocess.check_call(['git', 'add', '.gitattributes'])
  52. subprocess.check_call(['git', 'commit', '-s', '-m Initial commit'])
  53. subprocess.check_call(['git', 'push'])
  54. if __name__ == "__main__":
  55. main()