File: release.py

package info (click to toggle)
python-qrcode 8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 924 kB
  • sloc: python: 2,761; sh: 16; makefile: 11
file content (42 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download
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
"""
This file provides zest.releaser entrypoints using when releasing new
qrcode versions.
"""

import os
import re
import datetime


def update_manpage(data):
    """
    Update the version in the manpage document.
    """
    if data["name"] != "qrcode":
        return

    base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    filename = os.path.join(base_dir, "doc", "qr.1")
    with open(filename) as f:
        lines = f.readlines()

    changed = False
    for i, line in enumerate(lines):
        if not line.startswith(".TH "):
            continue
        parts = re.split(r'"([^"]*)"', line)
        if len(parts) < 5:
            continue
        changed = parts[3] != data["new_version"]
        if changed:
            # Update version
            parts[3] = data["new_version"]
            # Update date
            parts[1] = datetime.datetime.now().strftime("%-d %b %Y")
            lines[i] = '"'.join(parts)
        break

    if changed:
        with open(filename, "w") as f:
            for line in lines:
                f.write(line)