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.

svnlog-to-rn.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/python
  2. ################################################################################
  3. # SVN Log to ChangeLog generator for Release Notes
  4. #
  5. # Generates list of changes in HTML for ChangeLog
  6. # from SVN Log in XML format. You typically generate the log with
  7. # a command such as:
  8. # svn log -v -r 1234:HEAD > svnlog-1234:HEAD.log.xml
  9. # The command must be executed in the root directory of Toolkit project,
  10. # either in the trunk or in the proper branch. The converter is then
  11. # used as follows:
  12. # ./build/bin/svnlog-to-rn.py svnlog-1234:HEAD.log.xml
  13. #
  14. # The ChangeLog generator will strip away any merges that begin with
  15. # "Merged [...] from trunk to x.x branch."
  16. #
  17. # The generator will handle the following markup:
  18. # - Changeset tags such as [1234] to links to dev.itmill.com/changeset/1234
  19. # - Ticket references such as #1234 to links to dev.itmill.com/ticket/1234
  20. # - If ticket reference does not have explanation in parentheses,
  21. # the script will fetch the summary of the ticket from Trac and
  22. # add it in parentheses after the reference, such as:
  23. # "fixes #1234 (A nasty bug I found)".
  24. #
  25. # Requirements:
  26. # - Xalan
  27. ################################################################################
  28. import sys,re,os,httplib,urllib
  29. ################################################################################
  30. # Convert XML to XHTML
  31. # - The transformation includes various relevent information
  32. # and does basic formatting
  33. ################################################################################
  34. # Determine path to XSLT file
  35. pathToScript = sys.argv[0]
  36. sloc = pathToScript.rfind("/")
  37. pathToScript = pathToScript[:sloc]
  38. if len(sys.argv) != 2:
  39. print "Usage: svnlog-to-rn.py <logfile.xml>"
  40. print "Read the svnlog-to-rn.py header for more info."
  41. sys.exit(1)
  42. # Open Xalan
  43. filename = sys.argv[1]
  44. fin = open(filename, "r")
  45. (pout,pin) = os.popen2("xalan -xsl %s/svnlog-to-rn.xsl" % (pathToScript))
  46. # Preprocessing before feeding to XSLT Processor
  47. lines = fin.readlines()
  48. out = ""
  49. for line in lines:
  50. if line.find("action") != -1:
  51. line = line.replace(r'>[^<]+/', '')
  52. #print line,
  53. pout.write(line)
  54. pout.close()
  55. ################################################################################
  56. # Helper functions for postprocessing
  57. ################################################################################
  58. # Retrieves summary string with HTTP
  59. def fetchSummary(ticketno):
  60. params = urllib.urlencode({'format': 'tab'})
  61. conn = httplib.HTTPConnection("dev.itmill.com")
  62. conn.request("GET", "/ticket/%d?%s" % (ticketno, params) )
  63. response = conn.getresponse()
  64. data = response.read()
  65. conn.close()
  66. lines = data.split("\n")
  67. cols = lines[1].split("\t")
  68. return cols[1]
  69. # Adds summary to ticket number, unless the context already has it
  70. def addSummary(m):
  71. ticketnum = int(m.group(1))
  72. context = m.group(2)
  73. if re.match(" *\(", context):
  74. # The context already has ticket summary
  75. return "#%d%s" % (ticketnum, context)
  76. summary = fetchSummary(ticketnum)
  77. return "#%s (<i>%s</i>) %s" % (ticketnum, summary, context)
  78. ################################################################################
  79. # Postprocessing for XSLT output
  80. ################################################################################
  81. lines = pin.readlines()
  82. for line in lines:
  83. # Add ticket summary after ticket number, if missing
  84. line = re.sub(r'#([0-9]+)(.*)', addSummary, line)
  85. # Change ticket numbers to references to tickets
  86. line = re.sub(r'#([0-9]+)', '#<a href="http://dev.itmill.com/ticket/\\1">\\1</a>', line)
  87. # Change changeset numbers to references to changesets
  88. #line = re.sub(r'\[([0-9]+)\]', '[<a href="http://dev.itmill.com/changeset/\\1">\\1</a>]', line)
  89. # Remove prefix about merging
  90. line = re.sub(r'Merged.+from trunk to [0-9]+.[0-9]+ branch: ', '', line)
  91. print line,