File: versions.py

package info (click to toggle)
nodejs 20.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 219,072 kB
  • sloc: cpp: 1,277,408; javascript: 565,332; ansic: 129,476; python: 58,536; sh: 3,841; makefile: 2,725; asm: 1,732; perl: 248; lisp: 222; xml: 42
file content (52 lines) | stat: -rw-r--r-- 2,043 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3

import fileinput
import re


def update_cmakelists_version(new_version: str, file_path: str) -> None:
    inside_project = False
    with fileinput.FileInput(file_path, inplace=True) as cmakelists:
        for line in cmakelists:
            if 'set(ADA_LIB_VERSION' in line:
                line = re.sub(r'[0-9]+\.[0-9]+\.[0-9]+', new_version, line)
            elif 'set(ADA_LIB_SOVERSION' in line:
                line = re.sub(r'[0-9]+', new_version.split('.')[0], line)

            elif 'project(' in line:
                inside_project = True
            elif inside_project:
                if 'VERSION' in line:
                    line = re.sub(r'[0-9]+\.[0-9]+\.[0-9]+', new_version, line)
                    inside_project = False
            print(line, end='')


def update_ada_version_h(new_version: str, file_path: str) -> None:
    new_version_list = new_version.split('.')
    with fileinput.FileInput(file_path, inplace=True) as ada_version_h:
        inside_enum = False
        for line in ada_version_h:
            if '#define ADA_VERSION' in line:
                line = f'#define ADA_VERSION "{new_version}"\n'

            elif 'enum {' in line:
                inside_enum = True
            elif inside_enum:
                if line.strip().startswith('ADA_VERSION_MAJOR'):
                    line = re.sub(r'\d+', new_version_list[0], line)
                elif line.strip().startswith('ADA_VERSION_MINOR'):
                    line = re.sub(r'\d+', new_version_list[1], line)
                elif line.strip().startswith('ADA_VERSION_REVISION'):
                    line = re.sub(r'\d+', new_version_list[2], line)

            print(line, end='')


def update_doxygen_version(new_version: str, file_path: str) -> None:
    with fileinput.FileInput(file_path, inplace=True) as doxygen:
        for line in doxygen:
            if line.strip().startswith('PROJECT_NUMBER         ='):
                line = f'PROJECT_NUMBER         = "{new_version}"\n'

            print(line, end='')