From 4caae41287310cb1309c9b30e2871297d3ed21ef Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Wed, 3 Mar 2021 12:10:02 -0500 Subject: Add documentation request functions and use hints to admin utils Signed-off-by: Sawyer Bergeron Change-Id: I3211194fea5dc7d0c3569db6c1d42fe2f4aa53e1 Signed-off-by: Sawyer Bergeron --- src/dashboard/admin_utils.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/dashboard') diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py index 222ccd3..76db762 100644 --- a/src/dashboard/admin_utils.py +++ b/src/dashboard/admin_utils.py @@ -17,6 +17,9 @@ from resource_inventory.models import ( ) import json +import sys +import inspect +import pydoc from django.contrib.auth.models import User @@ -388,3 +391,38 @@ def extend_booking(booking_id, days=0, hours=0, minutes=0, weeks=0): booking = Booking.objects.get(id=booking_id) booking.end = booking.end + timedelta(days=days, hours=hours, minutes=minutes, weeks=weeks) booking.save() + + +def docs(function=None, fulltext=False): + fn = None + + if isinstance(function, str): + try: + fn = globals()[function] + except KeyError: + print("Couldn't find a function by the given name") + return + elif callable(function): + fn = function + else: + print("docs(function: callable | str, fulltext: bool) was called with a 'function' that was neither callable nor a string name of a function") + print("usage: docs('some_function_in_admin_utils', fulltext=True)") + print("The 'fulltext' argument is used to choose if you want the complete source of the function printed. If this argument is false then you will only see the pydoc rendered documentation for the function") + return + + if not fn: + print("couldn't find a function by that name") + + if not fulltext: + print("Pydoc documents the function as such:") + print(pydoc.render_doc(fn)) + else: + print("The full source of the function is this:") + print(inspect.getsource(fn)) + + +def admin_functions(): + return [name for name, func in inspect.getmembers(sys.modules[__name__]) if (inspect.isfunction(func) and func.__module__ == __name__)] + + +print("Hint: call `docs()` or `admin_functions()` for help on using the admin utils") -- cgit 1.2.3-korg