<commit_before># frozen_string_literal: true

require 'yaml'

require_relative '../facts'
require_relative 'enc'

module OctocatalogDiff
  module CatalogUtil
    # Represents a directory that is created such that a catalog can be compiled
    # in it. This has the following major functions:
    # - Create the temporary directory that will serve as the puppet configuration directory
    # - Register a handler to remove the temporary directory upon exit
    # - Install needed configuration files within the directory (e.g. puppetdb.conf)
    # - Install the facts into the directory
    # - Install 'environments/(environment)' which is a symlink to the checkout of the puppet code
    class BuildDir
      # Allow the path to the temporary directory to be read
      attr_reader :tempdir, :enc, :fact_file

      # Constructor
      # Options for constructor:
      # :puppetdb_url [String] PuppetDB Server URLs
      # :puppetdb_server_url_timeout [Integer] Timeout (seconds) for puppetdb.conf
      # :facts [OctocatalogDiff::Facts] Facts object
      # :fact_file [String] File from which to read facts
      # :node [String] Node name
      # :basedir [String] Directory containing puppet code
      # :enc [String] ENC script file (can be relative or absolute path)
      # :pe_enc_url [String] ENC URL (for Puppet Enterprise node classification service)
      # :hiera_config [String] hiera configuration file (relative to base directory)
      # :hiera_path [String] relative path to hiera data files (mutually exclusive with :hiera_path_strip)
      # :hiera_path_strip [String] string to strip off the beginning of :datadir
      # :puppetdb_ssl_ca [String] Path to SSL CA certificate
      # :puppetdb_ssl_client_key [String] String representation of SSL client key
      # :puppetdb_ssl_client_cert [String] String representation of SSL client certificate
      # :puppetdb_ssl_client_password [String] Password to unlock SSL private key
      # @param options [Hash] Options for class; see above description
      def initialize(options = {}, logger = nil)
        @options = options.dup
        @tempdir = Dir.mktmpdir('ocd-builddir-')
        at_exit { FileUtils.rm_rf(@tempdir) if File.directory?(@tempdir) }

        @factdir = nil
        @enc = nil
        @fact_file = nil
        @node = options[:node]
        @facts_terminus = options.fetch(:facts_terminus, 'yaml')<commit_msg>Use new temp dir logic in the builddir code<commit_after># frozen_string_literal: true

require 'yaml'

require_relative '../facts'
require_relative 'enc'
require_relative '../util/util'

module OctocatalogDiff
  module CatalogUtil
    # Represents a directory that is created such that a catalog can be compiled
    # in it. This has the following major functions:
    # - Create the temporary directory that will serve as the puppet configuration directory
    # - Register a handler to remove the temporary directory upon exit
    # - Install needed configuration files within the directory (e.g. puppetdb.conf)
    # - Install the facts into the directory
    # - Install 'environments/(environment)' which is a symlink to the checkout of the puppet code
    class BuildDir
      # Allow the path to the temporary directory to be read
      attr_reader :tempdir, :enc, :fact_file

      # Constructor
      # Options for constructor:
      # :puppetdb_url [String] PuppetDB Server URLs
      # :puppetdb_server_url_timeout [Integer] Timeout (seconds) for puppetdb.conf
      # :facts [OctocatalogDiff::Facts] Facts object
      # :fact_file [String] File from which to read facts
      # :node [String] Node name
      # :basedir [String] Directory containing puppet code
      # :enc [String] ENC script file (can be relative or absolute path)
      # :pe_enc_url [String] ENC URL (for Puppet Enterprise node classification service)
      # :hiera_config [String] hiera configuration file (relative to base directory)
      # :hiera_path [String] relative path to hiera data files (mutually exclusive with :hiera_path_strip)
      # :hiera_path_strip [String] string to strip off the beginning of :datadir
      # :puppetdb_ssl_ca [String] Path to SSL CA certificate
      # :puppetdb_ssl_client_key [String] String representation of SSL client key
      # :puppetdb_ssl_client_cert [String] String representation of SSL client certificate
      # :puppetdb_ssl_client_password [String] Password to unlock SSL private key
      # @param options [Hash] Options for class; see above description
      def initialize(options = {}, logger = nil)
        @options = options.dup
        @tempdir = OctocatalogDiff::Util::Util.temp_dir('ocd-builddir-', options[:existing_tempdir])
        @factdir = nil
        @enc = nil
        @fact_file = nil
        @node = options[:node]
        @facts_terminus = options.fetch(:facts_terminus, 'yaml')
{'fraction_non_alphanumeric': 0.07369942196531792, 'fraction_numerical': 0.0, 'mean_word_length': 3.4572217111315546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2264632', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1312, 'n_words': 510}