Skip to content

Instantly share code, notes, and snippets.

@coffindragger
Created December 22, 2011 20:32
Show Gist options
  • Save coffindragger/1511740 to your computer and use it in GitHub Desktop.
Save coffindragger/1511740 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import os
import optparse
class ExpandTemplateCommand(object):
def run(self, *args):
parser = optparse.OptionParser()
parser.add_option("-i", "", dest="in_filename", help="input file to use (default: stdin)", metavar="FILE")
parser.add_option("-o", "", dest="out_filename", help="output file to use (default: stdout)", metavar="FILE")
(self.options, self.args) = parser.parse_args()
self.in_file = sys.stdin if self.options.in_filename is None else open(self.options.in_filename, 'rb')
self.out_file = sys.stdout if self.options.out_filename is None else open(self.options.out_filename, 'w+')
data = self.in_file.read()
self.in_file.close()
self.out_file.write( data % os.environ )
self.out_file.close()
if __name__ == '__main__':
cmd = ExpandTemplateCommand()
cmd.run(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment