| (.+?) | (.+?) | (.+?) | (.+?)'
RegExp += r' | (.+?) | (.+?) | (.+?)'
def stripmarkup(x):
tags = re.compile(r'(<[^>]+?>)', re.S).findall(x)
for tag in tags: x = string.replace(x, tag, '')
return x
def format(y, flag):
if flag in ('name', 'values', 'media'): y = stripmarkup(y)
if flag == 'applies': y = string.replace(y, ' ', 'all')
if flag == 'perc': y = string.replace(y, ' ', 'N/A')
if flag == 'name':
y = string.replace(y, '\'', '')
y = string.replace(y, ' ', '_')
y = string.replace(y, '<', '<')
y = string.replace(y, '>', '>')
y = string.replace(y, '"', '\\"')
y = string.replace(y, '\n', '')
return string.replace(y, '\r', '')
def run():
print '@prefix : <#> .\n'
f = open(sys.argv[1],'r')
s = f.read()
f.close()
results = re.compile(RegExp, re.S).findall(s)
for m in results:
print ':%s :values "%s"; ' \
% (format(m[0], 'name'), format(m[1], 'values'))
print ' :initialValue "%s"; \n :appliesTo "%s"; ' \
% (format(m[2], 'init'), format(m[3], 'applies'))
print ' :inherited "%s"; \n :percentages "%s"; ' \
% (format(m[4], 'inherit'), format(m[5], 'perc'))
print ' :mediaGroups "%s" .' % (format(m[6], 'media'))
if __name__ == "__main__":
run()
|