File: get_version.py

package info (click to toggle)
libtcod 1.24.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,756 kB
  • sloc: ansic: 46,186; cpp: 13,523; python: 4,814; makefile: 44; sh: 25
file content (29 lines) | stat: -rwxr-xr-x 753 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python3
"""
    Print the version number for libtcod.

    The --so flag can be used to get the library version number instead.
"""

import io
import re
import sys

RE_MAJOR = '.*#define TCOD_MAJOR_VERSION *([0-9]+)'
RE_MINOR = '.*#define TCOD_MINOR_VERSION *([0-9]+)'
RE_PATCH = '.*#define TCOD_PATCHLEVEL *([0-9]+)'
RE_VERSION = RE_MAJOR + RE_MINOR + RE_PATCH


def main():
    with io.open('../../src/libtcod/version.h', encoding='utf-8') as f:
        header = f.read()
    major, minor, patch = re.match(RE_VERSION, header, re.DOTALL).groups()
    if '--so' in sys.argv:
        print('{major}:{minor}'.format(**locals()))
    else:
        print('{major}.{minor}.{patch}'.format(**locals()))


if __name__ == '__main__':
    main()