@@ -0,0 +1,1762 @@
+from optparse import make_option%0Afrom django.core.management.base import CommandError%0Afrom django.core.management.base import BaseCommand%0A%0Afrom wurfl.models import Patch%0A%0A%0Aclass Command(BaseCommand):%0A    option_list = BaseCommand.option_list + (%0A        make_option('-i', '--inactive', action='store_false', dest='active', default=True,%0A            help='Create an initially inactive patch'),%0A        make_option('-p', '--priority', action='store', type='int', dest='priority', default=None,%0A            help='Force the priority of the patch, 0 for maximum priority, otherwise a min priority is calculated and assigned'),%0A    )%0A    args = '%5B%3Cname%3E%5D %3Cpatch_file.xml%3E'%0A    help = 'Create a new WURFL patch from an xml file.'%0A    %0A    def handle(self, *args, **options):%0A        if len(args) == 1:%0A            file_name = args%5B0%5D%0A            name = file_name%0A        elif len(args) == 2:%0A            file_name = args%5B1%5D%0A            name = args%5B0%5D%0A        else:%0A            raise CommandError(%22Missing patch filename argument%22)%0A%0A        try:%0A            f = open(file_name, 'r')%0A            patch_content = f.read()%0A            f.close()%0A%0A            if options%5B'priority'%5D == None:%0A                # Get max priority + 1%0A                priority = 1%0A                for p in Patch.objects.order_by('-priority')%5B:1%5D:%0A                    priority = p.priority + 1%0A            else:%0A                priority = options%5B'priority'%5D%0A                %0A            p = Patch.objects.create(%0A                name=name,%0A                patch=patch_content,%0A                priority=priority,%0A                active=options%5B'active'%5D,%0A            )%0A            print 'Created patch %60%25s%60 with id %25d' %25 (name, p.pk)%0A        except Exception, e:%0A            raise CommandError(e)%0A

add patch command