indy-crypto 0.1.4-rc-2

This is the shared crypto libirary for Hyperledger Indy components.
Documentation
#!/usr/bin/env python3

import logging
import argparse
import re
import sys
from upload_debs import add_deb_to_repo, connect_to_remote, reset_cache
from plumbum.path import RemotePath


PACKAGE_ROOT = '/var/repository/repos/lib/apt/xenial/'
PACKAGE_PATH_TEMPLATE = PACKAGE_ROOT + '{}/python3-{}_{}_amd64.deb'
PRIMARY_PACKAGE_PATH_TEMPLATE = PACKAGE_ROOT + '{}/{}_{}_amd64.deb'
FALLBACK_COMPONENT='master-latest'

PACKAGES_WOUT_PREFIX = [
    'indy-node',
    'indy-plenum',
    'sovrin',
    'indy-anoncreds',
    'libindy-crypto',
    'libindy-crypto-dev',
    'libindy',
    'libindy-dev'
]
SOVRIN_DEPS = ['indy-node', 'sovrin']


def copy_file(rem, component, filename, dependency):
    add_deb_to_repo(rem, filename, component)
    logging.info("%s copied to the repo %s", filename, rem)


def main(dependencies, component, original_component, copy_unlisted):
    dependencies = [dependency.split('=') for dependency in dependencies]

    rem = connect_to_remote()

    for dependency in dependencies:
        logging.debug("Processing {}=={}".format(dependency[0], dependency[1]))
        if dependency[1] == 'null':
            continue
        path_template = PACKAGE_PATH_TEMPLATE
        if dependency[0] in PACKAGES_WOUT_PREFIX:
            path_template = PRIMARY_PACKAGE_PATH_TEMPLATE
        filename = path_template.format(original_component, dependency[0], dependency[1])
        try:
            copy_file(rem, component, filename, dependency[0])
        except Exception as e:
            if ((original_component.find('stable') == -1) and (original_component.find('master') == -1) and (original_component.find('rc') == -1)):
                filename = path_template.format(FALLBACK_COMPONENT, dependency[0], dependency[1])
                copy_file(rem, component, filename, dependency[0])
            else:
                raise e

    if copy_unlisted:
        original_component_dir = PACKAGE_ROOT + original_component
        path = RemotePath(rem, original_component_dir)
        files = [file for file in path.list() if not next((dep for dep in dependencies if file.name.find(dep[0]) != -1), None)]
        for file in files:
            add_deb_to_repo(rem, file, component)
            logging.info("%s copied to the repo %s", file, rem)

    reset_cache([rem])

    logging.info("All debs added")


if __name__ == '__main__':
    FORMAT = '%(asctime)-15s [%(name)-15s] %(levelname)-8s %(message)s'
    logging.basicConfig(format=FORMAT, level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('--deps', action='store_true')
    parser.add_argument('component')
    parser.add_argument('component_src')
    parser.add_argument('dependencies', nargs='+')
    args = vars(parser.parse_args())
    main(args['dependencies'], args['component'], args['component_src'], args['deps'])