utils.py 1.44 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 25
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))
    return versions[tag]
Torsten Grote's avatar
Torsten Grote committed
26 27 28 29 30 31 32 33 34 35 36 37 38


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()
39 40


akwizgran's avatar
akwizgran committed
41 42 43 44
def get_tor_version(versions):
    return versions['tor'].split('-')[1]


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


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


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


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