diff options
author | Tomás Touceda <chiiph@leap.se> | 2014-06-27 12:47:57 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2014-06-27 12:47:57 -0300 |
commit | 7858d83af4a09ab00f6ba33dd8dbcf07ade101ce (patch) | |
tree | 334e519a4d341c402b5fa81d339b9b1d2b5ead35 /setup.py | |
parent | c621fa7322b4f8151eb37b27f8aeae563cf6bd63 (diff) | |
parent | 7de085576dd6141a5303aa1e1460c2a208d7b5d4 (diff) |
Merge branch 'release-0.5.3'0.5.3
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 61 |
1 files changed, 60 insertions, 1 deletions
@@ -20,7 +20,9 @@ Setup file for bitmask. """ from __future__ import print_function +import hashlib import sys +import os import re if not sys.version_info[0] == 2: @@ -34,7 +36,6 @@ except ImportError: from pkg import distribute_setup distribute_setup.use_setuptools() from setuptools import setup, find_packages -import os from pkg import utils @@ -168,6 +169,64 @@ class cmd_develop(_develop): cmdclass["develop"] = cmd_develop + +class cmd_binary_hash(Command): + """ + Update the _binaries.py file with hashes for the different helpers. + This is used from within the bundle. + """ + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self, *args): + + OPENVPN_BIN = os.environ.get('OPENVPN_BIN', None) + BITMASK_ROOT = os.environ.get('BITMASK_ROOT', None) + + def exit(): + print("Please set environment variables " + "OPENVPN_BIN and BITMASK_ROOT pointing to the right path " + "to use this command") + sys.exit(1) + + bin_paths = OPENVPN_BIN, BITMASK_ROOT + if not all(bin_paths): + exit() + + if not all(map(os.path.isfile, bin_paths)): + exit() + + openvpn_bin_hash, bitmask_root_hash = map( + lambda path: hashlib.sha256(open(path).read()).hexdigest(), + bin_paths) + + template = r""" +# Hashes for binaries used in Bitmask Bundle. +# This file has been automatically generated by `setup.py hash_binaries` +# DO NOT modify it manually. + +OPENVPN_BIN = "{openvpn}" +BITMASK_ROOT = "{bitmask}" +""" + subst_template = template.format( + openvpn=openvpn_bin_hash, + bitmask=bitmask_root_hash) + + bin_hash_path = os.path.join('src', 'leap', 'bitmask', '_binaries.py') + with open(bin_hash_path, 'w') as f: + f.write(subst_template) + print("Binaries hash file %s has been updated!" % (bin_hash_path,)) + + +cmdclass["hash_binaries"] = cmd_binary_hash + + # next two classes need to augment the versioneer modified ones versioneer_build = cmdclass['build'] |