File: mumble-version.py

package info (click to toggle)
mumble 1.5.735-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 90,008 kB
  • sloc: cpp: 556,921; ansic: 81,662; python: 3,606; sh: 659; makefile: 506; asm: 371; cs: 306; sql: 228; javascript: 143; perl: 80; xml: 13
file content (70 lines) | stat: -rwxr-xr-x 2,087 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
#!/usr/bin/env python3
#
# Copyright 2019-2023 The Mumble Developers. All rights reserved.
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.
#
# This script reads and prints the current Mumble version

from __future__ import (unicode_literals, print_function, division)

import argparse
import os
import platform
import subprocess
import sys

def strip(s):
    s = s.replace('\r', '')
    s = s.replace('\n', '')
    return s

def cmd(args):
    shell = platform.system() == 'Windows'
    p = subprocess.Popen(args, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = p.communicate()
    if p.returncode != 0:
        raise Exception('cmd(): {0} failed with status {1}: {2}'.format(args, p.returncode, stderr))
    return stdout.decode('utf-8')

# Reads the version from CMakeLists.txt
def readProjectVersion():
    sourceTreeRoot = strip(cmd(['git', 'rev-parse', '--show-toplevel']))

    version = None
    with open(os.path.join(sourceTreeRoot, 'CMakeLists.txt'), 'r') as f:
        for line in f:
            # The version is specified as e.g. VERSION "1.4.0.${BUILD_NUMBER}"
            if 'VERSION "' in line and '.${BUILD_NUMBER}"' in line:
                line = line.replace('VERSION "', '')
                line = line[0 : line.find('.${BUILD_NUMBER}"')].strip()
                version = line
                break

    if version is None:
        raise Exception('Unable to read version from CMakeLists.txt')

    if len(version) == 0 or not '.' in version:
            raise Exception('Bad version: "{0}"'.format(version))

    return version

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-n', '--newline', action = "store_true", help = 'Break line after printing version')
    args = parser.parse_args()

    if args.newline:
        end = None
    else:
        end = ''

    version = readProjectVersion()

    print(version, end = end)



if __name__ == '__main__':
    main()