|
@@ -0,0 +1,129 @@
|
|
1
|
+from django.core.management.base import BaseCommand, CommandError
|
|
2
|
+from optparse import make_option
|
|
3
|
+from EditorialModel.model import Model
|
|
4
|
+from EditorialModel.backend.json_backend import EmBackendJson
|
|
5
|
+from EditorialModel.backend.dummy_backend import EmBackendDummy
|
|
6
|
+from EditorialModel.backend.graphviz import EmBackendGraphviz
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+class Command(BaseCommand):
|
|
10
|
+ option_list = BaseCommand.option_list + (
|
|
11
|
+ make_option('--no-classes',
|
|
12
|
+ action='store',
|
|
13
|
+ dest='classtype',
|
|
14
|
+ default = 0,
|
|
15
|
+ help='Chances for a classtype to be empty',
|
|
16
|
+ type="int",
|
|
17
|
+ metavar="INT",
|
|
18
|
+ ),
|
|
19
|
+ make_option('--max-classes',
|
|
20
|
+ action='store',
|
|
21
|
+ dest='nclass',
|
|
22
|
+ default = 5,
|
|
23
|
+ help='Maximum number of classes per classtype',
|
|
24
|
+ type="int",
|
|
25
|
+ metavar="INT",
|
|
26
|
+ ),
|
|
27
|
+ make_option('--no-fieldgroup',
|
|
28
|
+ action='store',
|
|
29
|
+ dest='nofg',
|
|
30
|
+ default = 10,
|
|
31
|
+ help='Chances for a class to have no fieldgroup',
|
|
32
|
+ type="int",
|
|
33
|
+ metavar="INT",
|
|
34
|
+ ),
|
|
35
|
+ make_option('--no-types',
|
|
36
|
+ action='store',
|
|
37
|
+ dest='notype',
|
|
38
|
+ default = 5,
|
|
39
|
+ help='Chances for a class to have no types',
|
|
40
|
+ type="int",
|
|
41
|
+ metavar="INT",
|
|
42
|
+ ),
|
|
43
|
+ make_option('--sel-opt-field',
|
|
44
|
+ action='store',
|
|
45
|
+ dest='seltype',
|
|
46
|
+ default = 2,
|
|
47
|
+ help='Chances for type to select an optionnal field',
|
|
48
|
+ type="int",
|
|
49
|
+ metavar="INT",
|
|
50
|
+ ),
|
|
51
|
+ make_option('--superiors',
|
|
52
|
+ action='store',
|
|
53
|
+ dest='ntypesuperiors',
|
|
54
|
+ default = 3,
|
|
55
|
+ help='Chances for a type to link with other types (superiors)',
|
|
56
|
+ type="int",
|
|
57
|
+ metavar="INT",
|
|
58
|
+ ),
|
|
59
|
+ make_option('--no-fields',
|
|
60
|
+ action='store',
|
|
61
|
+ dest='nofields',
|
|
62
|
+ default = 10,
|
|
63
|
+ help='Chances for a fieldgroup to be empty',
|
|
64
|
+ type="int",
|
|
65
|
+ metavar="INT",
|
|
66
|
+ ),
|
|
67
|
+ make_option('--max-fields',
|
|
68
|
+ action='store',
|
|
69
|
+ dest='nfields',
|
|
70
|
+ default = 8,
|
|
71
|
+ help='Maxmimum number of fields per fieldgroup',
|
|
72
|
+ type="int",
|
|
73
|
+ metavar="INT",
|
|
74
|
+ ),
|
|
75
|
+ make_option('--rel-to-type-attr',
|
|
76
|
+ action='store',
|
|
77
|
+ dest='rfields',
|
|
78
|
+ default = 5,
|
|
79
|
+ help='Maximum number of relation-to-type attribute fields',
|
|
80
|
+ type="int",
|
|
81
|
+ metavar="INT",
|
|
82
|
+ ),
|
|
83
|
+ make_option('--opt-field',
|
|
84
|
+ action='store',
|
|
85
|
+ dest='optfield',
|
|
86
|
+ default = 2,
|
|
87
|
+ help='Chances for a field to be optionnal',
|
|
88
|
+ type="int",
|
|
89
|
+ metavar="INT",
|
|
90
|
+ ),
|
|
91
|
+ make_option('-o',
|
|
92
|
+ '--output',
|
|
93
|
+ action='store',
|
|
94
|
+ dest='output',
|
|
95
|
+ default = 'random_me.json',
|
|
96
|
+ help='json output file for the me',
|
|
97
|
+ type="string",
|
|
98
|
+ metavar="FILENAME",
|
|
99
|
+ ),
|
|
100
|
+ make_option('-d',
|
|
101
|
+ '--output-dot',
|
|
102
|
+ action='store',
|
|
103
|
+ dest='dotout',
|
|
104
|
+ default = False,
|
|
105
|
+ help='graphviz output file for the me',
|
|
106
|
+ type="string",
|
|
107
|
+ metavar="FILENAME",
|
|
108
|
+ ),
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+ )
|
|
112
|
+ help = 'Randomly generate an EditorialModel'
|
|
113
|
+
|
|
114
|
+ def handle(self, *args, **options):
|
|
115
|
+ anames = ['classtype','nclass', 'nofg', 'notype', 'seltype', 'ntypesuperiors', 'nofields', 'nfields', 'optfield']
|
|
116
|
+ chances = dict()
|
|
117
|
+ for n in anames:
|
|
118
|
+ chances[n] = options[n]
|
|
119
|
+
|
|
120
|
+ bj = EmBackendJson(options['output'])
|
|
121
|
+
|
|
122
|
+ em = Model.random(EmBackendDummy())
|
|
123
|
+ bj.save(em)
|
|
124
|
+
|
|
125
|
+ if options['dotout']:
|
|
126
|
+ gvb = EmBackendGraphviz(options['dotout'])
|
|
127
|
+ gvb.save(em)
|
|
128
|
+
|
|
129
|
+
|