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

Last change on this file since 13416 was 12928, checked in by bastiK, 7 years ago

see #15229 - do not copy the entire preferences list, just to set a custom server API in OAuth wizard

  • Property svn:executable set to *
File size: 1.6 KB
Line 
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
14import re
15
16revision = None
17
18def main():
19 svn_status = subprocess.check_output("svn status --xml".split(" "))
20 for 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 = re.sub("since xxx", lambda _: "since {}".format(get_revision()), filedata)
29 if filedata != filedata2:
30 print("replacing 'since xxx' with 'since {}' in '{}'".format(get_revision(), path))
31 with open(path, 'w') as f:
32 f.write(filedata2)
33
34def get_revision():
35 global revision
36 if revision is not None:
37 return revision
38 svn_info_local = subprocess.check_output("svn info --xml".split(" "))
39 rep_url = ElementTree.fromstring(svn_info_local).findtext("./entry/repository/root")
40 svn_info_server = subprocess.check_output("svn info --xml".split(" ") + [rep_url])
41 revision = int(ElementTree.fromstring(svn_info_server).find("./entry").get("revision")) + 1
42 return revision
43
44main()
Note: See TracBrowser for help on using the repository browser.