<commit_before>require 'docker'
require 'pathname'

module Mumukit
  class IsolatedEnvironment

    attr_accessor :container

    def configure!(*files)

      filenames = files.map { |it| File.absolute_path(it.path) }
      dirnames = filenames.map { |it| Pathname.new(it).dirname }

      binds = dirnames.map { |it| "#{it}:#{it}" }
      volumes = Hash[[dirnames.map { |it| [it, {}] }]]

      command = yield(*filenames).split

      configure_container! command, binds, volumes
    end

    def configure_container!(command, binds, volumes)
      self.container = Docker::Container.create(
        'Image' => Mumukit.config.docker_image,
        'Cmd' => command,
        'NetworkDisabled' => true,
        'HostConfig' => {
            'Binds' => binds},
        'Volumes' => volumes)
    end

    def run!
      run_container!
      exit, out = fetch_container_state!

      if exit == 0
        [out, :passed]
      else
        [out, :failed]
      end
    rescue Docker::Error::TimeoutError => e
      [I18n.t('mumukit.time_exceeded', limit: Mumukit.config.command_time_limit), :aborted]
    end

    def run_container!
      container.start
      container.wait(Mumukit.config.command_time_limit)
    end

    def fetch_container_state!
      exit = container.json['State']['ExitCode']
      out = container.streaming_logs(stdout: true, stderr: true)
      [exit, out]
    end

    def destroy!
      if container
        container.stop
        container.delete
      end
    end
  end
end
<commit_msg>Modifying isolated_environment::configure! to support multiple files<commit_after>require 'docker'
require 'pathname'

module Mumukit
  class IsolatedEnvironment

    attr_accessor :container

    def configure!(*files)
      filenames = files.map { |it| File.absolute_path(it.path) }
      dirnames = filenames.map { |it| Pathname.new(it).dirname }

      binds = dirnames.map { |it| "#{it}:#{it}" }
      volumes = Hash[dirnames.map { |it| [[it, {}]] }]

      command = yield(*filenames).split

      configure_container! command, binds, volumes
    end

    def configure_container!(command, binds, volumes)
      self.container = Docker::Container.create(
        'Image' => Mumukit.config.docker_image,
        'Cmd' => command,
        'NetworkDisabled' => true,
        'HostConfig' => {
            'Binds' => binds},
        'Volumes' => volumes)
    end

    def run!
      run_container!
      exit, out = fetch_container_state!

      if exit == 0
        [out, :passed]
      else
        [out, :failed]
      end
    rescue Docker::Error::TimeoutError => e
      [I18n.t('mumukit.time_exceeded', limit: Mumukit.config.command_time_limit), :aborted]
    end

    def run_container!
      container.start
      container.wait(Mumukit.config.command_time_limit)
    end

    def fetch_container_state!
      exit = container.json['State']['ExitCode']
      out = container.streaming_logs(stdout: true, stderr: true)
      [exit, out]
    end

    def destroy!
      if container
        container.stop
        container.delete
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11785714285714285, 'fraction_numerical': 0.001948051948051948, 'mean_word_length': 2.5454545454545454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '6326553', 'n_tokens_mistral': 991, 'n_tokens_neox': 949, 'n_words': 211}