aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2021-03-03 12:10:02 -0500
committerSawyer Bergeron <sbergeron@iol.unh.edu>2021-03-03 13:27:23 -0500
commit4caae41287310cb1309c9b30e2871297d3ed21ef (patch)
tree3dab57398e5282d15ea3dc5548cc8dbfd4b48ff0 /src/dashboard
parentdb4c2dc4c4f0d86e0a00e8409eed74a0bcffb20b (diff)
Add documentation request functions and use hints to admin utils
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: I3211194fea5dc7d0c3569db6c1d42fe2f4aa53e1 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/dashboard')
-rw-r--r--src/dashboard/admin_utils.py38
1 files changed, 38 insertions, 0 deletions
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(<function name>)` or `admin_functions()` for help on using the admin utils")