source: josm/trunk/scripts/since_xxx.py@ 12139

Last change on this file since 12139 was 12120, checked in by bastiK, 7 years ago

new script to insert revision number for Javadoc @since xxx (see #14734)

File size: 1.3 KB
RevLine 
[12120]1#!/usr/bin/python
2# License: CC0
3
4"""
5Helper script to replace "@since xxx" in Javadoc by the upcoming revision number.
6
7Will retrieve the current revision number from the server. It runs over all
8modified and added .java files and replaces xxx in "@since xxx" by the revision
9number that is to be expected for the next commit.
10"""
11
12import xml.etree.ElementTree as ElementTree
13import subprocess
14
15svn_info_local = subprocess.check_output("svn info --xml".split(" "))
16rep_url = ElementTree.fromstring(svn_info_local).findtext("./entry/repository/root")
17svn_info_server = subprocess.check_output("svn info --xml".split(" ") + [rep_url])
18rev = int(ElementTree.fromstring(svn_info_server).find("./entry").get("revision")) + 1
19svn_status = subprocess.check_output("svn status --xml".split(" "))
20for el in ElementTree.fromstring(svn_status).findall("./target/entry"):
21 if el.find('wc-status').get("item") not in ["added", "modified"]:
22 continue
23 path = el.get("path")
24 if not path.endswith('.java'):
25 continue
26 with open(path, 'r') as f:
27 filedata = f.read()
28 filedata2 = filedata.replace("@since xxx", "@since {}".format(rev))
29 if filedata != filedata2:
30 print("replacing '@since xxx' with '@since {}' in '{}'".format(rev, path))
31 with open(path, 'w') as f:
32 f.write(filedata2)
33
Note: See TracBrowser for help on using the repository browser.