from django.core.management.base import BaseCommand, CommandError

from core.models import Storage, Host, Plugin, Data_Source as Source

from optparse import make_option
import logging


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
    )

    def handle(self, *args, **options):
        for s in Storage.objects.all():
            s.create_hosts()
        for h in Host.objects.all():
            h.create_plugins()
        for p in Plugin.objects.all():
            p.create_data_sources()

@@ -254,16 +254,314 @@
 ist + (%0A
+        make_option('-H', '--host', action='store_true', help=%22Force to walk on already created hosts%22),%0A        make_option('-P', '--plugin', action='store_true', help=%22Force to walk on already created plugins%22),%0A        make_option('-q', '--quiet', action='store_true', help=%22Don't print info%22),%0A
     )%0A%0A 
@@ -596,15 +596,38 @@
 *opt
-ion
 s):%0A
+        # Walk on storage%0A
     
@@ -673,16 +673,92 @@
         
+ self.stdout.write('Creating hosts from storage %25s' %25 s)%0A            hosts =
  s.creat
@@ -779,37 +779,212 @@
     
+    
-for h in Host.objects.all():%0A
+hosts = hosts if not opts%5B'host'%5D else Host.objects.filter(storage=s)%0A            # Walk on hosts%0A            for h in hosts:%0A                self.stdout.write('Creating plugins from host %25s' %25 h)%0A   
     
@@ -990,16 +990,27 @@
         
+  plugins =
  h.creat
@@ -1033,71 +1033,508 @@
     
-for p in Plugin.objects.all():%0A            p.create_data_sources(
+        plugins = plugins if not opts%5B'plugin'%5D else Plugin.objects.filter(host=h)%0A                # Walk on plugins%0A                for p in plugins:%0A                    self.stdout.write('Creating sources from plugin %25s' %25 p)%0A                    p.create_data_sources()%0A        self.stdout.write('Done.')%0A        self.stdout.write('%25i host(s)' %25 Host.objects.count())%0A        self.stdout.write('%25i plugin(s)' %25 Plugin.objects.count())%0A        self.stdout.write('%25i source(s)' %25 Source.objects.count()
 )%0A

Improve populate command