skip info
[auf_rh_dae.git] / project / dae / management / commands / dae.py
CommitLineData
0d5def11
OL
1# -*- encoding: utf-8 -*-
2
3from django.core.management.base import BaseCommand
f513a886 4
0d5def11 5from project.dae import models as dae
2d25d3ca 6from project.dae import exporter
f513a886
OL
7
8class Command(BaseCommand):
9
10
11 def handle(self, *args, **options):
bfdede88 12
5be12f6a
OL
13 if len(args) < 2:
14 print len(args)
15 self.stdout.write("dae <modele> <id> <run>\n")
0d5def11
OL
16 return
17
18 classname = args[0]
19 klass = getattr(dae, classname, None)
3b14230d
OL
20 if klass is None:
21 self.stdout.write("Le modèle %s n'existe pas dans DAE.\n" % classname)
0d5def11
OL
22
23 id = int(args[1])
24 try:
25 obj = klass.objects.get(id=id)
26 except:
27 self.stdout.write("L'id %s n'existe pas pour le modèle %s dans DAE.\n" % \
28 (id, classname))
29 return
30
0d5def11 31
5be12f6a 32 dry_run = True
9931d4cc 33 if len(args) >= 3 and args[2] == "run":
5be12f6a 34 dry_run = False
0d5def11 35
f513a886 36 verbosity = 0
9931d4cc 37 if len(args) >= 4:
f513a886
OL
38 verbosity = int(args[3])
39
2d25d3ca
OL
40 class_copier = getattr(exporter, "%sCopier" % classname.title())
41 copier = class_copier(verbosity=verbosity, dry_run=dry_run)
f513a886
OL
42
43 copy = copier.duplicate(obj)
5be12f6a 44 self.stdout.write(u"\n[%s] DAE:%s => RH:%s\n" % (obj.__class__.__name__, obj.id, copy.id))
0d5def11 45