File: since_xxx.py

package info (click to toggle)
josm 0.0.svn14760%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 187,192 kB
  • sloc: java: 317,260; xml: 197,001; perl: 10,125; jsp: 250; sh: 112; makefile: 94; python: 29
file content (44 lines) | stat: -rwxr-xr-x 1,606 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
# License: CC0

"""
Helper script to replace "@since xxx" in Javadoc by the upcoming revision number.

Will retrieve the current revision number from the server. It runs over all
modified and added .java files and replaces xxx in "since xxx" by the revision
number that is to be expected for the next commit.
"""

import xml.etree.ElementTree as ElementTree
import subprocess
import re

revision = None

def main():
    svn_status = subprocess.check_output("svn status --xml".split(" "))
    for el in ElementTree.fromstring(svn_status).findall("./target/entry"):
        if  el.find('wc-status').get("item") not in ["added", "modified"]:
            continue
        path = el.get("path")
        if not path.endswith('.java'):
            continue
        with open(path, 'r') as f:
            filedata = f.read()
        filedata2 = re.sub("since xxx", lambda _: "since {}".format(get_revision()), filedata)
        if filedata != filedata2:
            print("replacing 'since xxx' with 'since {}' in '{}'".format(get_revision(), path))
            with open(path, 'w') as f:
                f.write(filedata2)

def get_revision():
    global revision
    if revision is not None:
        return revision
    svn_info_local = subprocess.check_output("svn info --xml".split(" "))
    rep_url = ElementTree.fromstring(svn_info_local).findtext("./entry/repository/root")
    svn_info_server = subprocess.check_output("svn info --xml".split(" ") + [rep_url])
    revision = int(ElementTree.fromstring(svn_info_server).find("./entry").get("revision")) + 1
    return revision
    
main()