<commit_before>#!/usr/bin/python
import sys
import json
import shlex
from subprocess import Popen, PIPE


def _execute(cmd):
    return Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE).communicate()


def _build_cmd(source_path, name, version, force, exposed_ports):
    good_mounts = ['bin', 'etc', 'home', 'lib', 'lib64', 'media',
                   'opt', 'root', 'sbin', 'srv', 'usr', 'var']

    if force:
        _execute('sudo docker rm -f {}'.format(name))

    cmd = 'sudo docker create --restart always -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro'

    for mount in good_mounts:
        cmd += ' -v {d}/{m}:/{m}:Z'.format(d=source_path, m=mount)

    for port in exposed_ports:
        if not port.get('exposed_port'):
            cmd += ' -p {:d}/{p}'.format(port['port'], p=port['protocol'])
        else:
            cmd += ' -p {:d}:{:d}/{p}'.format(port['exposed_port'], port['port'], p=port['protocol'])

    cmd += ' --name ' + name + ' leapp/leapp-scratch:' + version + ' /.leapp/leapp-init'

    return cmd


if __name__ == "__main__":
    cmd = _build_cmd(json.loads(sys.argv[1])['value'],
                     json.loads(sys.argv[2])['value'],
                     json.loads(sys.argv[3])["version"].split(".")[0],
                     json.loads(sys.argv[5])['value'],
                     json.loads(sys.argv[4])['ports'])

    out, err = _execute(cmd)
    outputs = {
        'container_id': dict(value=out),
        'error': dict(value=err)
    }
    print(json.dumps(outputs))<commit_msg>create_container: Report failure if there was an error<commit_after>#!/usr/bin/python
import sys
import json
import shlex
from subprocess import Popen, PIPE


def _execute(cmd):
    return Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE).communicate()


def _build_cmd(source_path, name, version, force, exposed_ports):
    good_mounts = ['bin', 'etc', 'home', 'lib', 'lib64', 'media',
                   'opt', 'root', 'sbin', 'srv', 'usr', 'var']

    if force:
        _execute('sudo docker rm -f {}'.format(name))

    cmd = 'sudo docker create --restart always -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro'

    for mount in good_mounts:
        cmd += ' -v {d}/{m}:/{m}:Z'.format(d=source_path, m=mount)

    for port in exposed_ports:
        if not port.get('exposed_port'):
            cmd += ' -p {:d}/{p}'.format(port['port'], p=port['protocol'])
        else:
            cmd += ' -p {:d}:{:d}/{p}'.format(port['exposed_port'], port['port'], p=port['protocol'])

    cmd += ' --name ' + name + ' leapp/leapp-scratch:' + version + ' /.leapp/leapp-init'

    return cmd


if __name__ == "__main__":
    cmd = _build_cmd(json.loads(sys.argv[1])['value'],
                     json.loads(sys.argv[2])['value'],
                     json.loads(sys.argv[3])["version"].split(".")[0],
                     json.loads(sys.argv[5])['value'],
                     json.loads(sys.argv[4])['ports'])

    out, err = _execute(cmd)
    outputs = {
        'container_id': dict(value=out),
        'error': dict(value=err)
    }
    print(json.dumps(outputs))
    if err:
        sys.exit(1)
{'fraction_non_alphanumeric': 0.19418416801292407, 'fraction_numerical': 0.005492730210016155, 'mean_word_length': 2.6252927400468384, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4436027', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1063, 'n_words': 217}