| 1 |
#!/usr/bin/python |
| 2 |
from __future__ import print_function |
| 3 |
|
| 4 |
from re import compile,DOTALL,MULTILINE |
| 5 |
import sys |
| 6 |
|
| 7 |
enum = compile("static const PkEnumMatch enum_([^\]]+)\[\] = {(.*?)};", DOTALL|MULTILINE) |
| 8 |
value = compile("PK_([A-Z_]+)_ENUM_([A-Z0-9_]+),\s+\"([^\"]+)\"") |
| 9 |
|
| 10 |
inp = open(sys.argv[1]).read() |
| 11 |
|
| 12 |
names = {} |
| 13 |
|
| 14 |
print("# This file was autogenerated from %s by enum-converter.py\n" % sys.argv[1]) |
| 15 |
print("class PackageKitEnum:") |
| 16 |
for (name,data) in enum.findall(inp): |
| 17 |
print("\t%s = ("%name, end=' ') |
| 18 |
for (type,enum,string) in value.findall(data): |
| 19 |
print("\"%s\","%string, end=' ') |
| 20 |
names["%s_%s"%(type,enum)] = string |
| 21 |
print(")") |
| 22 |
|
| 23 |
print("\n# Constants\n") |
| 24 |
|
| 25 |
for k in sorted(names.keys()): |
| 26 |
print('%s = "%s"'%(k,names[k])) |