# Path: kraut_parser/models.py
# class Package(models.Model):
#     name = models.CharField(max_length=255)
#     creation_time = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True)
#     description = models.TextField(null=True, blank=True)
#     short_description = models.CharField(max_length=255, null=True, blank=True)
#     namespace = models.ManyToManyField('Namespace', blank=True)
#     version = models.CharField(max_length=255)
#     package_id = models.CharField(max_length=255)
#     source = models.CharField(max_length=255)
#     produced_time = models.DateTimeField(null=True, blank=True)
#     threat_actors = models.ManyToManyField('ThreatActor', blank=True)
#     campaigns = models.ManyToManyField('Campaign', blank=True)
#     indicators = models.ManyToManyField('Indicator', blank=True)
#     observables = models.ManyToManyField('Observable', blank=True)
#     ttps = models.ManyToManyField('TTP', blank=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.name)


from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.db.models import Count
from kraut_parser.models import Package
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

# import database models

class Command(BaseCommand):
    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)

    def handle(self, *args, **options):
        p = Package.objects.filter(package_id='edge:Package-a7b3f172-5204-473f-b77d-bce34d071611')
        print(p.count())
        self.stdout.write('------')

# Path: kraut_parser/models.py
# class Package(models.Model):
#     name = models.CharField(max_length=255)
#     creation_time = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True)
#     description = models.TextField(null=True, blank=True)
#     short_description = models.CharField(max_length=255, null=True, blank=True)
#     namespace = models.ManyToManyField('Namespace', blank=True)
#     version = models.CharField(max_length=255)
#     package_id = models.CharField(max_length=255)
#     source = models.CharField(max_length=255)
#     produced_time = models.DateTimeField(null=True, blank=True)
#     threat_actors = models.ManyToManyField('ThreatActor', blank=True)
#     campaigns = models.ManyToManyField('Campaign', blank=True)
#     indicators = models.ManyToManyField('Indicator', blank=True)
#     observables = models.ManyToManyField('Observable', blank=True)
#     ttps = models.ManyToManyField('TTP', blank=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.name)


# Path: kraut_parser/management/commands/remove_dup_pkgs.py
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.db.models import Count
from kraut_parser.models import Package

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

# import database models

class Command(BaseCommand):
    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)

    def handle(self, *args, **options):
        p = Package.objects.filter(package_id='edge:Package-a7b3f172-5204-473f-b77d-bce34d071611')
        print(p.count())
        self.stdout.write('------')

        pkgs = Package.objects.values('package_id').annotate(tcount=Count('package_id')).order_by('-tcount')