diff --git a/contrib/scripts/statistics.py b/contrib/scripts/statistics.py new file mode 100755 index 0000000000..abd5708031 --- /dev/null +++ b/contrib/scripts/statistics.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python + +import os +from os.path import join, getsize + +BASE_PATH = 'mayan/apps' + + +def print_views_summary(module_filename): + with open(module_filename) as file_object: + print ' module:', module_filename + count_class_based_views = 0 + count_function_based_views = 0 + for line in file_object: + if line.startswith('class') and 'View' in line: + count_class_based_views += 1 + + if line.startswith('def') and 'request' in line: + count_function_based_views += 1 + + + print ' class based views: {}'.format(count_class_based_views) + print ' function based views: {}'.format(count_function_based_views) + return count_class_based_views, count_function_based_views + + +def print_tests_summary(module_filename): + with open(module_filename) as file_object: + print ' module:', module_filename + count_tests = 0 + for line in file_object: + #if 'def test' in line: + if line.startswith(' def test'): + count_tests += 1 + + print ' tests: {}'.format(count_tests) + return count_tests + + +if __name__ == '__main__': + count_totals = { + 'Apps': 0, + 'Class based views': 0, + 'Function based views': 0, + 'Class based API views': 0, + 'Function based API views': 0, + 'Tests': 0, + } + + for app_name in sorted(os.listdir(BASE_PATH)): + if app_name != '__init__.py': + count_totals['Apps'] += 1 + print '\n\nApp name: {}'.format(app_name) + app_path = os.path.join(BASE_PATH, app_name) + + print '\n Views' + try: + module_filename = os.path.join(app_path, 'views.py') + count_class_based_views, count_function_based_views = print_views_summary(module_filename=module_filename) + count_totals['Class based views'] += count_class_based_views + count_totals['Function based views'] += count_function_based_views + + except IOError: + # Check for multiple view files inside a view directory + try: + module_path = os.path.join(module_path, 'views') + for module_name in os.listdir(module_path): + if not module_name.startswith('__init__.py') and not module_name.endswith('.pyc'): + module_filename = os.path.join(module_path, module_name) + count_class_based_views, count_function_based_views = print_views_summary(module_filename=module_filename) + count_totals['Class based views'] += count_class_based_views + count_totals['Function based views'] += count_function_based_views + except OSError: + # No views directory, skip app + print ' No views' + + print '\n API Views' + try: + module_filename = os.path.join(app_path, 'api_views.py') + count_class_based_views, count_function_based_views = print_views_summary(module_filename=module_filename) + count_totals['Class based API views'] += count_class_based_views + count_totals['Function based API views'] += count_function_based_views + + except IOError: + # No API views directory, skip app + print ' No API views' + + + print '\n Tests' + module_path = os.path.join(app_path, 'tests') + try: + for module_name in os.listdir(module_path): + if not module_name.startswith('__init__.py') and not module_name.endswith('.pyc'): + module_filename = os.path.join(module_path, module_name) + if module_name.startswith('test'): + count_tests = print_tests_summary(module_filename=module_filename) + count_totals['Tests'] += count_tests + + except OSError: + # No tests directory, skip app + print ' No tests' + + + print '-' * 10 + + print 'Totals:' + for key, value in count_totals.items(): + print ' {}: {}'.format(key, value) diff --git a/docs/topics/code_statistics.rst b/docs/topics/code_statistics.rst new file mode 100644 index 0000000000..f8115bf911 --- /dev/null +++ b/docs/topics/code_statistics.rst @@ -0,0 +1,649 @@ +=============== +Code statistics +=============== + +As of Sun Mar 4 00:43:25 2018 (commit d367d32be62ed86dd6d7b02658eac2fa8086dbb9) + +App name: acls + + Views + module: mayan/apps/acls/views.py + class based views: 4 + function based views: 0 + + API Views + module: mayan/apps/acls/api_views.py + class based views: 4 + function based views: 0 + + Tests + module: mayan/apps/acls/tests/test_models.py + tests: 8 + module: mayan/apps/acls/tests/test_actions.py + tests: 2 + module: mayan/apps/acls/tests/test_links.py + tests: 4 + module: mayan/apps/acls/tests/test_api.py + tests: 9 + module: mayan/apps/acls/tests/test_views.py + tests: 8 + + +App name: appearance + + Views + No views + + API Views + No API views + + Tests + No tests + + +App name: authentication + + Views + module: mayan/apps/authentication/views.py + class based views: 0 + function based views: 7 + + API Views + No API views + + Tests + module: mayan/apps/authentication/tests/test_views.py + tests: 10 + + +App name: cabinets + + Views + module: mayan/apps/cabinets/views.py + class based views: 9 + function based views: 0 + + API Views + module: mayan/apps/cabinets/api_views.py + class based views: 5 + function based views: 0 + + Tests + module: mayan/apps/cabinets/tests/test_models.py + tests: 5 + module: mayan/apps/cabinets/tests/test_events.py + tests: 2 + module: mayan/apps/cabinets/tests/test_api.py + tests: 13 + module: mayan/apps/cabinets/tests/test_views.py + tests: 15 + + +App name: checkouts + + Views + module: mayan/apps/checkouts/views.py + class based views: 4 + function based views: 0 + + API Views + module: mayan/apps/checkouts/api_views.py + class based views: 2 + function based views: 0 + + Tests + module: mayan/apps/checkouts/tests/test_models.py + tests: 10 + module: mayan/apps/checkouts/tests/test_api.py + tests: 8 + module: mayan/apps/checkouts/tests/test_views.py + tests: 7 + + +App name: common + + Views + module: mayan/apps/common/views.py + class based views: 16 + function based views: 1 + + API Views + module: mayan/apps/common/api_views.py + class based views: 1 + function based views: 0 + + Tests + module: mayan/apps/common/tests/test_api.py + tests: 1 + module: mayan/apps/common/tests/test_commands.py + tests: 1 + module: mayan/apps/common/tests/test_views.py + tests: 3 + + +App name: converter + + Views + module: mayan/apps/converter/views.py + class based views: 4 + function based views: 0 + + API Views + No API views + + Tests + module: mayan/apps/converter/tests/test_classes.py + tests: 6 + module: mayan/apps/converter/tests/test_views.py + tests: 6 + + +App name: django_gpg + + Views + module: mayan/apps/django_gpg/views.py + class based views: 9 + function based views: 0 + + API Views + module: mayan/apps/django_gpg/api_views.py + class based views: 2 + function based views: 0 + + Tests + module: mayan/apps/django_gpg/tests/test_models.py + tests: 15 + module: mayan/apps/django_gpg/tests/test_api.py + tests: 6 + module: mayan/apps/django_gpg/tests/test_views.py + tests: 4 + + +App name: document_comments + + Views + module: mayan/apps/document_comments/views.py + class based views: 3 + function based views: 0 + + API Views + module: mayan/apps/document_comments/api_views.py + class based views: 2 + function based views: 0 + + Tests + module: mayan/apps/document_comments/tests/test_api.py + tests: 4 + + +App name: document_indexing + + Views + module: mayan/apps/document_indexing/views.py + class based views: 13 + function based views: 0 + + API Views + module: mayan/apps/document_indexing/api_views.py + class based views: 6 + function based views: 0 + + Tests + module: mayan/apps/document_indexing/tests/test_models.py + tests: 4 + module: mayan/apps/document_indexing/tests/test_views.py + tests: 8 + + +App name: document_parsing + + Views + module: mayan/apps/document_parsing/views.py + class based views: 6 + function based views: 0 + + API Views + module: mayan/apps/document_parsing/api_views.py + class based views: 1 + function based views: 0 + + Tests + module: mayan/apps/document_parsing/tests/test_parsers.py + tests: 1 + module: mayan/apps/document_parsing/tests/test_events.py + tests: 2 + module: mayan/apps/document_parsing/tests/test_api.py + tests: 2 + module: mayan/apps/document_parsing/tests/test_views.py + tests: 4 + + +App name: document_signatures + + Views + module: mayan/apps/document_signatures/views.py + class based views: 8 + function based views: 0 + + API Views + No API views + + Tests + module: mayan/apps/document_signatures/tests/test_models.py + tests: 13 + module: mayan/apps/document_signatures/tests/test_links.py + tests: 4 + module: mayan/apps/document_signatures/tests/test_views.py + tests: 12 + + +App name: document_states + + Views + module: mayan/apps/document_states/views.py + class based views: 29 + function based views: 0 + + API Views + module: mayan/apps/document_states/api_views.py + class based views: 12 + function based views: 0 + + Tests + module: mayan/apps/document_states/tests/test_models.py + tests: 3 + module: mayan/apps/document_states/tests/test_actions.py + tests: 0 + module: mayan/apps/document_states/tests/test_api.py + tests: 66 + module: mayan/apps/document_states/tests/test_views.py + tests: 33 + + +App name: documents + + Views + No views + + API Views + module: mayan/apps/documents/api_views.py + class based views: 16 + function based views: 0 + + Tests + module: mayan/apps/documents/tests/test_utils.py + tests: 1 + module: mayan/apps/documents/tests/test_models.py + tests: 12 + module: mayan/apps/documents/tests/test_events.py + tests: 4 + module: mayan/apps/documents/tests/test_widgets.py + tests: 1 + module: mayan/apps/documents/tests/test_links.py + tests: 6 + module: mayan/apps/documents/tests/test_search.py + tests: 4 + module: mayan/apps/documents/tests/test_api.py + tests: 39 + module: mayan/apps/documents/tests/test_views.py + tests: 61 + + +App name: dynamic_search + + Views + module: mayan/apps/dynamic_search/views.py + class based views: 4 + function based views: 0 + + API Views + module: mayan/apps/dynamic_search/api_views.py + class based views: 3 + function based views: 0 + + Tests + module: mayan/apps/dynamic_search/tests/test_models.py + tests: 2 + module: mayan/apps/dynamic_search/tests/test_api.py + tests: 3 + module: mayan/apps/dynamic_search/tests/test_views.py + tests: 1 + + +App name: events + + Views + module: mayan/apps/events/views.py + class based views: 9 + function based views: 0 + + API Views + module: mayan/apps/events/api_views.py + class based views: 7 + function based views: 0 + + Tests + module: mayan/apps/events/tests/test_api.py + tests: 1 + module: mayan/apps/events/tests/test_views.py + tests: 2 + + +App name: linking + + Views + module: mayan/apps/linking/views.py + class based views: 11 + function based views: 0 + + API Views + module: mayan/apps/linking/api_views.py + class based views: 7 + function based views: 0 + + Tests + module: mayan/apps/linking/tests/test_models.py + tests: 1 + module: mayan/apps/linking/tests/test_api.py + tests: 34 + module: mayan/apps/linking/tests/test_views.py + tests: 8 + + +App name: lock_manager + + Views + No views + + API Views + No API views + + Tests + module: mayan/apps/lock_manager/tests/test_backends.py + tests: 6 + + +App name: mailer + + Views + module: mayan/apps/mailer/views.py + class based views: 10 + function based views: 0 + + API Views + No API views + + Tests + module: mayan/apps/mailer/tests/test_models.py + tests: 5 + module: mayan/apps/mailer/tests/test_views.py + tests: 12 + + +App name: mayan_statistics + + Views + module: mayan/apps/mayan_statistics/views.py + class based views: 4 + function based views: 0 + + API Views + No API views + + Tests + module: mayan/apps/mayan_statistics/tests/test_views.py + tests: 4 + + +App name: metadata + + Views + module: mayan/apps/metadata/views.py + class based views: 9 + function based views: 0 + + API Views + module: mayan/apps/metadata/api_views.py + class based views: 6 + function based views: 0 + + Tests + module: mayan/apps/metadata/tests/test_models.py + tests: 14 + module: mayan/apps/metadata/tests/test_api.py + tests: 35 + module: mayan/apps/metadata/tests/test_views.py + tests: 8 + + +App name: mimetype + + Views + No views + + API Views + No API views + + Tests + No tests + + +App name: mirroring + + Views + No views + + API Views + No API views + + Tests + No tests + + +App name: motd + + Views + module: mayan/apps/motd/views.py + class based views: 4 + function based views: 0 + + API Views + module: mayan/apps/motd/api_views.py + class based views: 2 + function based views: 0 + + Tests + module: mayan/apps/motd/tests/test_models.py + tests: 4 + module: mayan/apps/motd/tests/test_api.py + tests: 10 + + +App name: navigation + + Views + No views + + API Views + No API views + + Tests + module: mayan/apps/navigation/tests/test_classes.py + tests: 9 + + +App name: ocr + + Views + module: mayan/apps/ocr/views.py + class based views: 8 + function based views: 0 + + API Views + module: mayan/apps/ocr/api_views.py + class based views: 3 + function based views: 0 + + Tests + module: mayan/apps/ocr/tests/test_models.py + tests: 2 + module: mayan/apps/ocr/tests/test_events.py + tests: 2 + module: mayan/apps/ocr/tests/test_api.py + tests: 6 + module: mayan/apps/ocr/tests/test_views.py + tests: 4 + + +App name: permissions + + Views + module: mayan/apps/permissions/views.py + class based views: 7 + function based views: 0 + + API Views + module: mayan/apps/permissions/api_views.py + class based views: 3 + function based views: 0 + + Tests + module: mayan/apps/permissions/tests/test_models.py + tests: 2 + module: mayan/apps/permissions/tests/test_api.py + tests: 17 + module: mayan/apps/permissions/tests/test_views.py + tests: 3 + + +App name: rest_api + + Views + No views + + API Views + module: mayan/apps/rest_api/api_views.py + class based views: 0 + function based views: 0 + + Tests + + +App name: smart_settings + + Views + module: mayan/apps/smart_settings/views.py + class based views: 2 + function based views: 0 + + API Views + No API views + + Tests + module: mayan/apps/smart_settings/tests/test_classes.py + tests: 1 + module: mayan/apps/smart_settings/tests/test_view_permissions.py + tests: 2 + + +App name: sources + + Views + module: mayan/apps/sources/views.py + class based views: 10 + function based views: 0 + + API Views + module: mayan/apps/sources/api_views.py + class based views: 4 + function based views: 0 + + Tests + module: mayan/apps/sources/tests/test_models.py + tests: 2 + module: mayan/apps/sources/tests/test_classes.py + tests: 1 + module: mayan/apps/sources/tests/test_views.py + tests: 16 + + +App name: storage + + Views + No views + + API Views + No API views + + Tests + No tests + + +App name: tags + + Views + module: mayan/apps/tags/views.py + class based views: 8 + function based views: 0 + + API Views + module: mayan/apps/tags/api_views.py + class based views: 5 + function based views: 0 + + Tests + module: mayan/apps/tags/tests/test_models.py + tests: 1 + module: mayan/apps/tags/tests/test_actions.py + tests: 2 + module: mayan/apps/tags/tests/test_api.py + tests: 28 + module: mayan/apps/tags/tests/test_views.py + tests: 18 + + +App name: task_manager + + Views + module: mayan/apps/task_manager/views.py + class based views: 4 + function based views: 0 + + API Views + No API views + + Tests + module: mayan/apps/task_manager/tests/test_views.py + tests: 8 + + +App name: user_management + + Views + module: mayan/apps/user_management/views.py + class based views: 11 + function based views: 0 + + API Views + module: mayan/apps/user_management/api_views.py + class based views: 6 + function based views: 0 + + Tests + module: mayan/apps/user_management/tests/test_api.py + tests: 31 + module: mayan/apps/user_management/tests/test_views.py + tests: 10 +---------- +Totals: + Tests: 742 + Function based API views: 0 + Function based views: 8 + Apps: 34 + Class based API views: 97 + Class based views: 206 + +These are the defined views and tests defined. Actual executable views or +tests could be higher if subclassed. + +Actual test executed: 748 as lock manager app subclasses its 6 tests once diff --git a/docs/topics/index.rst b/docs/topics/index.rst index f445eee078..c56f987808 100644 --- a/docs/topics/index.rst +++ b/docs/topics/index.rst @@ -25,3 +25,4 @@ Introductions to all the key parts of Mayan EDMS you'll need to know: file_storage backups pending_work + code_statistics