Update the version in the manpage document.
(data)
| 9 | |
| 10 | |
| 11 | def update_manpage(data): |
| 12 | """ |
| 13 | Update the version in the manpage document. |
| 14 | """ |
| 15 | if data["name"] != "qrcode": |
| 16 | return |
| 17 | |
| 18 | base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 19 | filename = os.path.join(base_dir, "doc", "qr.1") |
| 20 | with open(filename) as f: |
| 21 | lines = f.readlines() |
| 22 | |
| 23 | changed = False |
| 24 | for i, line in enumerate(lines): |
| 25 | if not line.startswith(".TH "): |
| 26 | continue |
| 27 | parts = re.split(r'"([^"]*)"', line) |
| 28 | if len(parts) < 5: |
| 29 | continue |
| 30 | changed = parts[3] != data["new_version"] |
| 31 | if changed: |
| 32 | # Update version |
| 33 | parts[3] = data["new_version"] |
| 34 | # Update date |
| 35 | parts[1] = datetime.datetime.now().strftime("%-d %b %Y") |
| 36 | lines[i] = '"'.join(parts) |
| 37 | break |
| 38 | |
| 39 | if changed: |
| 40 | with open(filename, "w") as f: |
| 41 | for line in lines: |
| 42 | f.write(line) |