import DAE
[auf_rh_dae.git] / project / dae / management / commands / dae.py
index ae32173..0c2b404 100644 (file)
@@ -1,32 +1,17 @@
 # -*- encoding: utf-8 -*-
 
 from django.core.management.base import BaseCommand
-from project.dae import  models as dae
-
 
+from project.dae import  models as dae
 
 class Command(BaseCommand):
 
-    def explore(obj):
-        print obj
-        for f in obj._meta.fields:
-            def t(s):
-                s = "%s" % s
-                try:
-                    s = s.ljust(40)
-                    s = s.replace('\n', '')
-                    s = s[0:28]
-                except Exception, e:
-                    print e
-                    print s
-                    return
-                return s
-            print "%s%s%s" % (t(f.name), t(type(f).__name__), t(getattr(obj, f.name, "")))
-
+    
     def handle(self, *args, **options):
 
-        if len(args) != 2:
-            self.stdout.write("dae <modele> <id>\n")
+        if len(args) < 2:
+            print len(args)
+            self.stdout.write("dae <modele> <id> <run>\n")
             return
 
         classname = args[0]
@@ -42,31 +27,8 @@ class Command(BaseCommand):
                     (id, classname))
             return
 
-        def copy_model(src, dst, exclude=[]):
-            keys = [f.name for f in src._meta.fields if f.name not in ['id', ] + exclude]
-            for k in keys:
-                setattr(dst, k, getattr(src, k))
-            return dst
-
-        def duplicate(obj, level=0):
-            print "%s [%s] %s" % ("|"*level*4, obj.__class__.__name__, obj)
-            for obj_composition in obj._meta._related_objects_cache:
-                app_label, dummy = obj_composition.name.split(':')
-                field_name = obj_composition.field.rel.related_name
-                if app_label == obj._meta.app_label:
-                    try:
-                        children = getattr(obj, field_name)
-                    except:
-                        print obj_composition
-                        print field_name
-                        continue
-                    for child in children.all():
-                        duplicate(child, level+1)
-                
-
-        duplicate(obj)
-        import pdb; pdb.set_trace()
-        
-
 
+        copy = obj.importer()
+        self.stdout.write(u"\n[%s] DAE:%s => RH:%s\n" %
+                (obj.__class__.__name__, obj.id, copy.id))