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
|
#!/usr/bin/python
from __future__ import print_function
from re import compile,DOTALL,MULTILINE
import sys
enum = compile("static const PkEnumMatch enum_([^\]]+)\[\] = {(.*?)};", DOTALL|MULTILINE)
value = compile("PK_([A-Z_]+)_ENUM_([A-Z0-9_]+),\s+\"([^\"]+)\"")
inp = open(sys.argv[1]).read()
names = {}
print("# This file was autogenerated from %s by enum-converter.py\n" % sys.argv[1])
print("class PackageKitEnum:")
for (name,data) in enum.findall(inp):
print("\t%s = ("%name, end=' ')
for (type,enum,string) in value.findall(data):
print("\"%s\","%string, end=' ')
names["%s_%s"%(type,enum)] = string
print(")")
print("\n# Constants\n")
for k in sorted(names.keys()):
print('%s = "%s"'%(k,names[k]))
|