<commit_before>require "fileutils"
require "boxen/util"

module Boxen

  # Manages an invocation of puppet.

  class Puppeteer
    attr_reader :config

    def initialize(config)
      @config = config
    end

    def command
      manifest = "#{config.repodir}/manifests/site.pp"
      puppet   = "#{config.repodir}/bin/puppet"

      [puppet, "apply", flags, manifest].flatten
    end

    def flags
      flags = []
      root  = File.expand_path "../../..", __FILE__

      flags << ["--confdir",     "#{config.puppetdir}/conf"]
      flags << ["--vardir",      "#{config.puppetdir}/var"]
      flags << ["--libdir",      "#{config.repodir}/lib"]#:#{root}/lib"]
      flags << ["--libdir",      "#{root}/lib"]
      flags << ["--manifestdir", "#{config.repodir}/manifests"]
      flags << ["--modulepath",  "#{config.repodir}/modules:#{config.repodir}/shared"]

      # Log to both the console and a file.

      flags << ["--logdest", config.logfile]
      flags << ["--logdest", "console"]

      # For some reason Puppet tries to set up a bunch of rrd stuff
      # (user, group) unless reports are completely disabled.

      flags << "--no-report"
      flags << "--detailed-exitcodes"

      if config.profile?
        flags << "--evaltrace"
        flags << "--summarize"
      end

      flags << "--debug" if config.debug?
      flags << "--noop"  if config.pretend?

      flags.flatten
    end

    def run
      FileUtils.mkdir_p config.puppetdir

      FileUtils.rm_f config.logfile

      FileUtils.mkdir_p File.dirname config.logfile
      FileUtils.touch config.logfile

      warn command.join " " if config.debug?
      Boxen::Util.sudo *command
<commit_msg>Run librarian-puppet if it's relevant<commit_after>require "fileutils"
require "boxen/util"

module Boxen

  # Manages an invocation of puppet.

  class Puppeteer
    attr_reader :config

    def initialize(config)
      @config = config
    end

    def command
      manifest = "#{config.repodir}/manifests/site.pp"
      puppet   = "#{config.repodir}/bin/puppet"

      [puppet, "apply", flags, manifest].flatten
    end

    def flags
      flags = []
      root  = File.expand_path "../../..", __FILE__

      flags << ["--confdir",     "#{config.puppetdir}/conf"]
      flags << ["--vardir",      "#{config.puppetdir}/var"]
      flags << ["--libdir",      "#{config.repodir}/lib"]#:#{root}/lib"]
      flags << ["--libdir",      "#{root}/lib"]
      flags << ["--manifestdir", "#{config.repodir}/manifests"]
      flags << ["--modulepath",  "#{config.repodir}/modules:#{config.repodir}/shared"]

      # Log to both the console and a file.

      flags << ["--logdest", config.logfile]
      flags << ["--logdest", "console"]

      # For some reason Puppet tries to set up a bunch of rrd stuff
      # (user, group) unless reports are completely disabled.

      flags << "--no-report"
      flags << "--detailed-exitcodes"

      if config.profile?
        flags << "--evaltrace"
        flags << "--summarize"
      end

      flags << "--debug" if config.debug?
      flags << "--noop"  if config.pretend?

      flags.flatten
    end

    def run
      FileUtils.mkdir_p config.puppetdir

      FileUtils.rm_f config.logfile

      FileUtils.mkdir_p File.dirname config.logfile
      FileUtils.touch config.logfile

      if File.file? "Puppetfile"
        librarian = "#{config.repodir}/bin/librarian-puppet"

        # Set an environment variable for librarian-puppet's
        # github_tarball source strategy.

        ENV["GITHUB_API_TOKEN"] = config.token

        unless system librarian, "install", "--path=#{config.repodir}/shared"
          abort "Can't run Puppet, fetching dependencies with librarian failed."
        end
      end

      warn command.join " " if config.debug?
      Boxen::Util.sudo *command

{'fraction_non_alphanumeric': 0.14783748361730012, 'fraction_numerical': 0.0, 'mean_word_length': 2.315377932232841, 'pattern_counts': {'":': 0, '<': 59, '<?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': '6053850', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1189, 'n_words': 290}