Last active
February 29, 2016 14:58
-
-
Save techtonik/83817e595d41629cb7f8 to your computer and use it in GitHub Desktop.
pkg-config *.co file parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# public domain | |
data = """ | |
prefix=/opt/windows_32 | |
exec_prefix=${prefix} | |
libdir=/opt/windows_32/lib | |
includedir=${prefix}/include | |
Name: Pango Win32 | |
Description: Win32 GDI font support for Pango | |
Version: 1.34.1 | |
Requires: pango | |
Libs: -L${libdir} -lpangowin32-1.0 -lgdi32 | |
Cflags: -I${includedir}/pango-1.0 | |
""" | |
from collections import OrderedDict | |
class PkgCoFile(object): | |
""" pkg-config .co files parser """ | |
freevars = OrderedDict() | |
fields = OrderedDict() | |
def __init__(self, data=None): | |
idx = 0 | |
lines = data.splitlines() | |
for idx, line in enumerate(lines): | |
if not line.strip(): | |
continue | |
elif '=' in line.strip(): | |
name, value = line.strip().split('=') | |
self.freevars[name.strip()] = value.strip() | |
else: | |
break | |
for line in lines[idx:]: | |
if not line.strip(): | |
continue | |
elif ':' in line.strip(): | |
name, value = line.strip().split(':') | |
self.fields[name.strip()] = value.strip() | |
def __str__(self): | |
res = '' | |
for x in self.freevars: | |
res += '%s=%s\n' % (x, self.freevars[x]) | |
res += '\n' | |
for x in self.fields: | |
res += '%s: %s\n' % (x, self.fields[x]) | |
return res | |
print PkgCoFile(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment