Sha256: 7eb4d9a96d182e3d35262506fd349fe551af7adcb653e713d782c9ebc1a88ec0

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

require 'iniparse'

module Zypper
  module Upgraderepo


    class OsRelease

      attr_reader :custom, :unstable

      OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1', '15.2', '15.3', '15.4']

      UNSTABLE_VERSION = '15.5'

      def initialize(options)

        if options.allow_unstable
          raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?
          OS_VERSIONS << UNSTABLE_VERSION
          @unstable = true
        end

        fname = if File.exist? '/etc/os-release'
                  '/etc/os-release'
                elsif File.exist? '/etc/SuSE-release'
                  '/etc/SuSE-release'
                else
                  raise ReleaseFileNotFound
                end
        @release = IniParse.parse(File.read(fname))
        @current_idx = OS_VERSIONS.index(@release['__anonymous__']['VERSION'].delete('"'))

        if options.version
          raise InvalidVersion, options.version unless OS_VERSIONS.include?(options.version)
          @custom = options.version
        end
      end

      def current
        OS_VERSIONS[@current_idx]
      end

      def last
        OS_VERSIONS[-1]
      end

      def next
        unless last?
          OS_VERSIONS[@current_idx.next]
        else
          nil
        end
      end

      def previous
        unless first?
          OS_VERSIONS[@current_idx.pred]
        else
          nil
        end
      end

      def fullname
        @release['__anonymous__']['PRETTY_NAME'].gsub(/"/, '')
      end

      def seniority
        OS_VERSIONS.count - @current_idx.next
      end

      def newer
        if seniority > 0
          OS_VERSIONS[@current_idx.next..-1]
        else
          []
        end
      end

      def last?
        @current_idx == (OS_VERSIONS.count - 1)
      end

      def first?
        @current_idx == 0
      end

      def valid?(version)
        OS_VERSIONS.include? version
      end

      def current?(version)
        OS_VERSIONS.index(version) == @current_idx
      end
    end


  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zypper-upgraderepo-1.7.1 lib/zypper/upgraderepo/os_release.rb
zypper-upgraderepo-1.7.0 lib/zypper/upgraderepo/os_release.rb
zypper-upgraderepo-1.6.2 lib/zypper/upgraderepo/os_release.rb
zypper-upgraderepo-1.6.1 lib/zypper/upgraderepo/os_release.rb