Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- ## Copyright (c) 2013 by Vimja
- ## This code is released under the terms
- ## of the WTFPL (What the Fuck Pulic License) version 2.0
- ## http://sam.zoy.org/wtfpl/
- import sys
- import re
- import os
- if len(sys.argv) < 3:
- sys.exit("At least two arguemnts are required!")
- usefile = open(sys.argv[1], 'r')
- regex = re.compile("[=>]*(([^/]+)/[^\s]+)\s")
- usemap = dict()
- currentstring = ""
- for line in usefile:
- match = regex.match(line)
- if match and not line.startswith("#"):
- currentstring = currentstring + line
- # print(line)
- # if usemap[match.group(2)]:
- if match.group(2) in usemap:
- # Hinzufuegen
- usemap[match.group(2)][match.group(1)] = currentstring
- currentstring = ""
- else:
- keyword = match.group(1)
- usemap[match.group(2)] = dict({keyword:currentstring})
- currentstring = ""
- else:
- if not line in ['\n', '\r\n']:
- #print("Comment found", line)
- currentstring = currentstring + line
- # else:
- # print("Empty line")
- if not os.path.exists(sys.argv[2]):
- sys.exit("That's not a valid path! You suck!")
- if not os.path.isdir(sys.argv[2]):
- sys.exit("Given target is a file, needs to be a directory")
- dirprefix = sys.argv[2]
- for key in sorted(usemap):
- print(key)
- filename = dirprefix + key
- print(filename)
- if os.path.isdir(filename):
- print("Path '", filename, "exists but is a directory instead of a file")
- else:
- destfile = open(filename, 'w+')
- for subkey in sorted(usemap[key]):
- print("\t", subkey)
- destfile.write(usemap[key][subkey])
- destfile.closed
Advertisement
Add Comment
Please, Sign In to add comment