Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sdk/eventgrid/azure-eventgrid/swagger/postprocess_eventnames.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import inspect
import re
from azure.eventgrid._generated import models

def event_tuples(system_events):
tup_list = []
for event in system_events:
class_name = event[0].replace("EventData", "EventName")
try:
event_name = re.findall("Microsoft.[a-zA-Z]+.[a-zA-Z]+", event[1].__doc__)[0]
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to catch all types exceptions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - since this script is to autogenerate the evenname mappings, we dont want to let anything slip by

print(event[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be more explicit here that we weren't able to generate the mapping and sys.exit(1) at least to be sure any automation that would run this script would be stopped and blocked.

tup_list.append((class_name, event_name))
return tup_list

def generate_enum_content(tuples):
for tup in tup_list:
print(tup[0] + " = '" + tup[1] + "'\n")

system_events = [m for m in inspect.getmembers(models) if m[0].endswith('EventData')]
tup_list = event_tuples(system_events)

generate_enum_content(tup_list)