BrandProject.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # BrandProject.py
  2. #
  3. # Brand a VSS project with a "build number", then optionally
  4. # stamp DLL/EXE files with version information.
  5. import win32api, os, string, sys
  6. import vssutil
  7. import bulkstamp
  8. def BrandProject(vssProjectName, descFile, stampPath, filesToSubstitute, buildDesc = None, auto=0, bRebrand = 0):
  9. # vssProjectName -- The name of the VSS project to brand.
  10. # descFile -- A test file containing descriptions of the files in the release.
  11. # stampPath -- The full path to where the files referenced in descFile can be found.
  12. path=win32api.GetFullPathName(stampPath)
  13. build = vssutil.MakeNewBuildNo(vssProjectName, buildDesc, auto, bRebrand)
  14. if build is None:
  15. print "Cancelled"
  16. return
  17. bulkstamp.scan( build, stampPath, descFile )
  18. for infile, outfile in filesToSubstitute:
  19. SubstituteVSSInFile(vssProjectName, infile, outfile)
  20. return 1
  21. def usage(msg):
  22. print msg
  23. print """\
  24. %s Usage:
  25. %s [options] vssProject descFile stampPath
  26. Automatically brand a VSS project with an automatically incremented
  27. build number, and stamp DLL/EXE files with the build number.
  28. Checks that no files are checked out in the project, and finds the last
  29. build number, and suggests the next number.
  30. Options:
  31. -a - Auto increment the build number, and brand (otherwise prompt
  32. for the build number after looking for the previous)
  33. -r - Restamp the files with the existing build number.
  34. -d - A description for the VSS Label.
  35. -f infile=outfile - Substitute special VSS labels in the specified text
  36. file with the text extracted from VSS.
  37. """ % (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0]))
  38. sys.exit(1)
  39. if __name__=='__main__':
  40. try:
  41. import getopt
  42. opts, args = getopt.getopt(sys.argv[1:], "af:d:r")
  43. except getopts.error, msg:
  44. usage(msg)
  45. bAuto = bRebrand = 0
  46. stampFiles = []
  47. desc = None
  48. for opt, val in opts:
  49. if opt == '-a':
  50. bAuto = 1
  51. if opt == '-f':
  52. infile, outfile = string.split(val, "=", 2)
  53. stampFiles.append((infile, outfile))
  54. if opt == '-d':
  55. desc = val
  56. if opt == '-r':
  57. bRebrand = 1
  58. if len(args)<3:
  59. usage("You must specify the required arguments")
  60. vssProjectName = "$\\" + args[0]
  61. descFile = args[1]
  62. path = args[2]
  63. try:
  64. os.stat(descFile)
  65. except IOError:
  66. usage("The description file '%s' can not be found" % (descFile))
  67. if not os.path.isdir(path):
  68. usage("The path to the files to stamp '%s' does not exist" % (path))
  69. BrandProject(vssProjectName, descFile, path, stampFiles, desc, bAuto, bRebrand)