<commit_before>### -*- coding: utf-8 -*- ####################################################
from optparse import make_option

from django.core.management.base import BaseCommand
from django.db.models import get_app, get_model, FieldDoesNotExist

SIMILARS_LENGTH = 40

class Command(BaseCommand):
    '''Calculates similar albums for each album in database'''
    args = ''
    help = 'Returns missing or empty track files from the SoftLayer'
    option_list = BaseCommand.option_list + (
        make_option('--app',
                    dest='app',
                    help='Django application to get models from. Example: myApp'),
        make_option('--models',
                    dest='models',
                    help='Model names list. Example: User,Album,Track'),
        make_option('--fields',
                    dest='fields',
                    help='File fields list. Example: file,image,audio_track'),
    )


    def handle(self, app, models, fields, *args, **options):
        self.index = 1
        if not app:
            raise Exception('You must specify --app option')
        if not models:
            raise Exception('You must specify --models option')
        if not fields:
            raise Exception('You must specify --fields option')

        def printTrack(obj, reason):
            print "%s. Instance: %s\n\tID: %s\n\tReason: %s" % \
                  (self.index, unicode(obj), obj.pk, reason)
            self.index += 1

        def get_missing_files(model, field_name):
            print '\t-------------Searching missing or incomplete %ss in %s:------------\n' % \
                  (field_name, model.__name__)
            for obj in model.objects.all():
                try:
                    if getattr(obj, field_name).file.size == 0:
                        printTrack(obj, 'Size is 0')
                except:
                    printTrack(obj, 'FILE NOT FOUND')
            print '\t------------Done-------------'

        model_names = models.split(',')
        field_names = fields.split(',')<commit_msg>changed exception class<commit_after>### -*- coding: utf-8 -*- ####################################################
from optparse import make_option

from django.core.management.base import BaseCommand, CommandError
from django.db.models import get_app, get_model, FieldDoesNotExist

SIMILARS_LENGTH = 40

class Command(BaseCommand):
    '''Calculates similar albums for each album in database'''
    args = ''
    help = 'Returns missing or empty track files from the SoftLayer'
    option_list = BaseCommand.option_list + (
        make_option('--app',
                    dest='app',
                    help='Django application to get models from. Example: myApp'),
        make_option('--models',
                    dest='models',
                    help='Model names list. Example: User,Album,Track'),
        make_option('--fields',
                    dest='fields',
                    help='File fields list. Example: file,image,audio_track'),
    )


    def handle(self, app, models, fields, *args, **options):
        self.index = 1
        if not app:
            raise CommandError('You must specify --app option')
        if not models:
            raise CommandError('You must specify --models option')
        if not fields:
            raise CommandError('You must specify --fields option')

        def printTrack(obj, reason):
            print "%s. Instance: %s\n\tID: %s\n\tReason: %s" % \
                  (self.index, unicode(obj), obj.pk, reason)
            self.index += 1

        def get_missing_files(model, field_name):
            print '\t-------------Searching missing or incomplete %ss in %s:------------\n' % \
                  (field_name, model.__name__)
            for obj in model.objects.all():
                try:
                    if getattr(obj, field_name).file.size == 0:
                        printTrack(obj, 'Size is 0')
                except:
                    printTrack(obj, 'FILE NOT FOUND')
            print '\t------------Done-------------'

        model_names = models.split(',')
        field_names = fields.split(',')
{'fraction_non_alphanumeric': 0.15649867374005305, 'fraction_numerical': 0.003375934410417169, 'mean_word_length': 1.8027027027027027, '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': '2368298', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1034, 'n_words': 310}