Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bulkstamp.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #
  2. # bulkstamp.py:
  3. # Stamp versions on all files that can be found in a given tree.
  4. #
  5. # USAGE: python bulkstamp.py <version> <root directory> <descriptions>
  6. #
  7. # Example: python bulkstamp.py 103 ..\win32\Build\ desc.txt
  8. #
  9. # <version> corresponds to the build number. It will be concatenated with
  10. # the major and minor version numbers found in the description file.
  11. #
  12. # Description information is pulled from an input text file with lines of
  13. # the form:
  14. #
  15. # <basename> <white space> <description>
  16. #
  17. # For example:
  18. #
  19. # PyWinTypes.dll Common types for Python on Win32
  20. # etc
  21. #
  22. # The product's name, major, and minor versions are specified as:
  23. #
  24. # name <white space> <value>
  25. # major <white space> <value>
  26. # minor <white space> <value>
  27. #
  28. # The tags are case-sensitive.
  29. #
  30. # Any line beginning with "#" will be ignored. Empty lines are okay.
  31. #
  32. import fnmatch
  33. import os
  34. import sys
  35. import verstamp
  36. import win32api
  37. numStamped = 0
  38. g_patterns = [
  39. "*.dll",
  40. "*.pyd",
  41. "*.exe",
  42. "*.ocx",
  43. ]
  44. def walk(arg, dirname, names):
  45. global numStamped
  46. vars, debug, descriptions = arg
  47. for name in names:
  48. for pat in g_patterns:
  49. if fnmatch.fnmatch(name, pat):
  50. # Handle the "_d" thing.
  51. pathname = os.path.join(dirname, name)
  52. base, ext = os.path.splitext(name)
  53. if base[-2:] == "_d":
  54. name = base[:-2] + ext
  55. is_dll = ext.lower() != ".exe"
  56. if os.path.normcase(name) in descriptions:
  57. desc = descriptions[os.path.normcase(name)]
  58. try:
  59. verstamp.stamp(vars, pathname, desc, is_dll=is_dll)
  60. numStamped = numStamped + 1
  61. except win32api.error as exc:
  62. print(
  63. "Could not stamp",
  64. pathname,
  65. "Error",
  66. exc.winerror,
  67. "-",
  68. exc.strerror,
  69. )
  70. else:
  71. print("WARNING: description not provided for:", name)
  72. # skip branding this - assume already branded or handled elsewhere
  73. # print "Stamped", pathname
  74. def load_descriptions(fname, vars):
  75. retvars = {}
  76. descriptions = {}
  77. lines = open(fname, "r").readlines()
  78. for i in range(len(lines)):
  79. line = lines[i].strip()
  80. if line != "" and line[0] != "#":
  81. idx1 = line.find(" ")
  82. idx2 = line.find("\t")
  83. if idx1 == -1 or idx2 < idx1:
  84. idx1 = idx2
  85. if idx1 == -1:
  86. print("ERROR: bad syntax in description file at line %d." % (i + 1))
  87. sys.exit(1)
  88. key = line[:idx1]
  89. val = line[idx1:].strip()
  90. if key in vars:
  91. retvars[key] = val
  92. else:
  93. descriptions[key] = val
  94. if "product" not in retvars:
  95. print("ERROR: description file is missing the product name.")
  96. sys.exit(1)
  97. if "major" not in retvars:
  98. print("ERROR: description file is missing the major version number.")
  99. sys.exit(1)
  100. if "minor" not in retvars:
  101. print("ERROR: description file is missing the minor version number.")
  102. sys.exit(1)
  103. return retvars, descriptions
  104. def scan(build, root, desc, **custom_vars):
  105. global numStamped
  106. numStamped = 0
  107. try:
  108. build = int(build)
  109. except ValueError:
  110. print("ERROR: build number is not a number: %s" % build)
  111. sys.exit(1)
  112. debug = 0 ### maybe fix this one day
  113. varList = ["major", "minor", "sub", "company", "copyright", "trademarks", "product"]
  114. vars, descriptions = load_descriptions(desc, varList)
  115. vars["build"] = build
  116. vars.update(custom_vars)
  117. arg = vars, debug, descriptions
  118. os.path.walk(root, walk, arg)
  119. print("Stamped %d files." % (numStamped))
  120. if __name__ == "__main__":
  121. if len(sys.argv) != 4:
  122. print("ERROR: incorrect invocation. See script's header comments.")
  123. sys.exit(1)
  124. scan(*tuple(sys.argv[1:]))