Changeset 12787 in josm for trunk/scripts


Ignore:
Timestamp:
2017-09-08T19:26:33+02:00 (2 years ago)
Author:
bastiK
Message:

improve since_xxx.py script: do not fetch revision from server until pattern "@since xxx" is found

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/since_xxx.py

    r12257 r12787  
    1212import xml.etree.ElementTree as ElementTree
    1313import subprocess
     14import re
    1415
    15 svn_info_local = subprocess.check_output("svn info --xml".split(" "))
    16 rep_url = ElementTree.fromstring(svn_info_local).findtext("./entry/repository/root")
    17 svn_info_server = subprocess.check_output("svn info --xml".split(" ") + [rep_url])
    18 rev = int(ElementTree.fromstring(svn_info_server).find("./entry").get("revision")) + 1
    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 = 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)
     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    return int(ElementTree.fromstring(svn_info_server).find("./entry").get("revision")) + 1
    3342   
     43main()
Note: See TracChangeset for help on using the changeset viewer.