class Solaris::PatchdiagEntry

Class to represent a line from Sun’s patchdiag.xref patch “database”. See the following Oracle support publication for format: support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=REFERENCE&id=1019527.1

Attributes

archs[RW]

An array of architectures for this patch. Values are strings like “sparc”, “i386”.

bad[RW]

The bad field from the patchdiag xref database. Should be either ‘B’ or the empty string. See also #bad? (and #y2k? since these flags share the same column in patchdiag.xref).

date[RW]

The date of this patch (a Date object).

os[RW]

The operating system for this patch, a string like “2.4, ”10“, ”10_x86“ or ”Unbundled“.

patch[RW]

The patch object (class Patch) that this entry represents. See also convenience methods #major and #minor.

pkgs[RW]

An array of packages that pertain to this patch. Values are strings like “SUNWcsr”.

security[RW]

The security field from the patchdiag xref database. Should be either ‘S’ or the empty string. See also #security?

synopsis[RW]

This synopsis of this patch from the patchdiag xref database. This is a free text field (string).

y2k[RW]

The year 2000 field from the patchdiag xref database. Should be either ‘Y’ or the empty string. See also #y2k? (and #bad? since these flags share the same column in patchdiag.xref).

Public Class Methods

new(patchdiag_line) click to toggle source
# File lib/solaris/patchdiag_entry.rb, line 59
def initialize(patchdiag_line)
  fields = patchdiag_line.split( '|', 11 )
  major, minor, date, @recommended, @security, @obsolete, bad, @os, archs, pkgs, @synopsis = *fields
  @archs = archs.split( ';' )
  if date == ''
    year, month, day = 1970, 1, 1
  else
    month_s, day_s, year_s = *date.split( '/' )
    year = ( year_s.to_i > 50 ? "19#{year_s}" : "20#{year_s}" ).to_i
    month = Date::ABBR_MONTHNAMES.index( month_s )
    day = day_s.to_i
  end
  @bad = bad =~ %rB/ ? 'B' : ' '
  @y2k = bad =~ %rY/ ? 'Y' : ' '
  @date = Date.new( year, month, day )
  @patch = Patch.new( major, minor )
  @pkgs = pkgs.split( ';' )
  @synopsis.chomp!
end

Public Instance Methods

<=>(other) click to toggle source

Compare (by delegated comparison of patch versions, see Solaris::Patch#<=>).

# File lib/solaris/patchdiag_entry.rb, line 174
def <=>(other)
  self.patch <=> other.patch
end
bad?() click to toggle source

Boolean, returns true if this patch is marked as “bad” in the patchdiag xref database.

# File lib/solaris/patchdiag_entry.rb, line 81
def bad? ; @bad == 'B' end
download_patch!(opts={}) click to toggle source

Download this patch. For options hash see Solaris::Patch#download!.

# File lib/solaris/patchdiag_entry.rb, line 84
def download_patch!(opts={}) ;
  @patch.download_patch!( opts )
end
download_readme!(opts={}) click to toggle source

Download the README for this patch. For options hash see Solaris::Patch#download!.

# File lib/solaris/patchdiag_entry.rb, line 89
def download_readme!(opts={})
  @patch.download_readme!( opts )
end
major() click to toggle source

Returns this entries major patch number as an integer.

# File lib/solaris/patchdiag_entry.rb, line 94
def major ; @patch.major end
minor() click to toggle source

Returns this entries minor patch number as an integer.

# File lib/solaris/patchdiag_entry.rb, line 97
def minor ; @patch.minor end
obsolete?() click to toggle source

Boolean, returns true if this patch is marked as “obsolete” in the patchdiag xref database.

# File lib/solaris/patchdiag_entry.rb, line 101
def obsolete? ; @obsolete == 'O' end
security?() click to toggle source

Boolean, returns true if this patch is marked as “security” in the patchdiag xref database.

# File lib/solaris/patchdiag_entry.rb, line 109
def security? ; @security == 'S' end
successor() click to toggle source

Return the Solaris::Patch by which this entry is obsoleted. Throws Solaris::Patch::NotObsolete if this entry is not obsolete. Throws Solaris::Patch::MultipleSuccessors if this entry has more than one successor. Throws Solaris::Patch::InvalidSuccessor if the “obsoleted by” entry cannot be understood.

# File lib/solaris/patchdiag_entry.rb, line 117
def successor
  # I <3 consistency:
  # Obsoleted by : XXXXXX-XX
  # Obsoleted by: XXXXXX-XX
  # OBSOLETED by: XXXXXX
  # Obsoleted by: XXXXXX-XX OBSOLETED by WITHDRAWN
  # OBSOLETED by WITHDRAWN
  # OBSOLETED by XXXXXX
  # OBSOLETED by XXXXXX and XXXXXX # we ignore this pattern, see below
  # Obsoleted by XXXXXX-XX:
  # OBSOLETED by XXXXXX-XX:
  # WITHDRAWN Obsoleted by: XXXXXX-XX
  # WITHDRAWN PATCH Obsolete by:
  # WITHDRAWN PATCH Obsoleted by:
  # WITHDRAWN PATCH Obsoleted by XXXXXX-XX:

  # Fail if this entry is not actually obsolete
  raise Solaris::Patch::NotObsolete,
    "Entry #{patch.inspect} not obsolete" unless obsolete?

  # Fail if this entry is obsoleted by two patches (currently 2011/05/04
  # only 105716 and 105717)
  raise Solaris::Patch::MultipleSuccessors,
    "More than one successor for entry #{patch.inspect}" if synopsis =~ %robsolete(d?) by\s*(:?)\s*(\d+(-\d+)?)\s+and\s+(\d+(-\d+)?)/

  # See if we can find a successor
  if synopsis =~ %robsolete(d?) by\s*(:?)\s*(\d+(-\d+)?)/
    Patch.new( $3 )
  else
    raise Solaris::Patch::InvalidSuccessor,
      "Failed to parse successor to obsolete patchdiag entry for patch #{patch.inspect}"
  end
end
to_s() click to toggle source

Output this patchdiag xref entry as a string, in format of Oracle’s database.

# File lib/solaris/patchdiag_entry.rb, line 153
def to_s
  [ patch.major,
    Patch.pad_minor( patch.minor ),
    date_s,
    @recommended,
    @security,
    @obsolete,
    @bad + @y2k,
    @os,
    join_semis( @archs ),
    join_semis( @pkgs ),
    @synopsis
  ].join('|')
end
Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s
y2k?() click to toggle source

Boolean, returns true if this patch is marked as a year 2000 patch in the patchdiag xref database.

# File lib/solaris/patchdiag_entry.rb, line 171
def y2k? ; @y2k == 'Y' end

Private Instance Methods

date_s() click to toggle source

Convert the Date object to a date string as found in patchdiag.xref.

# File lib/solaris/patchdiag_entry.rb, line 181
def date_s
  [ Date::ABBR_MONTHNAMES[ @date.mon ], # month eg Jan
    @date.mday.to_s.rjust(2, '0'), # day of month
    @date.year % 100 # 2 digit year
  ].join('/')
end
join_semis(a) click to toggle source

Join an array of items with semicolons and append a trailing semicolon if the array is non-empty, otherwise return the empty string. Used to format @archs and @pkgs for to_s.

# File lib/solaris/patchdiag_entry.rb, line 191
def join_semis(a)
  a.empty? ? '' : a.join(';') + ';'
end