Created
September 28, 2011 01:07
-
-
Save pirogoeth/1246739 to your computer and use it in GitHub Desktop.
can split big files into smaller chunks easily with markers.
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
#!/usr/bin/env python | |
import sys | |
class Splitter(object): | |
def __init__(self, resource): | |
self.resource = resource | |
self.file = open(resource, 'r') | |
self.contents = self.file.read() | |
def __del__(self): | |
self.file.close() | |
del self.resource, self.file, self.contents | |
def expandTabs(self, do): | |
self.expand = do | |
def split(self): | |
file = None | |
for line in self.contents.splitlines(): | |
if line.lstrip().startswith('==!') and line.rstrip().endswith('!=='): | |
if file is not None: | |
file.close() | |
del file | |
file = open(line.split('!')[1], 'w+') | |
print 'Processing data for [%s]' % (line.split('!')[1]) | |
else: | |
if not file: | |
continue | |
elif file: | |
if self.expand: | |
file.write(line.expandtabs(4) + '\n') | |
elif not self.expand: | |
file.write(line + '\n') | |
if __name__ == '__main__': | |
resource = sys.argv[1] | |
print 'Processing [%s]' % (resource) | |
s = Splitter(resource) | |
if 'extab' in sys.argv: | |
print 'Tabs will be expanded to size: [4]' | |
s.expandTabs(True) | |
s.split() | |
del s | |
print 'Finished processing [%s]' % (resource) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment