Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pirogoeth
Created September 28, 2011 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirogoeth/1246739 to your computer and use it in GitHub Desktop.
Save pirogoeth/1246739 to your computer and use it in GitHub Desktop.
can split big files into smaller chunks easily with markers.
#!/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