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.

121 lines
3.5 KiB

  1. #!/usr/bin/env python
  2. import getopt
  3. import os
  4. import re
  5. import sys
  6. import subprocess
  7. import pdb
  8. def usage():
  9. print >> sys.stderr, 'checks in all open files in the default changelist, aggregating change comments from the provided list'
  10. print >> sys.stderr, ''
  11. print >> sys.stderr, 'usage:'
  12. print >> sys.stderr, sys.argv[0] + ' [-c p4client] [-p p4port] [-u p4user] [-d changelog (prefix)] [--changes "list of change numbers"]'
  13. print >> sys.stderr, ''
  14. print >> sys.stderr, 'the list of changes must either be the last argument, or be quoted, so '
  15. print >> sys.stderr, sys.argv[0] + ' ... --changes 1 2 3 [ok] '
  16. print >> sys.stderr, sys.argv[0] + ' ... --changes "1 2 3" ... [ok]'
  17. print >> sys.stderr, sys.argv[0] + ' ... -changes 1 2 3 ... [bad]'
  18. def main():
  19. try:
  20. opts, args = getopt.getopt( sys.argv[1:], "c:p:u:d:", [ "changes=" ] )
  21. except getopt.GetoptError, err:
  22. print >> sys.stderr, str(err)
  23. usage()
  24. sys.exit(-1)
  25. p4user = None
  26. p4client = None
  27. p4port = None
  28. changelog = None
  29. changes = []
  30. p4cmdbase = [ "p4" ]
  31. for opt, arg in opts:
  32. if opt == "-c":
  33. p4cmdbase.extend( [ opt, arg ] )
  34. p4client = arg
  35. elif opt == "-p":
  36. p4cmdbase.extend( [ opt, arg ] )
  37. p4port = arg
  38. elif opt == "-u":
  39. p4cmdbase.extend( [ opt, arg ] )
  40. p4user = arg
  41. elif opt == "-d":
  42. # eat this one, we'll build our own changespec
  43. changelog = arg
  44. elif opt == "--changes":
  45. # and these are the change #'s to include descriptions of
  46. changes = arg.split()
  47. if args is not None:
  48. changes.extend( args )
  49. if p4user is None:
  50. p4user = os.getenv( "P4USER" )
  51. if p4client is None:
  52. p4client = os.getenv( "P4CLIENT" )
  53. if p4port is None:
  54. p4port = os.getenv( "P4PORT" )
  55. if p4user is None or p4client is None or p4port is None:
  56. print >> sys.stderr, "one or more p4 environment variables (p4user, p4client, p4port) aren't set."
  57. usage()
  58. sys.exit(-1)
  59. # get the list of opened files
  60. openFiles = []
  61. stdout = subprocess.Popen( " ".join( p4cmdbase ) + " opened -c default", shell=True, stdout=subprocess.PIPE ).stdout
  62. lines = stdout.readlines()
  63. stdout.close()
  64. filere = re.compile( "(.*)#.*\n" )
  65. for line in lines:
  66. m = filere.match( line )
  67. if m is not None:
  68. openFiles += [ m.groups()[ 0 ] ]
  69. if openFiles == []:
  70. sys.stderr.write( "no files to submit from the default changelist" )
  71. sys.exit(0)
  72. # get the changenotes from the specified changes
  73. changeLines = []
  74. for change in changes:
  75. stdout = subprocess.Popen( " ".join( p4cmdbase ) + " describe -s " + change, shell=True, stdout=subprocess.PIPE ).stdout
  76. lines = stdout.readlines()
  77. stdout.close()
  78. stopre = re.compile( "Affected files ..." )
  79. for line in lines:
  80. if stopre.match( line ):
  81. break
  82. changeLines += [ line.strip() ]
  83. change_spec = ''
  84. change_spec += 'Change: new\n'
  85. change_spec += 'Client: %s\n' % p4client
  86. change_spec += 'User: %s\n' % p4user
  87. change_spec += 'Description:\n'
  88. # if they supplied a changelog line, prepend that to the list of changes
  89. if changelog is not None:
  90. change_spec += '\t%s\n\n' % changelog
  91. # and now each line from all the changelists
  92. if changeLines != []:
  93. change_spec += '\t%s\n\n' % "Changes included in this submit:"
  94. for changeLine in changeLines:
  95. change_spec += '\t%s\n' % changeLine
  96. change_spec += 'Files:\n'
  97. for file in openFiles:
  98. change_spec += '\t%s\n' % file
  99. p = subprocess.Popen( " ".join( p4cmdbase ) + " submit -i", shell=True, stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr )
  100. p.communicate( change_spec )
  101. sys.exit( p.returncode )
  102. if __name__ == '__main__':
  103. main()