/fedora_epel_push.py

https://github.com/GunioRobot/cobbler
Python | 147 lines | 84 code | 21 blank | 42 comment | 12 complexity | badca89cb1fab3585462386c15dc388f MD5 | raw file
  1. #!/usr/bin/python
  2. """
  3. Michael DeHaan <mdehaan@fedoraproject.org>, 2008
  4. This software may be freely redistributed under the terms of the GNU
  5. general public license.
  6. You should have received a copy of the GNU General Public License
  7. along with this program; if not, write to the Free Software
  8. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  9. ---
  10. This script automates pushes from git checkouts
  11. into Fedora CVS. It is expected you already have
  12. Fedora CVS set up for a project and have the build
  13. system tools installed.
  14. After that, usage looks like:
  15. python pusher.py --proj=/cg/func --cvs=~/func
  16. Work in progress
  17. """
  18. # if new releases come out or old ones go away, edit here
  19. PROCESS_RELEASES = [ "devel", "F-11", "F-10", "F-8", "EL-5", "EL-4" ]
  20. import optparse
  21. import os
  22. import sys
  23. import glob
  24. import subprocess
  25. def run(cmd,failok=False):
  26. """
  27. Wrapper around subprocess
  28. """
  29. print "running: %s" % cmd
  30. rc = subprocess.call(cmd, shell=True)
  31. print "rc: %s" % rc
  32. if not failok and not rc == 0:
  33. croak("aborting")
  34. def croak(msg):
  35. """
  36. Print something and die.
  37. """
  38. print msg
  39. sys.exit(1)
  40. # process options, as described at the top of this file
  41. p = optparse.OptionParser(usage="pusher [ARGS]")
  42. p.add_option("--cvs", dest="cvs", help="EX: ~/cvs/func")
  43. p.add_option("--proj", dest="proj", help="EX: /cg/func")
  44. (options,args) = p.parse_args()
  45. if options.cvs is None:
  46. croak("--cvs is required, PEBKAC")
  47. if options.proj is None:
  48. croak("--proj is required, PEBKAC")
  49. cvsdir = os.path.expanduser(options.cvs)
  50. projdir = os.path.expanduser(options.proj)
  51. print "----------------------------------------------"
  52. print "Running Michael's totally awesome code pusher script"
  53. print "----------------------------------------------"
  54. print "assuming you first ran something like..."
  55. print " ssh-agent bash"
  56. print " ssh-agent ~/.ssh/id_dsa"
  57. print "if not, expect pain and it's not my fault"
  58. print "----------------------------------------------"
  59. print " "
  60. print "ok, here we go..."
  61. print " "
  62. # find the RPM build directory
  63. rpmbuild = os.path.join(projdir, "rpm-build")
  64. if not os.path.exists(rpmbuild):
  65. croak("no directory: %s" % rpmbuild)
  66. print "found rpm-build directory"
  67. # find the tarballs
  68. tarsearch = "%s/*.tar.gz" % rpmbuild
  69. tars = glob.glob(tarsearch)
  70. if len(tars) != 1:
  71. croak("expected to find just one tar.gz in %s, no luck") % rpmbuild
  72. tarfile = tars[0]
  73. print "found tarball: %s" % tarfile
  74. # find a version file, if any
  75. versionfile = None
  76. versearch = os.path.join(projdir,"version")
  77. if os.path.exists(versearch):
  78. print "found a version file: %s" % versearch
  79. versionfile = versearch
  80. print "found version file: %s" % versionfile
  81. # find a specfile
  82. specsearch = "%s/*.spec" % projdir
  83. specs = glob.glob(specsearch)
  84. if len(specs) != 1:
  85. croak("need one and only one specfile in %s" % projdir)
  86. specfile = specs[0]
  87. print "found specfile: %s" % specfile
  88. # verify cvsdir exists
  89. if not os.path.exists(cvsdir):
  90. croak("can't find cvs directory: %s" % cvsdir)
  91. # store current directory
  92. topdir = os.getcwd()
  93. # do cvs update
  94. os.chdir(cvsdir)
  95. run("cvs update -d")
  96. os.chdir(topdir)
  97. # copy specfile and version file into CVS
  98. # plus upload tarball
  99. # and then commit
  100. for x in PROCESS_RELEASES:
  101. releasedir = os.path.join(cvsdir, x)
  102. rc = run("cp %s %s" % (specfile, releasedir))
  103. if versionfile:
  104. rc = run("cp %s %s" % (versionfile, releasedir))
  105. print "cd into %s" % releasedir
  106. os.chdir(releasedir)
  107. rc = run("make upload FILES=%s" % tarfile)
  108. os.chdir(cvsdir)
  109. run("cvs commit")
  110. # go back through each CVS directory and build stuff
  111. for x in PROCESS_RELEASES:
  112. releasedir = os.path.join(cvsdir, x)
  113. print "cd into %s" % releasedir
  114. os.chdir(releasedir)
  115. rc = run("make tag")
  116. rc = run("BUILD_FLAGS=\"--nowait\" make build",failok=True)
  117. print "---------------------------------------------"
  118. print "all done, assuming you didn't see anything weird"
  119. print "don't forget to visit https://admin.fedoraproject.org/updates"
  120. print " "