Class: Y2Packager::ReleaseNotesReader

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/packages/src/lib/y2packager/release_notes_reader.rb

Overview

This class is able to read release notes for a given product

It can use two different strategies or backends:

### How it works

We can distinguish two different case:

  • When the system *is registered*: release notes will be obtained from RPM packages. If release notes are not found there, it will fall back to the “relnotes_url” product property. This behaviour covers the case in which you are installing behind a SMT but without access to Internet.

  • When the system *is not registered*: it will work the other way around, trying first relnotes_url and falling back to RPM packages.

### Cached release notes

Release notes are stored using an instance of `Y2Packager::ReleaseNotesStore`. When trying to read a product release notes for second time, this class will try to fetch the latest version (determined by ReleaseNotesFetchers::Rpm#latest_version or ReleaseNotesFetchers::Url#latest_version from the store). If release notes are not there, or the stored version is outdated (maybe a new package is now available), it will try to get that version.

Take into account that, when using the relnotes_url property, an URL that already failed will not be retried again. See ReleaseNotesFetchers::Url for further details.

Constant Summary collapse

FALLBACK_LANG =

Fallback language

"en".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, release_notes_store = nil) ⇒ ReleaseNotesReader

Constructor

Parameters:

  • product (Product)

    Product to get release notes for

  • release_notes_store (ReleaseNotesStore) (defaults to: nil)

    Release notes store to cache data



63
64
65
66
# File 'library/packages/src/lib/y2packager/release_notes_reader.rb', line 63

def initialize(product, release_notes_store = nil)
  @release_notes_store = release_notes_store
  @product = product
end

Instance Attribute Details

#productObject (readonly)

Product to get release notes for



57
58
59
# File 'library/packages/src/lib/y2packager/release_notes_reader.rb', line 57

def product
  @product
end

Instance Method Details

#release_notes(user_lang: "en_US", format: :txt) ⇒ String?

Get release notes for a given product

Parameters:

  • user_lang (String)

    Release notes language (falling back to “en”)

  • format (Symbol)

    Release notes format (:txt or :rtf)

Returns:

  • (String, nil)

    Release notes or nil if release notes were not found (no package providing release notes or notes not found in the package)



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'library/packages/src/lib/y2packager/release_notes_reader.rb', line 77

def release_notes(user_lang: "en_US", format: :txt)
  readers =
    # registered system: get relnotes from RPMs and fallback to relnotes_url property
    if registered?
      [
        ReleaseNotesFetchers::Rpm.new(product),
        ReleaseNotesFetchers::Url.new(product)
      ]
    else # unregistered system: try relnotes first and fallback to RPMs
      [
        ReleaseNotesFetchers::Url.new(product),
        ReleaseNotesFetchers::Rpm.new(product)
      ]
    end

  prefs = ReleaseNotesContentPrefs.new(user_lang, FALLBACK_LANG, format)
  readers.each do |reader|
    rn = release_notes_via_reader(reader, prefs)
    return rn if rn
  end

  nil
end

#release_notes_via_reader(reader, prefs) ⇒ String?

Get release notes for a given product using a reader instance

Parameters:

Returns:

  • (String, nil)

    Release notes or nil if release notes were not found (no package providing release notes or notes not found in the package)

See Also:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'library/packages/src/lib/y2packager/release_notes_reader.rb', line 109

def release_notes_via_reader(reader, prefs)
  from_store = release_notes_store.retrieve(
    product.name, prefs.user_lang, prefs.format, reader.latest_version
  )

  if from_store
    log.info "Release notes for #{product.name} were found"
    return from_store
  end

  release_notes = reader.release_notes(prefs)

  if release_notes
    log.info "Release notes for #{product.name} were found"
    release_notes_store.store(release_notes)
  end

  release_notes
end