Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mumble-build-number.py « scripts - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 006bbfb08fdee1d118c883cc3b89c1bcbf55875a (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
#!/usr/bin/env python3
#
# Copyright 2022 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 fetches the build number for a given commit

import argparse
import urllib.request
import sys

def fetch_build_number(commit = None, version = None, password = None):
    if commit is None or version is None:
        return None

    query = "https://mumble.info/get-build-number?commit=" + commit + "&version=" + version

    if not password is None:
        query += "&token=" + password

    try:
        request = urllib.request.urlopen(query)
        answer = request.read().decode("utf-8")

        return int(answer)
    except urllib.error.HTTPError:
        # The request failed
        return None

def main():
    parser = argparse.ArgumentParser("This script will fetch the build number for the given commit hash")
    parser.add_argument("--commit", help="The hash of the commit to fetch the build number for", metavar="HASH", required=True)
    parser.add_argument("--version", help="The Mumble version the given commit belongs to (e.g. 1.4)", metavar="VERSION", required=True)
    parser.add_argument("--password", help="The password to use in order to gain write access on the server")
    parser.add_argument("--default", help="The default build number to use, in case none can be fetched. Note that this will cause this script to\
            always succeed.", type=int)
    args = parser.parse_args()

    if not args.password is None and args.password.strip() == "":
        # An empty password is considered to be no password at all
        args.password = None

    buildNumber = fetch_build_number(commit = args.commit, version = args.version, password = args.password)

    if buildNumber is None and not args.default is None:
        buildNumber = args.default

    if buildNumber is None:
        print("[ERROR]: Failed to fetch the build number for commit " + args.commit + " in Mumble v" + args.version, file=sys.stderr)

        sys.exit(1)
    else:
        print(buildNumber)
        sys.exit(0)


if __name__ == "__main__":
    main()