<commit_before>from pecan import expose, redirect
import wsmeext.pecan as wsme_pecan
import pecan
from pecan import rest

import wsme.types as wtypes

from wsme.types import File


import zipfile
import tarfile

import glob
import os
import json
import uuid
import datetime
import shutil

from io import BytesIO
from joulupukki.controllers.v2.datamodel.build import Build, APIBuild
from joulupukki.controllers.v2.datamodel.user import User
from joulupukki.controllers.v2.datamodel.project import Project
from joulupukki.controllers.v2.datamodel.job import Job
from joulupukki.controllers.v2.jobs import JobsController


from joulupukki.lib.queues import build_tasks
from joulupukki.lib.distros import supported_distros, reverse_supported_distros


archive_types = {"zip": "application/zip",
                 "tgz": "application/x-gzip",
                }


class DownloadController(rest.RestController):
    # CURL -x GET http://127.0.0.1:8080/v2/titilambert/kaji/builds/6/download
    # CURL -x GET http://127.0.0.1:8080/v2/titilambert/kaji/builds/6/download?archive=tgz
    # CURL -x GET http://127.0.0.1:8080/v2/titilambert/kaji/builds/6/download?distro=debian_7
    @pecan.expose()
    def get(self):
        """Returns log of a specific distro."""
        project_name = pecan.request.context['project_name']
        user = User.fetch(pecan.request.context['username'])
        project = Project.fetch(user, project_name)
        build_id = pecan.request.context['build_id']
        if build_id in ["latest"]:
            build_id = project.get_latest_build()
        build = Build.fetch(project, build_id, full_data=True)
        # Get options
        archive = pecan.request.GET.get('archive', 'tgz')
        distro = pecan.request.GET.get('distro', None)
        if distro not in supported_distros:
            distro = None
        # Prepare content type
        content_type = archive_types.get(archive, 'application/x-gzip')
        pecan.core.override_template(None, content_type)
        # Get output folder
        output_folder = build.get_output_folder_path(distro)
        # Test if output folder exists
        if not os.path.isdir(output_folder):<commit_msg>Small fix when download an unknown build<commit_after>from pecan import expose, redirect
import wsmeext.pecan as wsme_pecan
import pecan
from pecan import rest

import wsme.types as wtypes

from wsme.types import File


import zipfile
import tarfile

import glob
import os
import json
import uuid
import datetime
import shutil

from io import BytesIO
from joulupukki.controllers.v2.datamodel.build import Build, APIBuild
from joulupukki.controllers.v2.datamodel.user import User
from joulupukki.controllers.v2.datamodel.project import Project
from joulupukki.controllers.v2.datamodel.job import Job
from joulupukki.controllers.v2.jobs import JobsController


from joulupukki.lib.queues import build_tasks
from joulupukki.lib.distros import supported_distros, reverse_supported_distros


archive_types = {"zip": "application/zip",
                 "tgz": "application/x-gzip",
                }


class DownloadController(rest.RestController):
    # CURL -x GET http://127.0.0.1:8080/v2/titilambert/kaji/builds/6/download
    # CURL -x GET http://127.0.0.1:8080/v2/titilambert/kaji/builds/6/download?archive=tgz
    # CURL -x GET http://127.0.0.1:8080/v2/titilambert/kaji/builds/6/download?distro=debian_7
    @pecan.expose()
    def get(self):
        """Returns log of a specific distro."""
        project_name = pecan.request.context['project_name']
        user = User.fetch(pecan.request.context['username'])
        project = Project.fetch(user, project_name)
        build_id = pecan.request.context['build_id']
        if build_id in ["latest"]:
            build_id = project.get_latest_build()
        build = Build.fetch(project, build_id, full_data=True)
        if build is None:
            return
        # Get options
        archive = pecan.request.GET.get('archive', 'tgz')
        distro = pecan.request.GET.get('distro', None)
        if distro not in supported_distros:
            distro = None
        # Prepare content type
        content_type = archive_types.get(archive, 'application/x-gzip')
        pecan.core.override_template(None, content_type)
        # Get output folder
        output_folder = build.get_output_folder_path(distro)
        # Test if output folder exists
        if not os.path.isdir(output_folder):
{'fraction_non_alphanumeric': 0.0955716222322639, 'fraction_numerical': 0.018978761861726163, 'mean_word_length': 3.2897286821705425, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6185538', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1404, 'n_words': 322}