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(): |
| 28 | tree = ElementTree.fromstring(svn_status) |
| 29 | rev = get_revision() |
| 30 | if len(args) == 2: |
| 31 | for change_set in tree.findall("./changelist"): |
| 32 | if ( |
| 33 | "name" in change_set.attrib |
| 34 | and change_set.attrib["name"] == args[1] |
| 35 | ): |
| 36 | for el in change_set.findall("./entry"): |
| 37 | write_xxx(rev, el) |
| 38 | elif len(args) > 2: |
| 39 | raise ValueError( |
| 40 | "Too many args: only one changelist should be passed at a time, " |
| 41 | "or none at all " |
| 42 | ) |
| 43 | else: |
| 44 | for el in tree.findall("./target/entry"): |
| 45 | write_xxx(rev, el) |
| 46 | |
| 47 | |
| 48 | def write_xxx(rev: int, el: ElementTree.Element) -> None: |
| 49 | """ |
| 50 | Write a revision to a changed file |
| 51 | :param rev: The revision to write |
| 52 | :param el: The element containing the path to the file to update |
| 53 | :return: Nothing |
| 54 | """ |
| 55 | if el.find("wc-status").get("item") not in ["added", "modified"]: |
| 56 | return |
| 57 | path = el.get("path") |
| 58 | if not path.endswith(".java"): |
| 59 | return |
| 60 | with open(path, "r") as f: |
| 61 | old_text = f.read() |
| 62 | new_text = re.sub("since xxx", lambda _: "since {}".format(rev), old_text) |
| 63 | if old_text != new_text: |
| 64 | print( |
| 65 | "replacing 'since xxx' with 'since {}' in '{}'".format(rev, path) |
| 66 | ) |
| 67 | with open(path, "w") as f: |
| 68 | f.write(new_text) |
| 69 | |
| 70 | |
| 71 | def get_revision() -> int: |
| 72 | """ |
| 73 | Get the next revision |
| 74 | :return: The current revision + 1 |
| 75 | """ |
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 |
| 80 | rep_url = ElementTree.fromstring(svn_info_local).findtext( |
| 81 | "./entry/repository/root" |
| 82 | ) |
| 83 | svn_info_server = subprocess.check_output( |
| 84 | "svn info --xml".split(" ") + [rep_url] |
| 85 | ) |
| 86 | revision = ( |
| 87 | int( |
| 88 | ElementTree.fromstring(svn_info_server) |
| 89 | .find("./entry") |
| 90 | .get("revision") |
| 91 | ) |
| 92 | + 1 |
| 93 | ) |