Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import core.models |
| 4 | import inspect |
Sapan Bhatia | 4e80a26 | 2017-05-19 23:10:51 +0200 | [diff] [blame] | 5 | from core.models import XOSBase, PlModelMixIn |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 6 | import pdb |
| 7 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 8 | |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 9 | def count(lst): |
| 10 | c = 0 |
| 11 | for l in lst[0]: |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 12 | ll = l.lstrip() |
| 13 | if (ll and not ll.startswith('#') and ll.rstrip() != 'pass' and 'ModelLink' not in ll and 'CHOICES' not in ll): |
| 14 | c += 1 |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 15 | return c |
| 16 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 17 | |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 18 | def is_model_class(model): |
| 19 | """ Return True if 'model' is something that we're interested in """ |
| 20 | if not inspect.isclass(model): |
| 21 | return False |
| 22 | if model.__name__ in ["PlModelMixIn"]: |
| 23 | return False |
| 24 | bases = inspect.getmro(model) |
| 25 | bases = [x.__name__ for x in bases] |
Sapan Bhatia | 4e80a26 | 2017-05-19 23:10:51 +0200 | [diff] [blame] | 26 | if ("XOSBase" in bases) or ("PlModelMixIn" in bases): |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 27 | return True |
| 28 | |
| 29 | return False |
| 30 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 31 | |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 32 | for a in dir(core.models): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 33 | x = getattr(core.models, a) |
Sapan Bhatia | 3d61cf8 | 2017-05-14 23:59:23 +0200 | [diff] [blame] | 34 | if (is_model_class(x)): |
| 35 | lines = inspect.getsourcelines(x) |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 36 | print x.__name__, ":", count(lines) |