<commit_before>import os
from pecan import expose
from datetime import datetime

from mariner.models import Task
from mariner.controllers import error


class TaskController(object):

    def __init__(self, task_id):
        self.task = Task.query.filter_by(identifier=task_id).first()
        if not self.task:
            error('/errors/not_found/', '%s task was not found' % task_id)

    def read_log(self, path):
        if not path:
            return ''
        if not os.path.exists(path) or not os.path.isfile(path):
            return ''
        with open(path, 'r') as log_file:
            return log_file.read()

    @expose(generic=True, template='json')
    def completed(self):
        error('/errors/not_allowed/')

    @completed.when(method='POST', template='json')
    def completed_post(self):
        # XXX We should probably not assume that this is a one-off request and
        # that for some reason we might get hit again, in which case the files
        # may not exist and we would be wiping off information and overwriting
        # the ended time stamp
        self.task.ended = datetime.utcnow()
        self.task.stdout = self.read_log(self.task.stdout_file)<commit_msg>task should error like the doc says it should<commit_after>import os
from pecan import expose
from datetime import datetime

from mariner.models import Task
from mariner.controllers import error


class TaskController(object):

    def __init__(self, task_id):
        self.task = Task.query.filter_by(identifier=task_id).first()
        if not self.task:
            error('/errors/not_found/', '%s is not avilable' % task_id)

    def read_log(self, path):
        if not path:
            return ''
        if not os.path.exists(path) or not os.path.isfile(path):
            return ''
        with open(path, 'r') as log_file:
            return log_file.read()

    @expose(generic=True, template='json')
    def completed(self):
        error('/errors/not_allowed/')

    @completed.when(method='POST', template='json')
    def completed_post(self):
        # XXX We should probably not assume that this is a one-off request and
        # that for some reason we might get hit again, in which case the files
        # may not exist and we would be wiping off information and overwriting
        # the ended time stamp
        self.task.ended = datetime.utcnow()
        self.task.stdout = self.read_log(self.task.stdout_file)
{'fraction_non_alphanumeric': 0.09453349773941636, 'fraction_numerical': 0.0, 'mean_word_length': 2.7103658536585367, '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': '4094323', 'n_tokens_mistral': 694, 'n_tokens_neox': 678, 'n_words': 230}