create_rpm_git_repo.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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='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', 'git@github.com:xcp-ng-rpms/%s.git' % args.name])
  36. os.chdir(args.name)
  37. open('.gitignore', 'w').write(gitignore)
  38. subprocess.check_call(['git', 'add', '.gitignore'])
  39. open('README.md', 'w').write(readme)
  40. subprocess.check_call(['git', 'add', 'README.md'])
  41. subprocess.check_call(['git', 'lfs', 'install'])
  42. subprocess.check_call(['git', 'lfs', 'track', '*.gz'])
  43. subprocess.check_call(['git', 'lfs', 'track', '*.bz2'])
  44. subprocess.check_call(['git', 'lfs', 'track', '*.xz'])
  45. subprocess.check_call(['git', 'lfs', 'track', '*.zip'])
  46. subprocess.check_call(['git', 'lfs', 'track', '*.tar'])
  47. subprocess.check_call(['git', 'lfs', 'track', '*.tgz'])
  48. subprocess.check_call(['git', 'lfs', 'track', '*.tbz'])
  49. subprocess.check_call(['git', 'add', '.gitattributes'])
  50. subprocess.check_call(['git', 'commit', '-m Initial commit'])
  51. subprocess.check_call(['git', 'push'])
  52. if __name__ == "__main__":
  53. main()