<commit_before>from flask import Flask, Response, render_template, redirect, url_for
from docker import Client
from docker.utils import kwargs_from_env, create_host_config

import config
from util import pretty_json


app = Flask(__name__)
app.debug = True
doc = Client(**kwargs_from_env())
host_config = create_host_config(
    publish_all_ports=True,
)


@app.route('/all')
def all_containers():
    containers = doc.containers(trunc=True, all=True)
    return render_template('containers.html', containers=containers)


@app.route('/')
def containers():
    containers = doc.containers(trunc=True)
    return render_template('containers.html', containers=containers)


@app.route('/container/<cont_id>/start')
def start(cont_id):
    doc.start(container=cont_id)
    return redirect(url_for('containers'))


@app.route('/container/<cont_id>/login')
def login(cont_id):
    inspect = doc.inspect_container(container=cont_id)
    ext_port = list(inspect['NetworkSettings']['Ports'].values())[0][0]
    return redirect('http://{HostIp}:{HostPort}'.format(**ext_port))


@app.route('/pull')
def pull():
    def gen():
        yield b'Pulling image. Please wait! (streaming)\n'
        for line in doc.pull(config.repo, stream=True):
            yield pretty_json(line)
    return Response(gen())


@app.route('/new')
def new():
    doc.create_container(image=config.image, host_config=host_config)
    return redirect(url_for('containers'))


if __name__ == '__main__':
    app.run()
<commit_msg>Replace deprecated utils.create_host_config<commit_after>from flask import Flask, Response, render_template, redirect, url_for
from docker import Client
from docker.utils import kwargs_from_env

import config
from util import pretty_json


app = Flask(__name__)
app.debug = True
doc = Client(**kwargs_from_env())
host_config = doc.create_host_config(
    publish_all_ports=True,
)


@app.route('/all')
def all_containers():
    containers = doc.containers(trunc=True, all=True)
    return render_template('containers.html', containers=containers)


@app.route('/')
def containers():
    containers = doc.containers(trunc=True)
    return render_template('containers.html', containers=containers)


@app.route('/container/<cont_id>/start')
def start(cont_id):
    doc.start(container=cont_id)
    return redirect(url_for('containers'))


@app.route('/container/<cont_id>/login')
def login(cont_id):
    inspect = doc.inspect_container(container=cont_id)
    ext_port = list(inspect['NetworkSettings']['Ports'].values())[0][0]
    return redirect('http://{HostIp}:{HostPort}'.format(**ext_port))


@app.route('/pull')
def pull():
    def gen():
        yield b'Pulling image. Please wait! (streaming)\n'
        for line in doc.pull(config.repo, stream=True):
            yield pretty_json(line)
    return Response(gen())


@app.route('/new')
def new():
    doc.create_container(image=config.image, host_config=host_config)
    return redirect(url_for('containers'))


if __name__ == '__main__':
    app.run()

{'fraction_non_alphanumeric': 0.14280958721704395, 'fraction_numerical': 0.0013315579227696406, 'mean_word_length': 5.082995951417004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1123432', 'n_tokens_mistral': 976, 'n_tokens_neox': 951, 'n_words': 191}