So I created the script below to help me sort it out. It is not a complete script to handle all special cases like differences between ${} and $ token in BASH, but already good enough in my environment.
Try modify code yourself and enjoy hacking!
#!/usr/bin/env python
import sys
import re
keyval_pat = re.compile(r"[ ]*export ([^=]*)=(.*)")
fd = open(sys.argv[1])
print(r'<?xml version="1.0" encoding="utf-8">')
print(r'''
<!DOCTYPE plist PUBLIC
"-//Apple DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">''')
print('<plist version="1.0">')
print('<dict>')
for each_line in fd:
m = keyval_pat.search(each_line)
if m is None:
continue
key = m.group(1)
value = m.group(2)
print("<key>%s</key><string>%s</string>" % (key, value))
print('</dict>')
print('</plist>')
fd.close()
1 comment:
不错的script,收藏学习了!
Post a Comment