forked from mherrb/python-networkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeconstants.py
26 lines (23 loc) · 898 Bytes
/
makeconstants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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/libnm/nm-dbus-interface.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.replace('LL',''))
else:
val = last + 1
key = key.strip()
print('%s = %d' % (key, val))
last = val