Changeset 12787 in josm for trunk/scripts
- Timestamp:
- 2017-09-08T19:26:33+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/since_xxx.py
r12257 r12787 12 12 import xml.etree.ElementTree as ElementTree 13 13 import subprocess 14 import re 14 15 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) 16 revision = None 17 18 def 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 34 def 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 33 42 43 main()
Note:
See TracChangeset
for help on using the changeset viewer.