<commit_before>import tempfile
import urllib2
import os
from StringIO import StringIO
from zipfile import ZipFile

import mongoengine

#from monitor import generate_manifest_paths, manifests_state, display_summary

class CodeRevision(mongoengine.Document):
    id = mongoengine.StringField(primary_key=True)
    tests_url = mongoengine.StringField(required=True)
    date = mongoengine.DateTimeField(required=True)

    def download_tests(self):
        """Downloads and unpacks tests.zip to a temporary folder,
        and returns the path to that folder"""
        extraction_path = tempfile.mkdtemp()

        # We download the zip and instantiate a ZipFile
        remote_zip = urllib2.urlopen(self.tests_url)
        zipstream = StringIO(remote_zip.read())
        zipfile = ZipFile(zipstream)

        # We create a new folder
        os.mkdir(extraction_path)

        # We unpack all files contained in the zip to the extraction folder
        for name in zipfile.namelist():
            zipfile.extract(name, extraction_path)

        return extraction_path

    def parse_manifests(self):
        pass

class ManifestsState(mongoengine.Document):
    revision = mongoengine.ReferenceField(CodeRevision, primary_key=True)
    active_tests_count = mongoengine.IntField(required=True)
    skipped_tests_count = mongoengine.IntField(required=True)
    manifest_states = mongoengine.DictField()

class TestSuiteState(mongoengine.Document):
    revision = mongoengine.ReferenceField(CodeRevision, primary_key=True)
    active_tests = mongoengine.ListField(required=True)
    skipped_tests = mongoengine.ListField(required=True)<commit_msg>Updated CodeRevision with a processed field and tempdir fix<commit_after>import tempfile
import urllib2
import os
from StringIO import StringIO
from zipfile import ZipFile

import mongoengine

#from monitor import generate_manifest_paths, manifests_state, display_summary

class CodeRevision(mongoengine.Document):
    id = mongoengine.StringField(primary_key=True)
    tests_url = mongoengine.StringField(required=True)
    date = mongoengine.DateTimeField(required=True)
    processed = mongoengine.BooleanField(default=False)

    def download_tests(self):
        """Downloads and unpacks tests.zip to a temporary folder,
        and returns the path to that folder"""
        # We get a temporary folder
        extraction_path = tempfile.mkdtemp()

        # We download the zip and instantiate a ZipFile
        remote_zip = urllib2.urlopen(self.tests_url)
        zipstream = StringIO(remote_zip.read())
        zipfile = ZipFile(zipstream)

        # We unpack all files contained in the zip to the extraction folder
        for name in zipfile.namelist():
            zipfile.extract(name, extraction_path)

        return extraction_path

    def parse_manifests(self):
        pass

class ManifestsState(mongoengine.Document):
    revision = mongoengine.ReferenceField(CodeRevision, primary_key=True)
    active_tests_count = mongoengine.IntField(required=True)
    skipped_tests_count = mongoengine.IntField(required=True)
    manifest_states = mongoengine.DictField()

class TestSuiteState(mongoengine.Document):
    revision = mongoengine.ReferenceField(CodeRevision, primary_key=True)
    active_tests = mongoengine.ListField(required=True)
    skipped_tests = mongoengine.ListField(required=True)
{'fraction_non_alphanumeric': 0.06912991656734208, 'fraction_numerical': 0.0011918951132300357, 'mean_word_length': 4.13302752293578, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5228859', 'n_tokens_mistral': 976, 'n_tokens_neox': 933, 'n_words': 232}