Class: Zypper::Upgraderepo::OsRelease

Inherits:
Object
  • Object
show all
Defined in:
lib/zypper/upgraderepo/os_release.rb

Overview

Detect the current and next release.

Constant Summary collapse

OS_VERSIONS =
["13.1", "13.2",
"42.1", "42.2", "42.3",
"15.0", "15.1", "15.2", "15.3", "15.4", "15.5", "15.6"].freeze
UNSTABLE_VERSION =
"16.0"
OS_RELEASE_FILE =
"/etc/os-release"
SUSE_RELEASE_FILE =
"/etc/SuSE-release"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ OsRelease

Returns a new instance of OsRelease.

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zypper/upgraderepo/os_release.rb', line 23

def initialize(options)
  if options.allow_unstable
    raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?

    OS_VERSIONS << UNSTABLE_VERSION
    @unstable = true
  end

  fname = if File.exist? self.class::OS_RELEASE_FILE
            self.class::OS_RELEASE_FILE
          elsif File.exist? self.class::SUSE_RELEASE_FILE
            self.class::SUSE_RELEASE_FILE
          else
            raise ReleaseFileNotFound
          end
  @release = IniParse.parse(File.read(fname))
  @current_idx = OS_VERSIONS.index(@release["__anonymous__"]["VERSION"].delete('"'))

  return unless options.version
  raise InvalidVersion, options.version unless OS_VERSIONS.include?(options.version)

  @custom = options.version
end

Instance Attribute Details

#customObject (readonly)

Returns the value of attribute custom.



11
12
13
# File 'lib/zypper/upgraderepo/os_release.rb', line 11

def custom
  @custom
end

#unstableObject (readonly)

Returns the value of attribute unstable.



11
12
13
# File 'lib/zypper/upgraderepo/os_release.rb', line 11

def unstable
  @unstable
end

Instance Method Details

#currentObject



47
48
49
# File 'lib/zypper/upgraderepo/os_release.rb', line 47

def current
  OS_VERSIONS[@current_idx]
end

#current?(version) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/zypper/upgraderepo/os_release.rb', line 95

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

#first?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/zypper/upgraderepo/os_release.rb', line 87

def first?
  @current_idx.zero?
end

#fullnameObject



67
68
69
# File 'lib/zypper/upgraderepo/os_release.rb', line 67

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

#lastObject



51
52
53
# File 'lib/zypper/upgraderepo/os_release.rb', line 51

def last
  OS_VERSIONS[-1]
end

#last?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/zypper/upgraderepo/os_release.rb', line 83

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

#newerObject



75
76
77
78
79
80
81
# File 'lib/zypper/upgraderepo/os_release.rb', line 75

def newer
  if seniority.positive?
    OS_VERSIONS[@current_idx.next..-1]
  else
    []
  end
end

#nextObject



55
56
57
58
59
# File 'lib/zypper/upgraderepo/os_release.rb', line 55

def next
  return if last?

  OS_VERSIONS[@current_idx.next]
end

#previousObject



61
62
63
64
65
# File 'lib/zypper/upgraderepo/os_release.rb', line 61

def previous
  return if first?

  OS_VERSIONS[@current_idx.pred]
end

#seniorityObject



71
72
73
# File 'lib/zypper/upgraderepo/os_release.rb', line 71

def seniority
  OS_VERSIONS.count - @current_idx.next
end

#valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/zypper/upgraderepo/os_release.rb', line 91

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