Permalink
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (23 sloc) 885 Bytes
# Reads the Networkmanager headers and spits out the enums as a series of
# python variables.
import re
enum_regex = re.compile(r'typedef enum(?:\s+[a-zA-Z]+)?\s*\{(.*?)\}', re.DOTALL)
comment_regex = re.compile(r'/\*.*?\*/', re.DOTALL)
headers = ['/usr/include/NetworkManager/NetworkManager.h',
'/usr/include/NetworkManager/NetworkManagerVPN.h',
'/usr/include/libnm-glib/nm-secret-agent.h']
for h in headers:
for enum in enum_regex.findall(open(h).read()):
enum = comment_regex.sub('', enum)
last = -1
for key in enum.split(','):
if not key.strip():
continue
if '=' in key:
key, val = key.split('=')
val = eval(val)
else:
val = last + 1
key = key.strip()
print('%s = %d' % (key, val))
last = val