<commit_before>require 'puppet'
require 'puppet/network/client'

# A class for accessing Puppet's internal state regarding a certain node or
# class.
class CucumberPuppet
  # Returns a new CucumberPuppet object.
  def initialize
    @confdir = "/etc/puppet"
    @manifest = @confdir + "/manifest/site.pp"

    # default facts
    @facts = {
      'architecture' => "",
      'domain' => "no.domain",
      'environment' => "production",
      'hostname' => "testnode",
      'lsbdistcodename' => "",
      'network_eth0' => "127.0.0.0",
      'operatingsystem' => "",
    }

    Puppet::Util::Log.newdestination(:console)
    Puppet::Util::Log.level = :notice
  end

  # Set Puppet's log level to 'debug'.
  def debug
    Puppet::Util::Log.level = :debug
  end

  # Define Puppet classes to include in a feature's testnode.
  def klass=(klass)
    # XXX sth like klass.split(/,/) and remove whitespace
    @klass = klass.to_a
  end

  # Compile catalog for configured testnode.
  #
  #   @confdir defaults to '/etc/puppet'
  #   @manifest defaults to @confdir + '/manifests/site.pp'
  #
  def compile_catalog( node = nil )
    Puppet[:confdir] = @confdir
    Puppet[:manifest] = @manifest
    Puppet.parse_config

    unless node.is_a?(Puppet::Node)
      node = Puppet::Node.new(@facts['hostname'], :classes => @klass)
      node.merge(@facts)
    end

    begin
      # Compile our catalog
      begin
        @catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node)
      rescue NameError
        @catalog = Puppet::Node::Catalog.find(node.name, :use_node => node)
      end
    rescue => detail
      if Puppet[:trace]
        puts detail.backtrace
      end
      if detail.is_a?(XMLRPC::FaultException)
        $stderr.puts detail.message
      else
        $stderr.puts detail
      end
      exit 1
    end
  end

  # Returns an Object with the given title from catalog.
  def get_resource(title)
    @catalog.resource(title)
  end
  # XXX add deprecation warning for resource()
  def resource(title)
    get_resource(title)
  end

end
<commit_msg>set puppet config variables AFTER parse_config<commit_after>require 'puppet'
require 'puppet/network/client'

# A class for accessing Puppet's internal state regarding a certain node or
# class.
class CucumberPuppet
  # Returns a new CucumberPuppet object.
  def initialize
    @confdir = "/etc/puppet"
    @manifest = @confdir + "/manifest/site.pp"

    # default facts
    @facts = {
      'architecture' => "",
      'domain' => "no.domain",
      'environment' => "production",
      'hostname' => "testnode",
      'lsbdistcodename' => "",
      'network_eth0' => "127.0.0.0",
      'operatingsystem' => "",
    }

    Puppet::Util::Log.newdestination(:console)
    Puppet::Util::Log.level = :notice
  end

  # Set Puppet's log level to 'debug'.
  def debug
    Puppet::Util::Log.level = :debug
  end

  # Define Puppet classes to include in a feature's testnode.
  def klass=(klass)
    # XXX sth like klass.split(/,/) and remove whitespace
    @klass = klass.to_a
  end

  # Compile catalog for configured testnode.
  #
  #   @confdir defaults to '/etc/puppet'
  #   @manifest defaults to @confdir + '/manifests/site.pp'
  #
  def compile_catalog( node = nil )
    Puppet.settings.handlearg("--confdir", @confdir)
    Puppet.parse_config
    # reset confdir in case it got overwritten
    Puppet.settings.handlearg("--confdir", @confdir)
    Puppet.settings.handlearg("--manifest", @manifest)

    unless node.is_a?(Puppet::Node)
      node = Puppet::Node.new(@facts['hostname'], :classes => @klass)
      node.merge(@facts)
    end

    begin
      # Compile our catalog
      begin
        @catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node)
      rescue NameError
        @catalog = Puppet::Node::Catalog.find(node.name, :use_node => node)
      end
    rescue => detail
      if Puppet[:trace]
        puts detail.backtrace
      end
      if detail.is_a?(XMLRPC::FaultException)
        $stderr.puts detail.message
      else
        $stderr.puts detail
      end
      exit 1
    end
  end

  # Returns an Object with the given title from catalog.
  def get_resource(title)
    @catalog.resource(title)
  end
  # XXX add deprecation warning for resource()
  def resource(title)
    get_resource(title)
  end

end

{'fraction_non_alphanumeric': 0.1211489460273338, 'fraction_numerical': 0.003706277507528376, 'mean_word_length': 2.7943760984182777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1757025', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1428, 'n_words': 356}