#NEWLINE# @ requires_admin #NEWLINE# def post( self , step_id ) : #NEWLINE# #INDENT# step = Step . query . get ( step_id ) #NEWLINE# if ( step is None ) : #NEWLINE# #INDENT# return error ( 'step not found' , http_code = 404 ) #NEWLINE# #UNINDENT# args = self . parser . parse_args ( ) #NEWLINE# if ( args . implementation is not None ) : #NEWLINE# #INDENT# step . implementation = args . implementation #NEWLINE# #UNINDENT# if ( args . data is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# data = json . loads ( args . data ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# return error ( ( 'invalid JSON: %s' % e ) ) #NEWLINE# #UNINDENT# if ( not isinstance ( data , dict ) ) : #NEWLINE# #INDENT# return error ( 'data must be a JSON mapping' ) #NEWLINE# #UNINDENT# impl_cls = step . get_implementation ( load = False ) #NEWLINE# if ( impl_cls is None ) : #NEWLINE# #INDENT# return error ( 'unable to load build step implementation' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# impl_cls ( ** deepcopy ( data ) ) #NEWLINE# #UNINDENT# except Exception as exc : #NEWLINE# #INDENT# return error ( ( 'unable to create build step mapping provided data: %s' % exc ) ) #NEWLINE# #UNINDENT# step . data = data #NEWLINE# #UNINDENT# if ( args . order is not None ) : #NEWLINE# #INDENT# step . order = args . order #NEWLINE# #UNINDENT# step . date_modified = datetime . utcnow ( ) #NEWLINE# db . session . add ( step ) #NEWLINE# plan = step . plan #NEWLINE# plan . date_modified = step . date_modified #NEWLINE# db . session . add ( plan ) #NEWLINE# for name in STEP_OPTIONS . keys ( ) : #NEWLINE# #INDENT# value = args . get ( name ) #NEWLINE# if ( value is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# create_or_update ( ItemOption , where = { #NEWLINE# #INDENT# 'item_id' : step . id , #NEWLINE# 'name' : name , #NEWLINE# #UNINDENT# } , values = { #NEWLINE# #INDENT# 'value' : value , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# db . session . commit ( ) #NEWLINE# return self . respond ( step )