<commit_before>class DockerApi
   attr_reader :last_error
   def create_container container
     clear_error
     begin
       commandargs = container_commandline_args(container)
       commandargs = "docker run  -d " + commandargs
       SystemUtils.debug_output("create cont",commandargs)
       return   execute_docker_cmd(commandargs,container)
     rescue Exception=>e
       container.last_error=("Failed To Create ")
       SystemUtils.log_exception(e)
       return false
     end
   end

   def start_container   container
     clear_error
     begin
       commandargs ="docker start " + container.container_name
       return execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def stop_container container
     clear_error
     begin
       commandargs="docker stop " + container.container_name
       return execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def pause_container container
     clear_error
     begin
       commandargs = "docker pause " + container.container_name
       return execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def   image_exists? (image_name)
     cmd= "docker images -q " + image_name
     SystemUtils.debug_output( "image_exists",cmd)
     result = SystemUtils.execute_command(cmd)
     if  result[:result] != 0
       @last_error = result[:stderr]
                  return false
     end
     if  result[:stdout].length > 4
      return true
     else
       @last_error = result[:stderr]
     end
     
     return false
     rescue  Exception=>e
            SystemUtils.log_exception(e)
            return false
   end

   def unpause_container container
     clear_error
     begin
       commandargs="docker unpause " + container.container_name
       return  execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def ps_container container     
     cmdline="docker top " + container.container_name + " axl"
     result = SystemUtils.execute_command(cmdline)
     if result[:result] == 0
       return result[:stdout]
     end
     
    return    false
    
     rescue  Exception=>e
          SystemUtils.log_exception(e)
          return false  
   end

   
   def execute_docker_cmd(cmdline,container)
     clear_error
    
     docker_exec="docker exec -u " + container.cont_userid + " "
       p cmdline
     cmdline.gsub!(/docker exec/,docker_exec)
     p cmdline
     result = SystemUtils.execute_command(cmdline)
            container.last_result = result[:stdout]
            if container.last_result.start_with?("[") == true && (container.last_result.end_with?("]")  == false || container.last_result.end_with?("]") ==false)
                container.last_result+="]"
                
              end<commit_msg>force user on exec only<commit_after>class DockerApi
   attr_reader :last_error
   def create_container container
     clear_error
     begin
       commandargs = container_commandline_args(container)
       commandargs = "docker run  -d " + commandargs
       SystemUtils.debug_output("create cont",commandargs)
       return   execute_docker_cmd(commandargs,container)
     rescue Exception=>e
       container.last_error=("Failed To Create ")
       SystemUtils.log_exception(e)
       return false
     end
   end

   def start_container   container
     clear_error
     begin
       commandargs ="docker start " + container.container_name
       return execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def stop_container container
     clear_error
     begin
       commandargs="docker stop " + container.container_name
       return execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def pause_container container
     clear_error
     begin
       commandargs = "docker pause " + container.container_name
       return execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def   image_exists? (image_name)
     cmd= "docker images -q " + image_name
     SystemUtils.debug_output( "image_exists",cmd)
     result = SystemUtils.execute_command(cmd)
     if  result[:result] != 0
       @last_error = result[:stderr]
                  return false
     end
     if  result[:stdout].length > 4
      return true
     else
       @last_error = result[:stderr]
     end
     
     return false
     rescue  Exception=>e
            SystemUtils.log_exception(e)
            return false
   end

   def unpause_container container
     clear_error
     begin
       commandargs="docker unpause " + container.container_name
       return  execute_docker_cmd(commandargs,container)
     rescue  Exception=>e
       SystemUtils.log_exception(e)
       return false
     end
   end

   def ps_container container     
     cmdline="docker top " + container.container_name + " axl"
     result = SystemUtils.execute_command(cmdline)
     if result[:result] == 0
       return result[:stdout]
     end
     
    return    false
    
     rescue  Exception=>e
          SystemUtils.log_exception(e)
          return false  
   end

   
   def execute_docker_cmd(cmdline,container)
     clear_error
    if cmdline.include?("docker exec")    
     docker_exec="docker exec -u " + container.cont_userid + " "
       p cmdline
     cmdline.gsub!(/docker exec/,docker_exec)
     p cmdline
    end
     result = SystemUtils.execute_command(cmdline)
            container.last_result = result[:stdout]
            if container.last_result.start_with?("[") == true && (container.last_result.end_with?("]")  == false || container.last_result.end_with?("]") ==false)
                container.last_result+="]"
                
              end
{'fraction_non_alphanumeric': 0.07312317192070199, 'fraction_numerical': 0.0009749756256093598, 'mean_word_length': 2.398674765323026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2114432', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1692, 'n_words': 379}