File: enum-convertor.py

package info (click to toggle)
packagekit 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,704 kB
  • sloc: ansic: 56,209; cpp: 13,919; python: 4,970; xml: 4,945; sh: 313; perl: 60; makefile: 57
file content (26 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (7)
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]))