<commit_before>#
# omnibus project dsl reader
#
module Omnibus
  class Project
    include Rake::DSL

    PACKAGE_TYPES = []
    PACKAGE_SCRIPTS_PATH = "../omnibus-ruby/package-scripts"

    attr_reader :name
    attr_reader :description
    attr_reader :dependencies

    def self.load(filename)
      new(IO.read(filename), filename)
    end

    def initialize(io, filename)
      @exclusions = Array.new
      case platform_family 
          when 'debian' 
            PACKAGE_TYPES << "deb"
          when 'fedora', 'rhel'
            PACKAGE_TYPES << "rpm"
      end
      instance_eval(io)
      render_tasks
    end

    def name(val)
      @name = val
    end

    def description(val)
      @description = val
    end

    def dependencies(val)
      @dependencies = val
    end

    def exclude(pattern)
      @exclusions << pattern
    end

    def platform_family
      OHAI.platform_family
    end

    def config
      Omnibus.config
    end

    private

    def render_tasks
      directory "pkg"

      namespace :projects do

        PACKAGE_TYPES.each do |pkg_type|
          namespace @name do
            desc "package #{@name} into a #{pkg_type}"
            task pkg_type => (@dependencies.map {|dep| "software:#{dep}"}) do
              if !File.exists?("#{config.install_dir}/setup.sh")
                shell = Mixlib::ShellOut.new("cp setup.sh #{config.install_dir}",
                                             :live_stream => STDOUT, 
                                             :cwd => PACKAGE_SCRIPTS_PATH)
                shell.run_command
                shell.error!
              end

              # build the fpm command
              fpm_command = ["fpm",
                             "-s dir",
                             "-t #{pkg_type}",
                             "-v 0.0.1",
                             "-n #{@name}",
                             config.install_dir,
                             "--post-install '../#{PACKAGE_SCRIPTS_PATH}/postinst'",
                             "--post-uninstall '../#{PACKAGE_SCRIPTS_PATH}/postrm'",
                             "-m 'Opscode, Inc.'",
                             "--description 'The full stack of #{@name}'",
                             "--url http://www.opscode.com"]

              @exclusions.each do |pattern|
                fpm_command << "--exclude '#{pattern}'"
              end

              shell = Mixlib::ShellOut.new(fpm_command.join(" "),
                                           :live_stream => STDOUT,
                                           :timeout => 3600,
                                           :cwd => './pkg')
              shell.run_command
              shell.error!<commit_msg>Fix up package scripts path.<commit_after>#
# omnibus project dsl reader
#
module Omnibus
  class Project
    include Rake::DSL

    PACKAGE_TYPES = []

    attr_reader :name
    attr_reader :description
    attr_reader :dependencies

    def self.load(filename)
      new(IO.read(filename), filename)
    end

    def initialize(io, filename)
      @exclusions = Array.new
      case platform_family 
          when 'debian' 
            PACKAGE_TYPES << "deb"
          when 'fedora', 'rhel'
            PACKAGE_TYPES << "rpm"
      end
      instance_eval(io)
      render_tasks
    end

    def name(val)
      @name = val
    end

    def description(val)
      @description = val
    end

    def dependencies(val)
      @dependencies = val
    end

    def exclude(pattern)
      @exclusions << pattern
    end

    def platform_family
      OHAI.platform_family
    end

    def config
      Omnibus.config
    end

    def package_scripts_path
      "#{Omnibus.gem_path}/package_scripts"
    end

    private

    def render_tasks
      directory "pkg"

      namespace :projects do

        PACKAGE_TYPES.each do |pkg_type|
          namespace @name do
            desc "package #{@name} into a #{pkg_type}"
            task pkg_type => (@dependencies.map {|dep| "software:#{dep}"}) do
              if !File.exists?("#{config.install_dir}/setup.sh")
                shell = Mixlib::ShellOut.new("cp setup.sh #{config.install_dir}",
                                             :live_stream => STDOUT, 
                                             :cwd => package_scripts_path)
                shell.run_command
                shell.error!
              end

              # build the fpm command
              fpm_command = ["fpm",
                             "-s dir",
                             "-t #{pkg_type}",
                             "-v 0.0.1",
                             "-n #{@name}",
                             config.install_dir,
                             "--post-install '#{package_scripts_path}/postinst'",
                             "--post-uninstall '#{package_scripts_path}/postrm'",
                             "-m 'Opscode, Inc.'",
                             "--description 'The full stack of #{@name}'",
                             "--url http://www.opscode.com"]

              @exclusions.each do |pattern|
                fpm_command << "--exclude '#{pattern}'"
              end

              shell = Mixlib::ShellOut.new(fpm_command.join(" "),
                                           :live_stream => STDOUT,
                                           :timeout => 3600,
                                           :cwd => './pkg')
              shell.run_command
              shell.error!
{'fraction_non_alphanumeric': 0.10120790629575403, 'fraction_numerical': 0.002562225475841874, 'mean_word_length': 1.2125506072874495, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2188762', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1402, 'n_words': 323}