#NEWLINE# def fill_command( args = None ) : #NEWLINE# #INDENT# import sys , optparse , pkg_resources , os #NEWLINE# if ( args is None ) : #NEWLINE# #INDENT# args = sys . argv [ 1 : ] #NEWLINE# #UNINDENT# dist = pkg_resources . get_distribution ( 'Paste' ) #NEWLINE# parser = optparse . OptionParser ( version = str ( dist ) , usage = _fill_command_usage ) #NEWLINE# parser . add_option ( '-o' , '--output' , dest = 'output' , metavar = 'FILENAME' , help = 'File to write output to (default stdout)' ) #NEWLINE# parser . add_option ( '--html' , dest = 'use_html' , action = 'store_true' , help = 'Use HTML style filling (including automatic HTML quoting)' ) #NEWLINE# parser . add_option ( '--env' , dest = 'use_env' , action = 'store_true' , help = 'Put the environment in as top-level variables' ) #NEWLINE# ( options , args ) = parser . parse_args ( args ) #NEWLINE# if ( len ( args ) < 1 ) : #NEWLINE# #INDENT# print ( 'You must give a template filename' ) #NEWLINE# print ( dir ( parser ) ) #NEWLINE# assert 0 #NEWLINE# #UNINDENT# template_name = args [ 0 ] #NEWLINE# args = args [ 1 : ] #NEWLINE# vars = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if options . use_env : #NEWLINE# #INDENT# vars . update ( os . environ ) #NEWLINE# #UNINDENT# for value in args : #NEWLINE# #INDENT# if ( '=' not in value ) : #NEWLINE# #INDENT# print ( ( 'Bad argument: %r' % value ) ) #NEWLINE# sys . exit ( 2 ) #NEWLINE# #UNINDENT# ( name , value ) = value . split ( '=' , 1 ) #NEWLINE# if name . startswith ( 'py:' ) : #NEWLINE# #INDENT# name = name [ : 3 ] #NEWLINE# value = eval ( value ) #NEWLINE# #UNINDENT# vars [ name ] = value #NEWLINE# #UNINDENT# if ( template_name == '-' ) : #NEWLINE# #INDENT# template_content = sys . stdin . read ( ) #NEWLINE# template_name = '<stdin>' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f = open ( template_name , 'rb' ) #NEWLINE# template_content = f . read ( ) #NEWLINE# f . close ( ) #NEWLINE# #UNINDENT# if options . use_html : #NEWLINE# #INDENT# TemplateClass = HTMLTemplate #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# TemplateClass = Template #NEWLINE# #UNINDENT# template = TemplateClass ( template_content , name = template_name ) #NEWLINE# result = template . substitute ( vars ) #NEWLINE# if options . output : #NEWLINE# #INDENT# f = open ( options . output , 'wb' ) #NEWLINE# f . write ( result ) #NEWLINE# f . close ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . stdout . write ( result )