<commit_before>import os

import shutil
from django.conf import settings
from django.core import serializers
from django.core.management.commands.loaddata import Command as LoaddataCommand
from django.db.models import FileField


class Command(LoaddataCommand):
    def handle(self, *fixture_labels, **options):
        super(Command, self).handle(*fixture_labels, **options)
        for fixture_label in fixture_labels:
            for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label):
                _, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file))
                open_method, mode = self.compression_formats[cmp_fmt]
                fixture = open_method(fixture_file, mode)
                objects = serializers.deserialize(ser_fmt, fixture, using=self.using, ignorenonexistent=self.ignore)
                for obj in list(objects):
                    self.process_object_from_fixture(obj.object, fixture_dir)

    def process_object_from_fixture(self, object_from_fixture, fixture_dir):
        fields = [field for field in type(object_from_fixture)._meta.get_fields() if isinstance(field, FileField)]
        for field in fields:
            relative_file_path = getattr(object_from_fixture, field.name).name
            src_path = os.path.join(fixture_dir, 'media', relative_file_path)
            if not os.path.exists(src_path):
                print "Source files %s doesn't exist. Skipping."
                continue

            target_path = os.path.join(settings.MEDIA_ROOT, relative_file_path)

            if not os.path.exists(os.path.dirname(target_path)):
                os.makedirs(os.path.dirname(target_path))

            if os.path.exists(target_path):
                os.remove(target_path)
            shutil.copy(src_path, target_path)<commit_msg>Fixed error formatting; empty values are skipped now<commit_after>import os

import shutil
from django.conf import settings
from django.core import serializers
from django.core.management.commands.loaddata import Command as LoaddataCommand
from django.db.models import FileField


class Command(LoaddataCommand):
    def handle(self, *fixture_labels, **options):
        super(Command, self).handle(*fixture_labels, **options)
        for fixture_label in fixture_labels:
            for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label):
                _, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file))
                open_method, mode = self.compression_formats[cmp_fmt]
                fixture = open_method(fixture_file, mode)
                objects = serializers.deserialize(ser_fmt, fixture, using=self.using, ignorenonexistent=self.ignore)
                for obj in list(objects):
                    self.process_object_from_fixture(obj.object, fixture_dir)

    def process_object_from_fixture(self, object_from_fixture, fixture_dir):
        fields = [field for field in type(object_from_fixture)._meta.get_fields() if isinstance(field, FileField)]
        for field in fields:
            relative_file_path = getattr(object_from_fixture, field.name).name
            if not relative_file_path:
                continue
            src_path = os.path.join(fixture_dir, 'media', relative_file_path)
            if not os.path.exists(src_path):
                print "Source files %s doesn't exist. Skipping." % src_path
                continue

            target_path = os.path.join(settings.MEDIA_ROOT, relative_file_path)

            if not os.path.exists(os.path.dirname(target_path)):
                os.makedirs(os.path.dirname(target_path))

            if os.path.exists(target_path):
                os.remove(target_path)
            shutil.copy(src_path, target_path)
{'fraction_non_alphanumeric': 0.08359872611464968, 'fraction_numerical': 0.0, 'mean_word_length': 2.8696098562628336, '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': '6983561', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1050, 'n_words': 227}