<commit_before># Copyright 2013 <NAME> and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import csrf_exempt
from django.utils.translation import ugettext as _
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.db.models import Q
from django.utils.html import strip_tags
from django.core import serializers
from django.shortcuts import render_to_response
from containers.models import Host, Container
from django.template import RequestContext
from containers.forms import (CreateContainerForm,
    ImportRepositoryForm, ImageBuildForm)
from shipyard import utils
from docker import client
import urllib
import random
import json
import tempfile

def handle_upload(f):
    tmp_file = tempfile.mktemp()
    with open(tmp_file, 'w') as d:
        for c in f.chunks():
            d.write(c)
    return tmp_file

@login_required
def index(request):
    hosts = Host.objects.filter(enabled=True)
    show_all = True if request.GET.has_key('showall') else False
    containers = None
    # load containers
    if hosts:
        c_ids = []
        for h in hosts:
            for c in h.get_containers(show_all=show_all):
                c_ids.append(utils.get_short_id(c.get('Id')))
        # return metadata objects
        containers = Container.objects.filter(container_id__in=c_ids).filter(
            Q(owner=None) | Q(owner=request.user))
    ctx = {
        'hosts': hosts,
        'containers': containers,
        'show_all': show_all,
    }
    return render_to_response('containers/index.html', ctx,
        context_instance=RequestContext(request))

@login_required
def container_details(request, container_id=None):
    c = Container.objects.get(container_id=container_id)
    ctx = {
        'container': c,
    }
    return render_to_response('containers/container_details.html', ctx,
        context_instance=RequestContext(request))

@login_required
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            if command.strip() == '':
                command = None
            if environment.strip() == '':
                environment = None
            else:
                environment = environment.split()
            if memory.strip() == '':
                memory = 0
            # build volumes
            binds = None
            if volume == '':
                volume = None
            if volume:
                if volume.find(':') > -1:
                    mnt, vol = volume.split(':')
                    volume = { mnt: {}}
                    binds = { vol: mnt }
                else:
                    volume = { volume: {}}
            # convert memory from MB to bytes
            if memory:
                memory = int(memory) * 1048576
            ports = form.data.get('ports', '').split()<commit_msg>fixed bug with binds<commit_after># Copyright 2013 <NAME> and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import csrf_exempt
from django.utils.translation import ugettext as _
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.db.models import Q
from django.utils.html import strip_tags
from django.core import serializers
from django.shortcuts import render_to_response
from containers.models import Host, Container
from django.template import RequestContext
from containers.forms import (CreateContainerForm,
    ImportRepositoryForm, ImageBuildForm)
from shipyard import utils
from docker import client
import urllib
import random
import json
import tempfile

def handle_upload(f):
    tmp_file = tempfile.mktemp()
    with open(tmp_file, 'w') as d:
        for c in f.chunks():
            d.write(c)
    return tmp_file

@login_required
def index(request):
    hosts = Host.objects.filter(enabled=True)
    show_all = True if request.GET.has_key('showall') else False
    containers = None
    # load containers
    if hosts:
        c_ids = []
        for h in hosts:
            for c in h.get_containers(show_all=show_all):
                c_ids.append(utils.get_short_id(c.get('Id')))
        # return metadata objects
        containers = Container.objects.filter(container_id__in=c_ids).filter(
            Q(owner=None) | Q(owner=request.user))
    ctx = {
        'hosts': hosts,
        'containers': containers,
        'show_all': show_all,
    }
    return render_to_response('containers/index.html', ctx,
        context_instance=RequestContext(request))

@login_required
def container_details(request, container_id=None):
    c = Container.objects.get(container_id=container_id)
    ctx = {
        'container': c,
    }
    return render_to_response('containers/container_details.html', ctx,
        context_instance=RequestContext(request))

@login_required
def create_container(request):
    form = CreateContainerForm()
    if request.method == 'POST':
        # save
        form = CreateContainerForm(request.POST)
        if form.is_valid():
            image = form.data.get('image')
            environment = form.data.get('environment')
            command = form.data.get('command')
            memory = form.data.get('memory', 0)
            volume = form.data.get('volume')
            volumes_from = form.data.get('volumes_from')
            if command.strip() == '':
                command = None
            if environment.strip() == '':
                environment = None
            else:
                environment = environment.split()
            if memory.strip() == '':
                memory = 0
            # build volumes
            binds = None
            if volume == '':
                volume = None
            if volume:
                if volume.find(':') > -1:
                    mnt, vol = volume.split(':')
                    volume = { vol: {}}
                    binds = { mnt: vol }
                else:
                    volume = { volume: {}}
            # convert memory from MB to bytes
            if memory:
                memory = int(memory) * 1048576
            ports = form.data.get('ports', '').split()
{'fraction_non_alphanumeric': 0.0923193340900492, 'fraction_numerical': 0.004540295119182747, 'mean_word_length': 2.5213143872113677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7015127', 'n_tokens_mistral': 2146, 'n_tokens_neox': 2094, 'n_words': 636}