summaryrefslogtreecommitdiffstats
path: root/Doc/tools/getversioninfo
blob: d22c16ddc04562c3e5275b98d3ad3e585b5f877f (plain)
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
#! /usr/bin/env python

import os
import re
import sys

try:
    __file__
except NameError:
    __file__ = sys.argv[0]

tools = os.path.dirname(os.path.abspath(__file__))
Doc = os.path.dirname(tools)
src = os.path.dirname(Doc)
patchlevel_h = os.path.join(src, "Include", "patchlevel.h")

# This won't pick out all #defines, but it will pick up the ones we
# care about.
rx = re.compile(r"\s*#define\s+([a-zA-Z][a-zA-Z_0-9]*)\s+([a-zA-Z_0-9]+)")

d = {}
f = open(patchlevel_h)
for line in f:
    m = rx.match(line)
    if m is not None:
        name, value = m.group(1, 2)
        d[name] = value
f.close()

release = "%s.%s" % (d["PY_MAJOR_VERSION"], d["PY_MINOR_VERSION"])
micro = int(d["PY_MICRO_VERSION"])
shortversion = release
if micro != 0:
    release += "." + str(micro)
level = d["PY_RELEASE_LEVEL"]

suffixes = {
    "PY_RELEASE_LEVEL_ALPHA": "a",
    "PY_RELEASE_LEVEL_BETA":  "b",
    "PY_RELEASE_LEVEL_GAMMA": "c",
    }

releaseinfo = ""
if level != "PY_RELEASE_LEVEL_FINAL":
    releaseinfo = suffixes[level] + str(int(d["PY_RELEASE_SERIAL"]))

def write_file(name, text):
    """Write text to a file if the file doesn't exist or if text
    differs from any existing content."""
    if os.path.exists(name):
        f = open(name, "r")
        s = f.read()
        f.close()
        if s == text:
            return
    f = open(name, "w")
    f.write(text)
    f.close()

patchlevel_tex = os.path.join(Doc, "commontex", "patchlevel.tex")

write_file(patchlevel_tex,
           "%% This file is generated by ../tools/getversioninfo;\n"
           "%% do not edit manually.\n"
           "\n"
           "\\release{%s}\n"
           "\\setreleaseinfo{%s}\n"
           "\\setshortversion{%s}\n"
           % (release, releaseinfo, shortversion))

print release + releaseinfo