<commit_before>import docker

from logging import debug
import sys
import subprocess
import os

docker_client = None

def exists(exe):
    return any(os.access(os.path.join(path, exe), os.X_OK) for path in os.environ["PATH"].split(os.pathsep))

def is_linux():
    return sys.platform == 'linux' or sys.platform == 'linux2'

def run(cmd, cont=False):
    debug('Running command: ' + cmd)

    import shlex
    args = shlex.split(cmd)
    if cont:
        return subprocess.call(args, stdout=open(os.devnull, 'w'))
    else:
        return subprocess.check_output(args)

def docker_machine_run(cmd):
    if is_linux():
        return run(cmd)
    else:
        return run('docker-machine ssh YANS-machine ' + cmd)

def create_links(links):
    for lnk in links:
        docker_machine_run('sudo /usr/local/sbin/brctl addbr ' + lnk.bridge_name)
        docker_machine_run('sudo /usr/local/sbin/ip link set ' + lnk.bridge_name + ' up')

def destroy_links(links):
    for lnk in links:
        docker_machine_run('sudo /usr/local/sbin/ip link set ' + lnk.bridge_name + ' down')
        docker_machine_run('sudo /usr/local/sbin/brctl delbr ' + lnk.bridge_name)

def create_nodes(nodes):
    client().images.pull('kennethjiang/yans-node')
    for node in nodes:
        client().containers.run('kennethjiang/yans-node', name=node.container_name, command='sleep 3153600000', detach=True, privileged=True)

def destroy_nodes(nodes):
    dc = client()
    for node in nodes:
        try:
            dc.containers.get(node.container_name).remove(force=True)
        except docker.errors.NotFound:
            pass

def bind_interface(interface):
    docker_machine_run('sudo /usr/local/sbin/ip link add ' + interface.name + ' type veth peer name ' + interface.peer_name)
    docker_machine_run('sudo /usr/local/sbin/ip link set ' + interface.peer_name + ' up')
    docker_machine_run('sudo /usr/local/sbin/brctl addif ' + interface.link.bridge_name + ' ' + if_peer)
    container_pid = str(client().api.inspect_container(node)['State']['Pid'])
    docker_machine_run('sudo /usr/local/sbin/ip link set netns ' + container_pid + ' dev ' + if_name)

def ensure_docker_machine():
    if is_linux(): # docker machine not required on linux
        return
def ensure_docker_machine():
    if is_linux(): # docker machine not required on linux
        return
<commit_msg>minor bugs. basic flow works<commit_after>import docker

from logging import debug
import sys
import subprocess
import os

docker_client = None

def exists(exe):
    return any(os.access(os.path.join(path, exe), os.X_OK) for path in os.environ["PATH"].split(os.pathsep))

def is_linux():
    return sys.platform == 'linux' or sys.platform == 'linux2'

def run(cmd, cont=False):
    debug('Running command: ' + cmd)

    import shlex
    args = shlex.split(cmd)
    if cont:
        return subprocess.call(args, stdout=open(os.devnull, 'w'))
    else:
        return subprocess.check_output(args)

def docker_machine_run(cmd):
    if is_linux():
        return run(cmd)
    else:
        return run('docker-machine ssh YANS-machine ' + cmd)

def create_links(links):
    for lnk in links:
        docker_machine_run('sudo /usr/local/sbin/brctl addbr ' + lnk.bridge_name)
        docker_machine_run('sudo /usr/local/sbin/ip link set ' + lnk.bridge_name + ' up')

def destroy_links(links):
    for lnk in links:
        docker_machine_run('sudo /usr/local/sbin/ip link set ' + lnk.bridge_name + ' down')
        docker_machine_run('sudo /usr/local/sbin/brctl delbr ' + lnk.bridge_name)

def create_nodes(nodes):
    client().images.pull('kennethjiang/yans-node')
    for node in nodes:
        client().containers.run('kennethjiang/yans-node', name=node.container_name, command='sleep 3153600000', detach=True, privileged=True)

def destroy_nodes(nodes):
    dc = client()
    for node in nodes:
        try:
            dc.containers.get(node.container_name).remove(force=True)
        except docker.errors.NotFound:
            pass

def bind_interface(interface):
    docker_machine_run('sudo /usr/local/sbin/ip link add ' + interface.name + ' type veth peer name ' + interface.peer_name)
    docker_machine_run('sudo /usr/local/sbin/ip link set ' + interface.peer_name + ' up')
    docker_machine_run('sudo /usr/local/sbin/brctl addif ' + interface.link.bridge_name + ' ' + interface.peer_name)
    container_pid = str(client().api.inspect_container( interface.node.container_name )['State']['Pid'])
    docker_machine_run('sudo /usr/local/sbin/ip link set netns ' + container_pid + ' dev ' + interface.name)

def ensure_docker_machine():
    if is_linux(): # docker machine not required on linux
        return
def ensure_docker_machine():
    if is_linux(): # docker machine not required on linux
        return

{'fraction_non_alphanumeric': 0.12140910044034389, 'fraction_numerical': 0.004613126441602013, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 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': '2437145', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1535, 'n_words': 358}