<commit_before>from __future__ import absolute_import

from celery import shared_task

from documents.models import Document
import clamd


@shared_task
def compile_tex(document_id):
    document = Document.objects.get(pk=document_id)
    print(document)


@shared_task
def check_clamav(document_id):
    document = Document.objects.get(pk=document_id)
    clam = clamd.ClamdUnixSocket(settings.CLAMAV_SOCKET)
    status, sig = clam.scan(absolute_path_to_pdf)[absolute_path_to_pdf]
    if status == 'OK':
        document.isClean = True
    elif status == 'FOUND':
        document.isClean = False
        print("Signature found", sig)
    else:
        # unknown state
       document.isClean = False
       print("Unknown return of clamav", status, sig)

    document.save()


<commit_msg>Subprocess call to run compilation command<commit_after>from __future__ import absolute_import

from celery import shared_task

from documents.models import Document
from django.conf import settings
import clamd
import os
import subprocess


@shared_task
def compile_tex(document_id):
    script = os.path.join(settings.BASE_DIR, '../scripts', 'jailifier.sh')
    document = Document.objects.get(pk=document_id)
    command = ["sh", script, document.id, document.zipFile.path]
    subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1800, check=True)


@shared_task
def check_clamav(document_id):
    document = Document.objects.get(pk=document_id)
    clam = clamd.ClamdUnixSocket(settings.CLAMAV_SOCKET)
    status, sig = clam.scan(absolute_path_to_pdf)[absolute_path_to_pdf]
    if status == 'OK':
        document.isClean = True
    elif status == 'FOUND':
        document.isClean = False
        print("Signature found", sig)
    else:
        # unknown state
       document.isClean = False
       print("Unknown return of clamav", status, sig)

    document.save()



{'fraction_non_alphanumeric': 0.0945089757127772, 'fraction_numerical': 0.0021119324181626186, 'mean_word_length': 3.896640826873385, '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': '1523483', 'n_tokens_mistral': 589, 'n_tokens_neox': 570, 'n_words': 136}