openssl_wrap.py 598 Bytes
Newer Older
ale's avatar
ale committed
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
import logging
import subprocess

log = logging.getLogger(__name__)


class CommandError(Exception):
    pass


def run(*args):
    cmd = ['openssl']
    cmd.extend(args)
    log.debug('executing "%s"' % ' '.join(cmd))
    pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    stdout, _ = pipe.communicate()
    if pipe.returncode != 0:
        raise CommandError('openssl exited with status %d' % (
                pipe.returncode,))
    return stdout


def run_with_config(config_file, *args):
    cmd = args[0]
    args = args[1:]
    return run(cmd, '-config', config_file, '-batch', *args)