X-Git-Url: https://v.licheni.net/stack/cam.git/blobdiff_plain/de74ecfb399e9c18e476104744856fde67ea2e81..112c04e3926d62291efd902a1dcb0b2d24feeb59:/cam/openssl_wrap.py diff --git a/cam/openssl_wrap.py b/cam/openssl_wrap.py new file mode 100644 index 0000000..db44f26 --- /dev/null +++ b/cam/openssl_wrap.py @@ -0,0 +1,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)