1 | # Copyright (c) 2014, Salesforce.com, Inc. All rights reserved. |
||
2 | # |
||
3 | # Redistribution and use in source and binary forms, with or without |
||
4 | # modification, are permitted provided that the following conditions |
||
5 | # are met: |
||
6 | # |
||
7 | # - Redistributions of source code must retain the above copyright |
||
8 | # notice, this list of conditions and the following disclaimer. |
||
9 | # - Redistributions in binary form must reproduce the above copyright |
||
10 | # notice, this list of conditions and the following disclaimer in the |
||
11 | # documentation and/or other materials provided with the distribution. |
||
12 | # - Neither the name of Salesforce.com nor the names of its contributors |
||
13 | # may be used to endorse or promote products derived from this |
||
14 | # software without specific prior written permission. |
||
15 | # |
||
16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
17 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
18 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||
19 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||
20 | # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||
22 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||
23 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
||
25 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
||
26 | # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | |||
28 | from collections import defaultdict |
||
29 | import parsable |
||
30 | from distributions.tests.util import list_models, import_model |
||
31 | |||
32 | |||
33 | View Code Duplication | @parsable.command |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
34 | def flavors_by_model(): |
||
35 | ''' |
||
36 | List flavors implemented of each model. |
||
37 | ''' |
||
38 | models = defaultdict(lambda: []) |
||
39 | for spec in list_models(): |
||
40 | models[spec['name']].append(spec['flavor']) |
||
41 | for model in sorted(models): |
||
42 | print 'model {}: {}'.format(model, ' '.join(sorted(models[model]))) |
||
43 | |||
44 | |||
45 | View Code Duplication | @parsable.command |
|
0 ignored issues
–
show
|
|||
46 | def models_by_flavor(): |
||
47 | ''' |
||
48 | List models implemented of each flavor. |
||
49 | ''' |
||
50 | flavors = defaultdict(lambda: []) |
||
51 | for spec in list_models(): |
||
52 | flavors[spec['flavor']].append(spec['name']) |
||
53 | for flavor in sorted(flavors): |
||
54 | print 'flavor {}: {}'.format(flavor, ' '.join(sorted(flavors[flavor]))) |
||
55 | |||
56 | |||
57 | @parsable.command |
||
58 | def model_apis(): |
||
59 | ''' |
||
60 | List api of each model. |
||
61 | ''' |
||
62 | for spec in list_models(): |
||
63 | Model = import_model(spec).Model |
||
64 | attrs = sorted(attr for attr in dir(Model) if not attr.startswith('_')) |
||
65 | types = [] |
||
66 | methods = [] |
||
67 | constants = [] |
||
68 | for attr in attrs: |
||
69 | var = getattr(Model, attr) |
||
70 | if isinstance(var, type): |
||
71 | types.append(attr) |
||
72 | elif hasattr(var, '__call__'): |
||
73 | methods.append(attr) |
||
74 | else: |
||
75 | constants.append(attr) |
||
76 | print 'distributions.{}.models.{}.{}:'.format( |
||
77 | spec['flavor'], |
||
78 | spec['name'], |
||
79 | Model.__name__) |
||
80 | print ' types:\n {}'.format('\n '.join(types)) |
||
81 | print ' methods:\n {}'.format('\n '.join(methods)) |
||
82 | print ' constants:\n {}'.format('\n '.join(constants)) |
||
83 | |||
84 | |||
85 | if __name__ == '__main__': |
||
86 | parsable.dispatch() |
||
87 |