<commit_before>#!/usr/bin/env python

import os
from shipper import Shipper, run, command
import subprocess

# DOCKER_URL = "/var/run/docker.sock"
DOCKER_HOST = "localhost:4243"
DOCKER_URL = "tcp://127.0.0.1:4243"
s = Shipper([DOCKER_HOST])

def pmk(t):
    rootdir = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
    return os.path.join(rootdir, t)


def splitimage(name):
    return name.split(':', 1)


@command
def cleanup_containers():
    try:
      subprocess.check_call("docker -H {} ps -a -q | grep ''", shell=True).format(DOCKER_URL)
    except subprocess.CalledProcessError, e:
      s.log.debug("No docker containers found, skipping cleanup")
    else:
      cmd = "docker -H={} rm `docker -H {} ps -a -q`".format(DOCKER_URL, DOCKER_URL)
      s.log.debug("About to execute: {}".format(cmd))
      subprocess.check_output(cmd, shell=True)


@command
def cleanup_images():
    try:
      subprocess.check_call("docker -H {} images -q | grep ''", shell=True).format(DOCKER_URL)
    except subprocess.CalledProcessError, e:
      s.log.debug("No docker images found, skipping cleanup")
    else:
      cmd = "docker -H={} rmi `docker -H {} images -q`".format(DOCKER_URL, DOCKER_URL)
      s.log.debug("About to execute: {}".format(cmd))
      subprocess.check_output(cmd, shell=True)


@command
def precise(stamp):
    s.build(
        tag="precise-with-updates:{}".format(stamp),
        path=pmk("precise"))


@command
def export(image, exportto):
    container = s.run(image, "/bin/bash")[0]
    cmd = "docker -H={} export {} | gzip > {}".format(DOCKER_URL, container.id, exportto)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)
    s.stop(container)


@command
def flatten(image):
    repo, tag = splitimage(image)
    container = s.run(image, "/bin/bash")[0]

    cmd = "docker -H={} export {} > /tmp/{}.tar".format(DOCKER_URL, container.id, container.id)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)

    s.stop(container)

    cmd = "cat /tmp/{}.tar | docker -H=tcp://127.0.0.1:4243 import - {} {}".format(container.id, repo, tag)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)

    cmd = "rm -f /tmp/{}.tar".format(container.id)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)


@command
def retag(image, newname):<commit_msg>fix(parameter): Parameterize DOCKER_URL in this command<commit_after>#!/usr/bin/env python

import os
from shipper import Shipper, run, command
import subprocess

# DOCKER_URL = "/var/run/docker.sock"
DOCKER_HOST = "localhost:4243"
DOCKER_URL = "tcp://127.0.0.1:4243"
s = Shipper([DOCKER_HOST])

def pmk(t):
    rootdir = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
    return os.path.join(rootdir, t)


def splitimage(name):
    return name.split(':', 1)


@command
def cleanup_containers():
    try:
      subprocess.check_call("docker -H {} ps -a -q | grep ''", shell=True).format(DOCKER_URL)
    except subprocess.CalledProcessError, e:
      s.log.debug("No docker containers found, skipping cleanup")
    else:
      cmd = "docker -H={} rm `docker -H {} ps -a -q`".format(DOCKER_URL, DOCKER_URL)
      s.log.debug("About to execute: {}".format(cmd))
      subprocess.check_output(cmd, shell=True)


@command
def cleanup_images():
    try:
      subprocess.check_call("docker -H {} images -q | grep ''", shell=True).format(DOCKER_URL)
    except subprocess.CalledProcessError, e:
      s.log.debug("No docker images found, skipping cleanup")
    else:
      cmd = "docker -H={} rmi `docker -H {} images -q`".format(DOCKER_URL, DOCKER_URL)
      s.log.debug("About to execute: {}".format(cmd))
      subprocess.check_output(cmd, shell=True)


@command
def precise(stamp):
    s.build(
        tag="precise-with-updates:{}".format(stamp),
        path=pmk("precise"))


@command
def export(image, exportto):
    container = s.run(image, "/bin/bash")[0]
    cmd = "docker -H={} export {} | gzip > {}".format(DOCKER_URL, container.id, exportto)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)
    s.stop(container)


@command
def flatten(image):
    repo, tag = splitimage(image)
    container = s.run(image, "/bin/bash")[0]

    cmd = "docker -H={} export {} > /tmp/{}.tar".format(DOCKER_URL, container.id, container.id)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)

    s.stop(container)

    cmd = "cat /tmp/{}.tar | docker -H={} import - {} {}".format(container.id, DOCKER_URL, repo, tag)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)

    cmd = "rm -f /tmp/{}.tar".format(container.id)
    s.log.debug("About to execute: {}".format(cmd))
    subprocess.check_output(cmd, shell=True)


@command
def retag(image, newname):
{'fraction_non_alphanumeric': 0.1714458804523425, 'fraction_numerical': 0.008885298869143781, 'mean_word_length': 3.6814744801512287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '3571030', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1764, 'n_words': 373}