File: update_packages.py

package info (click to toggle)
roc-toolkit 0.4.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,700 kB
  • sloc: cpp: 102,987; ansic: 8,959; python: 6,125; sh: 942; makefile: 19; javascript: 9
file content (112 lines) | stat: -rwxr-xr-x 3,039 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /usr/bin/env python3

import datetime
import fileinput
import os
import os.path
import re
import subprocess
import sys
import textwrap

os.chdir(os.path.join(
    os.path.dirname(__file__), '..'))

def update_deb_copyright():
    in_path = 'docs/sphinx/about_project/authors.rst'
    out_path = 'debian/copyright'

    print(f'updating {out_path}')

    with open(in_path, 'r') as in_file:
        in_lines = in_file.readlines()

    with open(out_path, 'r') as out_file:
        out_content = out_file.readlines()

    updated_content = []

    for line in out_content:
        updated_content.append(line)
        if line.startswith('Copyright:'):
            break

    for line in in_lines:
        if line.startswith('* '):
            updated_content.append(line.replace('* ', '  '))

    for line in out_content:
        if line.startswith('License:'):
            updated_content.append(line)
            break

    with open(out_path, 'w') as out_file:
        out_file.writelines(updated_content)

def update_deb_changelog():
    in_path = 'docs/sphinx/development/changelog.rst'
    out_path = 'debian/changelog'

    print(f'updating {out_path}')

    in_file = open(in_path, 'r')
    out_file = open(out_path, 'w')

    def fprint(msg=''):
        print(msg, file=out_file)

    first = True

    for line in in_file.readlines():
        pad = re.sub(r'^(\s*).*$', r'\1', line.rstrip())
        line = line.strip()

        if line.startswith('==='):
            if not first:
                fprint()
                fprint(f' -- Roc Streaming authors <roc@freelists.org>  {prev_date}')
                fprint()
            first = False

            m = re.match('^Version\s+(\S+)\s+\((.*)\)$', prev_line)
            version, date = m.group(1), m.group(2)
            prev_date = datetime.datetime.strptime(date, "%b %d, %Y").\
                replace(tzinfo=datetime.timezone.utc).\
                strftime("%a, %d %b %Y %H:%M:%S %z")
            fprint(f'roc-toolkit ({version}) unstable; urgency=low')

        if line.startswith('---'):
            fprint()
            fprint(f'  [ {prev_line} ]')

        if line.startswith('* '):
            line = re.sub(r'`([^` ]+)\s*<[^` >]+>`_+', r'\1', line)
            line = re.sub(r'``', '`', line)
            fprint('\n'.join(textwrap.wrap(
                line, width=80, initial_indent=('  '+pad), subsequent_indent=('    '+pad))))

        prev_line = line

    fprint()
    fprint(f' -- Roc Streaming authors <roc@freelists.org>  {prev_date}')
    fprint()

def update_rpm_spec():
    out_path = 'rpm/roc-toolkit.spec'

    print(f'updating {out_path}')

    version = subprocess.check_output([
        sys.executable, 'scripts/scons_helpers/parse-version.py']).decode().strip()

    for line in fileinput.input(files=[out_path], inplace=True):
        m = re.match('^(Version:\s+).*$', line)
        if m:
            line = m.group(1) + version + '\n'
        print(line, end='')

update_deb_copyright()
update_deb_changelog()
update_rpm_spec()

print('done')