parameters: (self, script, run_user, json_string, verbose=False)
docstring: @param run_user: run the script with this user
function: def run_script(self, script, run_user, json_string, verbose=False):
          """ @param run_user: run the script with this user """
  
          if run_user:
              # format string in order to run with 'su $user -c $cmd'
              json_string = json_string.replace('"', '\\\\\\"').replace(' ', '').replace('{', '\\{').replace('$', '\\\\\\$')
              # this command only works with shell=True
              script_cmd = '"%s su - %s -c \'%s/scripts/%s %s\'"' % (self.sudo_prefix, run_user, TMP_DIR, script, json_string)
              self.execute(script_cmd, verbose=verbose, shell=True, chkerr=False)
          else:
              script_cmd = '%s %s/scripts/%s \'%s\'' % (self.sudo_prefix, TMP_DIR, script, json_string)
              self.execute(script_cmd, verbose=verbose, chkerr=False)
  
          format1 = 'Host [%s]: Script [%s]: %s' % (self.host, script, self.stdout)
          format2 = 'Host [%s]: Script [%s]' % (self.host, script)
  
          self.logger.info(format1)
  
          if self.rc == 0:
              if not self.quiet: state_ok(format2)
              self.logger.info(format2 + ' ran successfully!')
          else:
              if not self.quiet: state_fail(format2)
              msg = 'Host [%s]: Failed to run \'%s\'' % (self.host, script)
              if self.stderr:
                  msg += ': ' + self.stderr
                  print '\n ' + self.stderr
              self.logger.error(msg)
              exit(1)
function_tokens: def run_script ( self , script , run_user , json_string , verbose = False ) : if run_user : # format string in order to run with 'su $user -c $cmd' json_string = json_string . replace ( '"' , '\\\\\\"' ) . replace ( ' ' , '' ) . replace ( '{' , '\\{' ) . replace ( '$' , '\\\\\\$' ) # this command only works with shell=True script_cmd = '"%s su - %s -c \'%s/scripts/%s %s\'"' % ( self . sudo_prefix , run_user , TMP_DIR , script , json_string ) self . execute ( script_cmd , verbose = verbose , shell = True , chkerr = False ) else : script_cmd = '%s %s/scripts/%s \'%s\'' % ( self . sudo_prefix , TMP_DIR , script , json_string ) self . execute ( script_cmd , verbose = verbose , chkerr = False ) format1 = 'Host [%s]: Script [%s]: %s' % ( self . host , script , self . stdout ) format2 = 'Host [%s]: Script [%s]' % ( self . host , script ) self . logger . info ( format1 ) if self . rc == 0 : if not self . quiet : state_ok ( format2 ) self . logger . info ( format2 + ' ran successfully!' ) else : if not self . quiet : state_fail ( format2 ) msg = 'Host [%s]: Failed to run \'%s\'' % ( self . host , script ) if self . stderr : msg += ': ' + self . stderr print '\n ' + self . stderr self . logger . error ( msg ) exit ( 1 )