<commit_before>require "dockerbash/version"
require "highline/import"
require "rest-client"
require "fileutils"
require "colorize"
require "open3"
require "json"
require "mkmf"

module MakeMakefile::Logging
  @logfile = File::NULL
  @quiet = true
end

module Dockerbash

  class Client

    def initialize(url, port)
      @docker_url = url
      @docker_port = port
      banner
      @docker_path = find_docker()
    end

    def select_docker_container(ids, tmp_work)
      counter = 0
      docker_ids = []
      ids = get_docker_containers_ids()
      ids.each do |i|
        container = RestClient.get "#{@docker_url}:#{@docker_port}/containers/#{i}/json"
        Dir.mkdir(tmp_work) unless File.exists?(tmp_work)
        container2json = open("#{tmp_work}#{i}.json", 'w')
        container2json.truncate(0)
        container2json.write(container)
        container2json.close
        
        json = File.read("#{tmp_work}#{i}.json")
        content_json = JSON.parse(json)
        container_name = content_json['Name'].green
        container_name.delete!("/")
        container_ip = content_json['NetworkSettings']['IPAddress'].blue
        container_started = content_json['State']['StartedAt'].gsub("T",' - ').blue
        container_id = content_json['Id']
        
        puts "#{counter}. Container: #{container_name}\t IP: #{container_ip}\t Started At: #{container_started}"
        docker_ids << container_id
        counter += 1
      end

      selected_id = ask("Container?  ", Integer) { |q| q.in = 0..docker_ids.count }
      command = "/usr/bin/docker exec -t -i #{docker_ids[selected_id]} /bin/bash"
      exec(command)
    end
    
    private
    
    def banner
     puts '         _            _             _               _       '.green.bold
     puts '      __| | ___   ___| | _____ _ __| |__   __ _ ___| |___   '.green.bold
     puts '     / _` |/ _ \ / __| |/ / _ \  __|  _ \ / _` / __|  _  \  '.white.bold
     puts '    | (_| | (_) | (__|   <  __/ |  | |_) | (_| \__ \ | | |  '.white.bold
     puts '     \__,_|\___/ \___|_|\_\___|_|  |_.__/ \__,_|___/_| |_|  '.yellow.bold
     puts '                                                            '.yellow.bold
     puts '                                                 by m8051.  '.red.bold
     puts '                                                            '
   end

   def find_docker()
     docker_path = find_executable('docker', path = nil)
     if docker_path.nil? || docker_path.empty?
       msg = " -- Docker not found, is the docker package installed?".red
       abort(msg)
     else
       return docker_path
     end
   end

   def get_docker_containers_ids()
     docker_containers_ids = []
     stdout, stdeerr, status = Open3.capture3("#{@docker_path} ps -aq -f status=running")
     if stdout.nil? || stdout.empty?
       msg = "  -- Is the Docker daemon running and the containers up?".red
       abort(msg)
     else
       concat_stdout = stdout.gsub(/\n/,' ')
       docker_containers_ids = concat_stdout.split(" ")
       return docker_containers_ids
     end
   end

  end

end
<commit_msg>Make the MakeMakefile logger write file output to null and stop msg checking for ... from STDOUT<commit_after>require "dockerbash/version"
require "highline/import"
require "rest-client"
require "fileutils"
require "colorize"
require "open3"
require "json"
require "mkmf"

# Preventing mkmf to:
#  => litter with log files.
#  => non-verbose stdout
module Logging
   @logfile = File::NULL
   @quiet = true
end

module Dockerbash

  class Client

    def initialize(url, port)
      @docker_url = url
      @docker_port = port
      banner
      @docker_path = find_docker()
    end

    def select_docker_container(ids, tmp_work)
      counter = 0
      docker_ids = []
      ids = get_docker_containers_ids()
      ids.each do |i|
        container = RestClient.get "#{@docker_url}:#{@docker_port}/containers/#{i}/json"
        Dir.mkdir(tmp_work) unless File.exists?(tmp_work)
        container2json = open("#{tmp_work}#{i}.json", 'w')
        container2json.truncate(0)
        container2json.write(container)
        container2json.close
        
        json = File.read("#{tmp_work}#{i}.json")
        content_json = JSON.parse(json)
        container_name = content_json['Name'].green
        container_name.delete!("/")
        container_ip = content_json['NetworkSettings']['IPAddress'].blue
        container_started = content_json['State']['StartedAt'].gsub("T",' - ').blue
        container_id = content_json['Id']
        
        puts "#{counter}. Container: #{container_name}\t IP: #{container_ip}\t Started At: #{container_started}"
        docker_ids << container_id
        counter += 1
      end

      selected_id = ask("Container?  ", Integer) { |q| q.in = 0..docker_ids.count }
      command = "/usr/bin/docker exec -t -i #{docker_ids[selected_id]} /bin/bash"
      exec(command)
    end
    
    private
    
    def banner
     puts '         _            _             _               _       '.green.bold
     puts '      __| | ___   ___| | _____ _ __| |__   __ _ ___| |___   '.green.bold
     puts '     / _` |/ _ \ / __| |/ / _ \  __|  _ \ / _` / __|  _  \  '.white.bold
     puts '    | (_| | (_) | (__|   <  __/ |  | |_) | (_| \__ \ | | |  '.white.bold
     puts '     \__,_|\___/ \___|_|\_\___|_|  |_.__/ \__,_|___/_| |_|  '.yellow.bold
     puts '                                                            '.yellow.bold
     puts '                                                 by m8051.  '.red.bold
     puts '                                                            '
   end

   def find_docker()
     docker_path = find_executable('docker', path = nil)
     if docker_path.nil? || docker_path.empty?
       msg = " -- Docker not found, is the docker package installed?".red
       abort(msg)
     else
       return docker_path
     end
   end

   def get_docker_containers_ids()
     docker_containers_ids = []
     stdout, stdeerr, status = Open3.capture3("#{@docker_path} ps -aq -f status=running")
     if stdout.nil? || stdout.empty?
       msg = "  -- Is the Docker daemon running and the containers up?".red
       abort(msg)
     else
       concat_stdout = stdout.gsub(/\n/,' ')
       docker_containers_ids = concat_stdout.split(" ")
       return docker_containers_ids
     end
   end

  end

end

{'fraction_non_alphanumeric': 0.12801133679735474, 'fraction_numerical': 0.004723665564478035, 'mean_word_length': 1.9084249084249085, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6566226', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1975, 'n_words': 394}