<commit_before># LinuxAdmin Distro Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

require 'linux_admin/etc_issue'

class LinuxAdmin
  module Distros
    def self.generic
      @generic ||= Generic.new
    end

    def self.rhel
      @rhel ||= RHEL.new
    end

    def self.fedora
      @fedora ||= Fedora.new
    end

    def self.ubuntu
      @ubuntu ||= Ubuntu.new
    end

    def self.all
      @distros ||= [rhel, fedora, ubuntu, generic]
    end

    def self.local
      @local ||= begin
        Distros.all.detect(&:detected?) || Distros.generic
      end
    end

    class Distro
      attr_accessor :commands, :release_file, :etc_issue_keywords, :info_class

      def initialize(commands, release_file = nil, etc_issue_keywords = [], info_class = nil)
        @commands           = commands
        @release_file       = release_file
        @etc_issue_keywords = etc_issue_keywords
        @info_class         = info_class
      end

      def id
        @id ||= self.class.name.downcase.to_sym
      end

      def detected?
        detected_by_etc_issue? || detected_by_etc_release?
      end

      def detected_by_etc_issue?
        etc_issue_keywords && etc_issue_keywords.any? { |k| EtcIssue.instance.include?(k) }
      end

      def detected_by_etc_release?
        release_file && File.exists?(release_file)
      end

      def command(name)
        commands[name]
      end

      def info(pkg)
        info_class ? info_class.info(pkg) : nil
      end
    end

    class Generic < Distro
      def initialize
        super({})
      end
    end

    class RedHat < Distro
      def initialize(extra_commands, release_file, etc_issue_keywords)
        super({
          :service   => '/sbin/service',
          :chkconfig => '/sbin/chkconfig',
          :parted    => '/sbin/parted',
          :mount     => '/bin/mount',
          :umount    => '/bin/umount',
          :shutdown  => '/sbin/shutdown',
          :mke2fs    => '/sbin/mke2fs',
          :fdisk     => '/sbin/fdisk',
          :dd        => '/bin/dd',
          :vgdisplay => '/sbin/vgdisplay',
          :pvdisplay => '/sbin/pvdisplay',
          :lvdisplay => '/sbin/lvdisplay',
          :lvextend  => '/sbin/lvextend',
          :vgextend  => '/sbin/vgextend',
          :lvcreate  => '/sbin/lvcreate',
          :pvcreate  => '/sbin/pvcreate',
          :vgcreate  => '/sbin/vgcreate'
          }.merge(extra_commands), release_file, etc_issue_keywords, LinuxAdmin::Rpm)
      end
    end

    class RHEL < RedHat
      def initialize
        super({:rpm => '/bin/rpm'}, '/etc/redhat-release', ['red hat','centos'])
      end

      # def detected?
      #   super || File.exists?("/etc/redhat-release")
      # end
    end

    class Fedora < RedHat
      def initialize
        super({:rpm => '/usr/bin/rpm'}, "/etc/fedora-release", ['Fedora'])
      end
    end

    class Ubuntu < Distro
      def initialize
        super({}, nil, ['ubuntu'], LinuxAdmin::Deb)
      end
    end
  end
end<commit_msg>use a PATH instead of hardcoding commands<commit_after># LinuxAdmin Distro Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

require 'linux_admin/etc_issue'

class LinuxAdmin
  module Distros
    def self.generic
      @generic ||= Generic.new
    end

    def self.rhel
      @rhel ||= RHEL.new
    end

    def self.fedora
      @fedora ||= Fedora.new
    end

    def self.ubuntu
      @ubuntu ||= Ubuntu.new
    end

    def self.all
      @distros ||= [rhel, fedora, ubuntu, generic]
    end

    def self.local
      @local ||= begin
        Distros.all.detect(&:detected?) || Distros.generic
      end
    end

    class Distro
      attr_accessor :release_file, :etc_issue_keywords, :info_class

      def initialize(release_file = nil, etc_issue_keywords = [], info_class = nil)
        @path               = %w(/sbin /bin /usr/bin /usr/sbin)
        @release_file       = release_file
        @etc_issue_keywords = etc_issue_keywords
        @info_class         = info_class
      end

      def id
        @id ||= self.class.name.downcase.to_sym
      end

      def detected?
        detected_by_etc_issue? || detected_by_etc_release?
      end

      def detected_by_etc_issue?
        etc_issue_keywords && etc_issue_keywords.any? { |k| EtcIssue.instance.include?(k) }
      end

      def detected_by_etc_release?
        release_file && File.exists?(release_file)
      end

      def command(name)
        @path.collect { |dir| "#{dir}/#{name}" }.detect { |cmd| File.exists?(cmd) }
      end

      def info(pkg)
        info_class ? info_class.info(pkg) : nil
      end
    end

    class Generic < Distro
      def initialize
        super()
      end
    end

    class RedHat < Distro
      def initialize(release_file, etc_issue_keywords)
        super(release_file, etc_issue_keywords, LinuxAdmin::Rpm)
      end
    end

    class RHEL < RedHat
      def initialize
        super('/etc/redhat-release', ['red hat','centos'])
      end

      # def detected?
      #   super || File.exists?("/etc/redhat-release")
      # end
    end

    class Fedora < RedHat
      def initialize
        super("/etc/fedora-release", ['Fedora'])
      end
    end

    class Ubuntu < Distro
      def initialize
        super(nil, ['ubuntu'], LinuxAdmin::Deb)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11100763643136524, 'fraction_numerical': 0.0018625442354255914, 'mean_word_length': 2.008403361344538, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, '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': '4521236', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1679, 'n_words': 389}