#NEWLINE# @ argh_named ( 'script' ) #NEWLINE# @ arg_verbose #NEWLINE# @ argh . arg ( 'script' , metavar = 'FILE' , type = str , help = 'script file path or "-" (a single minus-sign) for stdin' ) #NEWLINE# @ argh . arg ( 'variable' , type = str , nargs = '*' , help = "'name=[type:]value'" ) #NEWLINE# @ expects_obj #NEWLINE# def handle_script( self , arg ) : #NEWLINE# #INDENT# 'run commands from a script file' #NEWLINE# try : #NEWLINE# #INDENT# if ( arg . script != '-' ) : #NEWLINE# #INDENT# script_text = open ( arg . script ) . read ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# script_text = sys . stdin . read ( ) #NEWLINE# #UNINDENT# #UNINDENT# except ( OSError , IOError ) as error : #NEWLINE# #INDENT# raise errors . Error ( ( '%s: %s' % ( error . __class__ . __name__ , error ) ) ) #NEWLINE# #UNINDENT# variables = dict ( ( util . parse_prop ( var ) for var in arg . variable ) ) #NEWLINE# variables [ 'current_script_dir' ] = os . path . dirname ( arg . script ) #NEWLINE# match = re . search ( '^\\s*#\\s+poni\\.template\\s*:\\s*(\\w+)' , lines , re . MULTILINE ) #NEWLINE# engine = ( match . group ( 1 ) if match else 'cheetah' ) #NEWLINE# script_text = template . render ( engine = engine , source_text = script_text , variables = variables ) #NEWLINE# lines = script_text . splitlines ( ) #NEWLINE# def wrap( args ) : #NEWLINE# #INDENT# if ( ' ' in args ) : #NEWLINE# #INDENT# return repr ( args ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return args #NEWLINE# #UNINDENT# #UNINDENT# def set_repo_path( sub_arg ) : #NEWLINE# #INDENT# self . tune_arg_namespace ( sub_arg ) #NEWLINE# sub_arg . root_dir = arg . root_dir #NEWLINE# #UNINDENT# lines = self . preprocess_script_lines ( lines ) #NEWLINE# for ( i , line ) in enumerate ( lines ) : #NEWLINE# #INDENT# args = shlex . split ( line , comments = True ) #NEWLINE# if ( not args ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if arg . verbose : #NEWLINE# #INDENT# print ( ( '$ ' + ' ' . join ( ( wrap ( a ) for a in args ) ) ) ) #NEWLINE# #UNINDENT# namespace = argparse . Namespace ( ) #NEWLINE# try : #NEWLINE# #INDENT# extra_loc = args . index ( '--' ) #NEWLINE# namespace . extras = args [ ( extra_loc + 1 ) : ] #NEWLINE# args = args [ : extra_loc ] #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# namespace . extras = [ ] #NEWLINE# #UNINDENT# start = time . time ( ) #NEWLINE# self . parser . dispatch ( argv = args , pre_call = set_repo_path , namespace = namespace ) #NEWLINE# stop = time . time ( ) #NEWLINE# if namespace . time_op : #NEWLINE# #INDENT# self . task_times . add_task ( ( 'L%d' % ( i + 1 ) ) , line , start , stop , args = args )