Beispiel #1
0
    def handle(self, *args, **options):
        self.stdout.write('Checking hashes...')
        for bot in Bot.objects.all():
            if bot.bot_zip_md5hash == calculate_md5_django_filefield(bot.bot_zip):
                self.stdout.write(f'{bot.name} - bot_zip - MATCH')
            else:
                self.stdout.write(f'{bot.name} - bot_zip - MISMATCH')

            if bot.bot_data:
                if bot.bot_data_md5hash == calculate_md5_django_filefield(bot.bot_data):
                    self.stdout.write(f'{bot.name} - bot_data - MATCH')
                else:
                    self.stdout.write(f'{bot.name} - bot_data - MISMATCH')

        self.stdout.write('Done.')
Beispiel #2
0
def post_save_bot(sender, instance, created, **kwargs):
    # bot zip
    if created and hasattr(instance, _UNSAVED_BOT_ZIP_FILEFIELD):
        instance.bot_zip = getattr(instance, _UNSAVED_BOT_ZIP_FILEFIELD)
        post_save.disconnect(pre_save_bot, sender=sender)
        instance.save()
        post_save.connect(pre_save_bot, sender=sender)
        # delete the saved instance
        instance.__dict__.pop(_UNSAVED_BOT_ZIP_FILEFIELD)

    # bot data
    if created and hasattr(instance, _UNSAVED_BOT_DATA_FILEFIELD):
        instance.bot_data = getattr(instance, _UNSAVED_BOT_DATA_FILEFIELD)
        post_save.disconnect(pre_save_bot, sender=sender)
        instance.save()
        post_save.connect(pre_save_bot, sender=sender)
        # delete the saved instance
        instance.__dict__.pop(_UNSAVED_BOT_DATA_FILEFIELD)

    # Re-calculate the file hashes if required.
    if instance.bot_zip:
        bot_zip_hash = calculate_md5_django_filefield(instance.bot_zip)
        if instance.bot_zip_md5hash != bot_zip_hash:
            instance.bot_zip_md5hash = bot_zip_hash
            instance.bot_zip_updated = timezone.now()
            post_save.disconnect(pre_save_bot, sender=sender)
            instance.save()
            post_save.connect(pre_save_bot, sender=sender)

    if instance.bot_data:
        bot_data_hash = calculate_md5_django_filefield(instance.bot_data)
        if instance.bot_data_md5hash != bot_data_hash:
            instance.bot_data_md5hash = bot_data_hash
            post_save.disconnect(pre_save_bot, sender=sender)
            instance.save()
            post_save.connect(pre_save_bot, sender=sender)
    elif instance.bot_data_md5hash is not None:
        instance.bot_data_md5hash = None
        post_save.disconnect(pre_save_bot, sender=sender)
        instance.save()
        post_save.connect(pre_save_bot, sender=sender)

    # register a season participation if the bot has been activated
    if instance.active and instance.seasonparticipation_set.filter(
            season=Season.get_current_season()).count() == 0:
        from .season_participation import SeasonParticipation
        SeasonParticipation.objects.create(season=Season.get_current_season(),
                                           bot=instance)
Beispiel #3
0
    def handle(self, *args, **options):
        self.stdout.write('Repairing hashes...')

        if options['zip'] is None:
            self.stdout.write('No argument supplied - no actions taken.')
        else:
            for bot in Bot.objects.all():
                with transaction.atomic():
                    bot.lock_me()
                    bot_zip_hash = calculate_md5_django_filefield(bot.bot_zip)
                    if options['zip'] is not None and bot.bot_zip_md5hash != bot_zip_hash:
                        bot.bot_zip_md5hash = bot_zip_hash
                        bot.save()
                        self.stdout.write(f'{bot.name} - bot_zip - MISMATCH - REPAIRED')

                    if options['data'] is not None and bot.bot_data:
                        bot_data_hash = calculate_md5_django_filefield(bot.bot_data)
                        if bot.bot_data_md5hash != bot_data_hash:
                            bot.bot_data_md5hash = bot_data_hash
                            bot.save()
                            self.stdout.write(f'{bot.name} - bot_data - MISMATCH - REPAIRED')

        self.stdout.write('Done.')