#NEWLINE# @ staticmethod #NEWLINE# def _add_append_script( ) : #NEWLINE# #INDENT# "\n        write the 'append to list' ES script to a file and store it at\n        ES scripts path (<ES>/config/scripts)\n        " #NEWLINE# es_path = os . path . dirname ( os . path . dirname ( subprocess . check_output ( 'which elasticsearch' , shell = True ) . rstrip ( '\r\n' ) ) ) #NEWLINE# es_scripts_path = os . path . join ( es_path , 'config/scripts' ) #NEWLINE# script_path = os . path . join ( es_scripts_path , 'append.groovy' ) #NEWLINE# if os . path . exists ( script_path ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# use_sudo = ( os . environ . get ( 'CI' ) == 'true' ) #NEWLINE# script = 'if (ctx._source.containsKey(key)) {ctx._source[key] += value;} else {ctx._source[key] = [value]}' . replace ( '"' , '\\"' ) #NEWLINE# if ( not os . path . exists ( es_scripts_path ) ) : #NEWLINE# #INDENT# os . system ( '{0} mkdir -p {1}' . format ( ( 'sudo' if use_sudo else '' ) , es_scripts_path ) ) #NEWLINE# #UNINDENT# os . system ( 'echo "{0}" | {1} tee {2}' . format ( script , ( 'sudo' if use_sudo else '' ) , script_path ) )