hudson.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # hudson runs this from the raptor/util/install-linux directory
  2. import datetime
  3. import os
  4. import re
  5. import shutil
  6. import subprocess
  7. import sys
  8. # run "hg id" to get the current branch name and tip changeset
  9. hgid = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE)
  10. stdout = hgid.communicate()[0]
  11. if hgid.returncode == 0 and len(stdout) >= 12:
  12. changeset = stdout[0:12]
  13. print "CHANGESET", changeset
  14. prototype = ("wip" in stdout or "fix" in stdout)
  15. print "PROTOTYPE", prototype
  16. else:
  17. sys.stderr.write("error: failed to get tip mercurial changeset.\n")
  18. sys.exit(1)
  19. # get today's date in ISO format YYYY-MM-DD
  20. today = datetime.date.today().isoformat()
  21. print "DATE", today
  22. # insert the date and changeset into the raptor/version.py file
  23. filename = "../../raptor/version.py"
  24. lines = []
  25. try:
  26. file = open(filename, "r")
  27. for line in file.readlines():
  28. if "ISODATE" in line and "CHANGESET" in line:
  29. line = line.replace("ISODATE", today)
  30. line = line.replace("CHANGESET", changeset)
  31. if prototype:
  32. line = line.replace("system", "system PROTOTYPE")
  33. lines.append(line)
  34. else:
  35. lines.append(line)
  36. except IOError, ex:
  37. sys.stderr.write("error: failed to read file '%s'\n%s" % (filename, str(ex)))
  38. sys.exit(1)
  39. finally:
  40. file.close()
  41. # ... and write the modified raptor/version.py file
  42. try:
  43. file = open(filename, "w")
  44. for line in lines:
  45. file.write(line)
  46. except IOError, ex:
  47. sys.stderr.write("error: failed to write file '%s'\n%s" % (filename, str(ex)))
  48. sys.exit(1)
  49. finally:
  50. file.close()
  51. # check that we really did change the raptor version string
  52. sbs_v = subprocess.Popen(["../../bin/sbs", "-v"], stdout=subprocess.PIPE)
  53. version = sbs_v.communicate()[0]
  54. if sbs_v.returncode == 0:
  55. print "VERSION", version
  56. if not today in version or not changeset in version:
  57. sys.stderr.write("error: date or changeset does not match the sbs version.\n")
  58. sys.exit(1)
  59. if prototype and not "PROTOTYPE" in version:
  60. sys.stderr.write("error: the sbs version should be marked PROTOTYPE.\n")
  61. sys.exit(1)
  62. else:
  63. sys.stderr.write("error: failed to get sbs version.\n")
  64. sys.exit(1)
  65. # run the Linux installer maker script
  66. package_sbs = subprocess.Popen(["./package_sbs.sh", "-s"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  67. (stdout, stderr) = package_sbs.communicate()
  68. if package_sbs.returncode != 0:
  69. sys.stderr.write("error: failed to create linux package of sbs.\n")
  70. sys.exit(1)
  71. # find the name of the archive in /tmp
  72. match = re.search('archive "([^"]+)" successfully created', stdout)
  73. if match:
  74. tmp_archive = "/tmp/" + match.group(1)
  75. print "TMP ARCHIVE", tmp_archive
  76. else:
  77. sys.stderr.write("error: failed to find linux archive file.\n")
  78. sys.exit(1)
  79. # move it to the WORKSPACE root
  80. if 'WORKSPACE' in os.environ:
  81. name = re.sub(r'/tmp/(sbs-\d+\.\d+\.\d+-).*', r'\1', tmp_archive)
  82. if prototype:
  83. fullname = name + "PROTOTYPE-" + changeset + ".run"
  84. else:
  85. fullname = name + changeset + ".run"
  86. final_archive = os.path.join(os.environ['WORKSPACE'], fullname)
  87. print "WORKSPACE ARCHIVE", final_archive
  88. else:
  89. sys.stderr.write("error: no WORKSPACE is set.\n")
  90. sys.exit(1)
  91. try:
  92. shutil.move(tmp_archive, final_archive)
  93. except Error, err:
  94. sys.stderr.write("error: could not rename '%s' as '%s'.\n" % (tmp_archive, final_archive))
  95. sys.exit(1)
  96. # the end