Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit e75cad3

Browse files
committed
Fix makeconstants.py
run with python3 changed headers due to changes in NM packaging
1 parent ea78c5f commit e75cad3

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

makeconstants.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33

44
import re
55

6-
enum_regex = re.compile(r'typedef enum(?:\s+[a-zA-Z]+)?\s*\{(.*?)\}', re.DOTALL)
6+
enum_regex = re.compile(r'typedef enum[^{]*\{(.*?)\}', re.DOTALL)
77
comment_regex = re.compile(r'/\*.*?\*/', re.DOTALL)
8+
suffix_regex = re.compile(r'[uUlL]+$')
9+
10+
def parse_c_value(val, constants):
11+
val = suffix_regex.sub('', val.strip())
12+
return eval(val, constants)
13+
814
headers = [ '/usr/include/libnm/nm-dbus-interface.h',
9-
'/usr/include/NetworkManager/NetworkManagerVPN.h',
10-
'/usr/include/libnm-glib/nm-secret-agent.h']
15+
'/usr/include/libnm/nm-vpn-dbus-interface.h',
16+
'/usr/include/libnm/nm-secret-agent-old.h']
1117

18+
constants = {}
1219
for h in headers:
1320
for enum in enum_regex.findall(open(h).read()):
1421
enum = comment_regex.sub('', enum)
@@ -17,10 +24,11 @@
1724
if not key.strip():
1825
continue
1926
if '=' in key:
20-
key, val = key.split('=')
21-
val = eval(val.replace('LL',''))
27+
key, val = key.split('=', 1)
28+
val = parse_c_value(val, constants)
2229
else:
2330
val = last + 1
2431
key = key.strip()
2532
print('%s = %d' % (key, val))
33+
constants[key] = val
2634
last = val

0 commit comments

Comments
 (0)