aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2021-03-03 19:07:19 +0000
committerGerrit Code Review <gerrit@opnfv.org>2021-03-03 19:07:19 +0000
commita320df5bf04978fc1e73a2e49d1a4bed5b82b849 (patch)
tree73cdcbc9de8097d471911e2a97dcc05d4b68028c
parent402e6e1111964f28235f6f7ec53ba51c76a8298f (diff)
parent4caae41287310cb1309c9b30e2871297d3ed21ef (diff)
Merge "Add documentation request functions and use hints to admin utils"
-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")