utils.py 1.46 KB
Newer Older
Torsten Grote's avatar
Torsten Grote committed
1 2 3
#!/usr/bin/env python3

import hashlib
4
import json
Torsten Grote's avatar
Torsten Grote committed
5
import sys
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
from collections import OrderedDict

REPO_DIR = 'tor-android'


def get_version():
    if len(sys.argv) > 2:
        fail("Usage: %s [Tor version tag]" % sys.argv[0])
    return sys.argv[1] if len(sys.argv) > 1 else None


def get_build_versions(tag):
    # load Tor versions and their dependencies
    with open('tor-versions.json', 'r') as f:
        versions = json.load(f, object_pairs_hook=OrderedDict)

    if tag is None:
        # take top-most Tor version
        tag = next(iter(versions))
25
    versions[tag]['tag'] = tag
26
    return versions[tag]
Torsten Grote's avatar
Torsten Grote committed
27 28 29 30 31 32 33 34 35 36 37 38 39


def fail(msg=""):
    sys.stderr.write("Error: %s\n" % msg)
    sys.exit(1)


def get_sha256(filename, block_size=65536):
    sha256 = hashlib.sha256()
    with open(filename, 'rb') as f:
        for block in iter(lambda: f.read(block_size), b''):
            sha256.update(block)
    return sha256.hexdigest()
40 41


42 43
def get_version_tag(versions):
    return versions['tag']
akwizgran's avatar
akwizgran committed
44 45


46
def get_file_suffix(versions, android=False):
47
    version = get_version_tag(versions)
48
    return "%s-%s" % ("android", version) if android else version
49 50


51 52
def get_final_file_name(versions, android=False):
    return 'tor-%s.zip' % get_file_suffix(versions, android)
akwizgran's avatar
akwizgran committed
53 54


55 56
def get_sources_file_name(versions, android=False):
    return 'tor-%s-sources.jar' % get_file_suffix(versions, android)
akwizgran's avatar
akwizgran committed
57 58


59 60
def get_pom_file_name(versions, android=False):
    return 'tor-%s.pom' % get_file_suffix(versions, android)