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.

vssutil.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import string
  2. import time
  3. import traceback
  4. import pythoncom
  5. import win32com.client
  6. import win32com.client.gencache
  7. import win32con
  8. constants = win32com.client.constants
  9. win32com.client.gencache.EnsureModule("{783CD4E0-9D54-11CF-B8EE-00608CC9A71F}", 0, 5, 0)
  10. error = "vssutil error"
  11. def GetSS():
  12. ss = win32com.client.Dispatch("SourceSafe")
  13. # SS seems a bit weird. It defaults the arguments as empty strings, but
  14. # then complains when they are used - so we pass "Missing"
  15. ss.Open(pythoncom.Missing, pythoncom.Missing, pythoncom.Missing)
  16. return ss
  17. def test(projectName):
  18. ss = GetSS()
  19. project = ss.VSSItem(projectName)
  20. for item in project.GetVersions(constants.VSSFLAG_RECURSYES):
  21. print(item.VSSItem.Name, item.VersionNumber, item.Action)
  22. # item=i.Versions[0].VSSItem
  23. # for h in i.Versions:
  24. # print `h.Comment`, h.Action, h.VSSItem.Name
  25. def SubstituteInString(inString, evalEnv):
  26. substChar = "$"
  27. fields = string.split(inString, substChar)
  28. newFields = []
  29. for i in range(len(fields)):
  30. didSubst = 0
  31. strVal = fields[i]
  32. if i % 2 != 0:
  33. try:
  34. strVal = eval(strVal, evalEnv[0], evalEnv[1])
  35. newFields.append(strVal)
  36. didSubst = 1
  37. except:
  38. traceback.print_exc()
  39. print("Could not substitute", strVal)
  40. if not didSubst:
  41. newFields.append(strVal)
  42. return string.join(map(str, newFields), "")
  43. def SubstituteInFile(inName, outName, evalEnv):
  44. inFile = open(inName, "r")
  45. try:
  46. outFile = open(outName, "w")
  47. try:
  48. while 1:
  49. line = inFile.read()
  50. if not line:
  51. break
  52. outFile.write(SubstituteInString(line, evalEnv))
  53. finally:
  54. outFile.close()
  55. finally:
  56. inFile.close()
  57. def VssLog(project, linePrefix="", noLabels=5, maxItems=150):
  58. lines = []
  59. num = 0
  60. labelNum = 0
  61. for i in project.GetVersions(constants.VSSFLAG_RECURSYES):
  62. num = num + 1
  63. if num > maxItems:
  64. break
  65. commentDesc = itemDesc = ""
  66. if i.Action[:5] == "Added":
  67. continue
  68. if len(i.Label):
  69. labelNum = labelNum + 1
  70. itemDesc = i.Action
  71. else:
  72. itemDesc = i.VSSItem.Name
  73. if str(itemDesc[-4:]) == ".dsp":
  74. continue
  75. if i.Comment:
  76. commentDesc = "\n%s\t%s" % (linePrefix, i.Comment)
  77. lines.append(
  78. "%s%s\t%s%s"
  79. % (
  80. linePrefix,
  81. time.asctime(time.localtime(int(i.Date))),
  82. itemDesc,
  83. commentDesc,
  84. )
  85. )
  86. if labelNum > noLabels:
  87. break
  88. return string.join(lines, "\n")
  89. def SubstituteVSSInFile(projectName, inName, outName):
  90. import win32api
  91. if win32api.GetFullPathName(inName) == win32api.GetFullPathName(outName):
  92. raise RuntimeError("The input and output filenames can not be the same")
  93. sourceSafe = GetSS()
  94. project = sourceSafe.VSSItem(projectName)
  95. # Find the last label
  96. label = None
  97. for version in project.Versions:
  98. if version.Label:
  99. break
  100. else:
  101. print("Couldnt find a label in the sourcesafe project!")
  102. return
  103. # Setup some local helpers for the conversion strings.
  104. vss_label = version.Label
  105. vss_date = time.asctime(time.localtime(int(version.Date)))
  106. now = time.asctime(time.localtime(time.time()))
  107. SubstituteInFile(inName, outName, (locals(), globals()))
  108. def CountCheckouts(item):
  109. num = 0
  110. if item.Type == constants.VSSITEM_PROJECT:
  111. for sub in item.Items:
  112. num = num + CountCheckouts(sub)
  113. else:
  114. if item.IsCheckedOut:
  115. num = num + 1
  116. return num
  117. def GetLastBuildNo(project):
  118. i = GetSS().VSSItem(project)
  119. # Find the last label
  120. lab = None
  121. for version in i.Versions:
  122. lab = str(version.Label)
  123. if lab:
  124. return lab
  125. return None
  126. def MakeNewBuildNo(project, buildDesc=None, auto=0, bRebrand=0):
  127. if buildDesc is None:
  128. buildDesc = "Created by Python"
  129. ss = GetSS()
  130. i = ss.VSSItem(project)
  131. num = CountCheckouts(i)
  132. if num > 0:
  133. msg = (
  134. "This project has %d items checked out\r\n\r\nDo you still want to continue?"
  135. % num
  136. )
  137. import win32ui
  138. if win32ui.MessageBox(msg, project, win32con.MB_YESNO) != win32con.IDYES:
  139. return
  140. oldBuild = buildNo = GetLastBuildNo(project)
  141. if buildNo is None:
  142. buildNo = "1"
  143. oldBuild = "<None>"
  144. else:
  145. try:
  146. buildNo = string.atoi(buildNo)
  147. if not bRebrand:
  148. buildNo = buildNo + 1
  149. buildNo = str(buildNo)
  150. except ValueError:
  151. raise error("The previous label could not be incremented: %s" % (oldBuild))
  152. if not auto:
  153. from pywin.mfc import dialog
  154. buildNo = dialog.GetSimpleInput(
  155. "Enter new build number", buildNo, "%s - Prev: %s" % (project, oldBuild)
  156. )
  157. if buildNo is None:
  158. return
  159. i.Label(buildNo, "Build %s: %s" % (buildNo, buildDesc))
  160. if auto:
  161. print("Branded project %s with label %s" % (project, buildNo))
  162. return buildNo
  163. if __name__ == "__main__":
  164. # UpdateWiseExeName("PyWiseTest.wse", "PyWiseTest-10.exe")
  165. # MakeVersion()
  166. # test(tp)
  167. # MakeNewBuildNo(tp)
  168. tp = "\\Python\\Python Win32 Extensions"
  169. SubstituteVSSInFile(
  170. tp, "d:\\src\\pythonex\\win32\\win32.txt", "d:\\temp\\win32.txt"
  171. )