hudson.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # hudson runs this from the raptor/util/install-windows directory
  2. import os
  3. import re
  4. import shutil
  5. import subprocess
  6. import sys
  7. # run "hg id" to get the current branch name and tip changeset
  8. hgid = subprocess.Popen(["hg", "id"], stdout=subprocess.PIPE)
  9. stdout = hgid.communicate()[0]
  10. if hgid.returncode == 0 and len(stdout) >= 12:
  11. changeset = stdout[0:12]
  12. print "CHANGESET", changeset
  13. prototype = ("wip" in stdout or "fix" in stdout)
  14. print "PROTOTYPE", prototype
  15. else:
  16. sys.stderr.write("error: failed to get tip mercurial changeset.\n")
  17. sys.exit(1)
  18. # get the raptor version string
  19. sbs_v = subprocess.Popen(["../../bin/sbs", "-v"], stdout=subprocess.PIPE)
  20. version = sbs_v.communicate()[0]
  21. if sbs_v.returncode == 0:
  22. print "VERSION", version
  23. if not changeset in version:
  24. sys.stderr.write("error: changeset does not match the sbs version.\n")
  25. sys.exit(1)
  26. if prototype and not "PROTOTYPE" in version:
  27. sys.stderr.write("error: the sbs version should be marked PROTOTYPE.\n")
  28. sys.exit(1)
  29. else:
  30. sys.stderr.write("error: failed to get sbs version.\n")
  31. sys.exit(1)
  32. # find the SBS_HOME and WIN32_SUPPORT
  33. if 'SBS_HOME' in os.environ:
  34. sbs_home = os.environ['SBS_HOME']
  35. else:
  36. sys.stderr.write("error: no SBS_HOME is set.\n")
  37. sys.exit(1)
  38. if 'WIN32_SUPPORT' in os.environ:
  39. win32_support = os.environ['WIN32_SUPPORT']
  40. else:
  41. sys.stderr.write("error: no WIN32_SUPPORT is set.\n")
  42. sys.exit(1)
  43. # run the Windows installer maker script
  44. if prototype:
  45. postfix = "-PROTOTYPE-" + changeset
  46. else:
  47. postfix = "-" + changeset
  48. package_sbs = subprocess.Popen(["python", "raptorinstallermaker.py",
  49. "-s", sbs_home, "-w", win32_support,
  50. "--postfix=" + postfix],
  51. stdout=subprocess.PIPE) #, stderr=subprocess.PIPE)
  52. (stdout, stderr) = package_sbs.communicate()
  53. if package_sbs.returncode == 0:
  54. match = re.search('Output: "([^"]+)"', stdout)
  55. zip_match = re.search('Zipoutput: "([^"]+)"', stdout)
  56. if match:
  57. tmp_archive = match.group(1)
  58. print "TMP ARCHIVE", tmp_archive
  59. else:
  60. sys.stderr.write("error: failed to find packaged filename.\n")
  61. sys.exit(1)
  62. if zip_match:
  63. tmp_zip_archive = zip_match.group(1)
  64. print "TMP ZIP ARCHIVE", tmp_zip_archive
  65. else:
  66. sys.stderr.write("error: failed to find zip filename.\n")
  67. sys.exit(1)
  68. else:
  69. sys.stderr.write("error: failed to create windows package of sbs.\n")
  70. sys.exit(1)
  71. # move the results to WORKSPACE
  72. if 'WORKSPACE' in os.environ:
  73. final_archive = os.path.join(os.environ['WORKSPACE'], os.path.basename(tmp_archive))
  74. final_zip_archive = os.path.join(os.environ['WORKSPACE'], os.path.basename(tmp_zip_archive))
  75. print "WORKSPACE ARCHIVE", final_archive
  76. print "WORKSPACE ZIP ARCHIVE", final_zip_archive
  77. else:
  78. sys.stderr.write("error: no WORKSPACE is set.\n")
  79. sys.exit(1)
  80. try:
  81. shutil.move(tmp_archive, final_archive)
  82. except Error, err:
  83. sys.stderr.write("error: could not rename '%s' as '%s'.\n" % (tmp_archive, final_archive))
  84. sys.exit(1)
  85. try:
  86. shutil.move(tmp_zip_archive, final_zip_archive)
  87. except Error, err:
  88. sys.stderr.write("error: could not rename '%s' as '%s'.\n" % (tmp_zip_archive, final_zip_archive))
  89. sys.exit(1)
  90. # the end