Team Fortress 2 Source Code as on 22/4/2020
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.

150 lines
5.1 KiB

  1. import sys, os, string, re, time, smtplib, getopt
  2. # syncs the current clientspec
  3. def Sync( szP4SrcFilesToWatch, bForce ):
  4. print "syncing to files " + szP4SrcFilesToWatch + "..."
  5. sForce = ""
  6. if bForce:
  7. sForce = "-f "
  8. aszSyncLines = string.split( szP4SrcFilesToWatch, ";" )
  9. for szLine in aszSyncLines:
  10. if szLine:
  11. print "p4 sync " + sForce + szLine
  12. os.popen('p4 sync ' + sForce + szLine)
  13. print " sync completed"
  14. # current changelist number for this clientspec
  15. def SubmittedChangelist( szP4SrcFilesToWatch ):
  16. szChangeText = os.popen('p4 changes -m1 -s submitted ' + szP4SrcFilesToWatch).read()
  17. line = []
  18. line = string.split( szChangeText )
  19. if len(line) > 0:
  20. return line[1]
  21. # returns a set of changes of range [start, end]
  22. def GetChangelistRange(start, end, szP4SrcFilesToWatch):
  23. if start and end:
  24. szChangeText = os.popen('p4 changes -m10 ' + szP4SrcFilesToWatch + '@' + start + ',' + end).read()
  25. return string.split(szChangeText, '\n');
  26. szResult = []
  27. return szResult
  28. # returns the raw text of a set of the most recent submissions
  29. def GetRecentCheckins( szP4SrcFilesToWatch ):
  30. szChangeText = os.popen('p4 changes -m5 -s submitted ' + szP4SrcFilesToWatch).read()
  31. return "Most recent checkins:\n" + szChangeText
  32. # perforce counter access
  33. def GetCounter(counter):
  34. return string.split(os.popen('p4 counter ' + counter).read(), '\n')[0]
  35. #returns the raw text of all unverified checkins
  36. def GetUnverifiedCheckins( szP4SrcFilesToWatch, szVerifiedCounter, szChangeCounter ):
  37. szCounter = GetCounter( szVerifiedCounter )
  38. szLastVerified = str( int( szCounter ) + 1 )
  39. szCurrentChange = GetCounter( szChangeCounter )
  40. szChangeText = os.popen('p4 changes -s submitted ' + szP4SrcFilesToWatch + '@' + szLastVerified + ',@' + szCurrentChange).read()
  41. return "Unverified checkins:\n" + szChangeText
  42. # extracts an email from a "changes" output line
  43. def GetEmailFromChangeLine(changeline):
  44. change = (string.split(changeline, ' '))[1]
  45. output = os.popen('p4 change -o ' + change).read()
  46. user = string.split(string.split(output, "User:")[2])[0]
  47. output = os.popen('p4 user -o ' + user).read()
  48. return string.split(string.split(output, "Email:")[2])[0]
  49. # perforce counter setting
  50. def SetCounter(counter, value):
  51. os.popen('p4 counter ' + counter + ' ' + value).read()
  52. # checks to see if any update is currently available
  53. def AnyNewCheckins( szChangeCounter, szP4SrcFilesToWatch ):
  54. szChange = GetCounter(szChangeCounter)
  55. if not szChange:
  56. #is this the problem? Every night all these things fail.
  57. return 0
  58. return szChange <> SubmittedChangelist( szP4SrcFilesToWatch )
  59. def LockMutex( szMutex ):
  60. szLogLines = os.popen('newp4mutex lock ' + szMutex + ' 3 steambuilder perforce:1666').read()
  61. count = string.count( szLogLines, '\n' )
  62. if ( count < 3 ):
  63. print szLogLines
  64. print "HERE IS THE WEIRD LOCK ERROR!"
  65. print szMutex + "mutex lock failed."
  66. return 0
  67. szT = string.split(szLogLines, '\n')[2]
  68. successLine = string.split( szT, ' ')
  69. if successLine[0] == "Success:":
  70. print szMutex + " mutex locked."
  71. return 1
  72. else:
  73. print szMutex + " mutex lock failed."
  74. return 0
  75. def LockMutexOld( szMutex ):
  76. szLogLines = os.popen('p4mutex lock ' + szMutex + ' 3 steambuilder perforce:1666').read()
  77. count = string.count( szLogLines, '\n' )
  78. if ( count < 3 ):
  79. print szLogLines
  80. print "HERE IS THE WEIRD LOCK ERROR!"
  81. print szMutex + "mutex lock failed."
  82. return 0
  83. szT = string.split(szLogLines, '\n')[3]
  84. successLine = string.split( szT, ' ')
  85. if successLine[0] == "Success:":
  86. print szMutex + " mutex locked."
  87. return 1
  88. else:
  89. print szMutex + " mutex lock failed."
  90. return 0
  91. def UnlockMutex( szMutex ):
  92. szLogLines = os.popen('newp4mutex release ' + szMutex + ' 3 steambuilder perforce:1666').read()
  93. count = string.count( szLogLines, '\n' )
  94. if ( count < 3 ):
  95. print szLogLines
  96. print "HERE IS THE WEIRD RELEASE ERROR!"
  97. print szMutex + "mutex release failed."
  98. return 0
  99. szT = string.split(szLogLines, '\n')[2]
  100. # print szT
  101. successLine = string.split( szT, ' ')
  102. # print successLine
  103. if successLine[0] == "Success:":
  104. print szMutex + " mutex released."
  105. return 1
  106. else:
  107. print szMutex + " mutex release failed."
  108. return 0
  109. def Integrate( szBranch ):
  110. return os.popen('p4 integ -b ' + szBranch + ' -1 -i' ).read()
  111. def Revert( szFiles ):
  112. return os.popen('p4 revert ' + szFiles).read()
  113. def Resolve():
  114. return os.popen('p4 resolve -am').read()
  115. def Fstat( szFiles ):
  116. szConflicts = os.popen('p4 fstat -Ru ' + szFiles).read()
  117. return szConflicts
  118. def Changes( szFile, iNumResults ):
  119. return os.popen('p4 changes -m' + iNumResults + ' ' + szFile).read()
  120. def Query( szMutex ):
  121. szLines = os.popen( 'p4mutex query ' + szMutex ).read()
  122. count = string.count( szLines, 'HELD' )
  123. if (count == 0 ):
  124. return 1
  125. else:
  126. print "Lock held"
  127. return 0
  128. def SetClient( szClient ):
  129. os.environ['P4CLIENT'] = szClient