Created
December 5, 2016 16:20
-
-
Save allenap/614af046490d2a5bbc005c01b9c25844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import requests | |
maas_url = "http://maas.server:5240/MAAS/" | |
api_desc = requests.get(maas_url + "api/2.0/describe/").json() | |
uri_templates = {h["uri"] for h in api_desc["handlers"]} | |
class FormatKeys: | |
def __getitem__(self, name): | |
# Remove hyphens and underscores from the key. | |
return name.replace("_", "").replace("-", "").upper() | |
# Convert "{this_style}" placeholders in URIs because the underscores will not | |
# appear in rendered URLs but will skew the counts. | |
vformat = string.Formatter().vformat | |
uris = {vformat(uri, None, FormatKeys()) for uri in uri_templates} | |
for uri in sorted(uris): | |
print(uri) | |
print() | |
print(" Number of URIs:", len(uris)) | |
print(" underscores:", sum(1 for uri in uris if "_" in uri)) | |
print(" hyphens:", sum(1 for uri in uris if "-" in uri)) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For my server this outputs the list of URIs which it's counting followed by the summary: