configfiles/scripts/barformatter.py

25 lines
588 B
Python
Raw Normal View History

2015-06-09 22:41:53 +02:00
from sys import argv, exit
class DefaultDict(dict):
def __init__(self,default):
super(DefaultDict, self).__init__()
self.default = default
def __getitem__(self, key):
return self.get(key, self.default)
if len(argv) <= 2:
print("%s <format_left> <format_right>" % argv[0])
exit(1)
format_left = argv[1]
format_right = argv[2]
cache = DefaultDict("")
_format = lambda: '%{l}' + (format_left % cache) + '%{r}' + (format_right % cache)
while True:
print(_format())
tag,content = input().rstrip('\n').split(' ',1)
cache[tag] = content