-
Notifications
You must be signed in to change notification settings - Fork 19
/
feature.rb
123 lines (106 loc) · 3.55 KB
/
feature.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright (c) [2023] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require "yast"
require "storage"
module Y2Storage
# Generalization of the concept of {StorageFeature}.
#
# In libstorage-ng the concept of "feature" is used to communicate the usage of some
# functionality that may require the presence in the system of some packages and tools.
#
# The sibling concept of {YastFeature} makes it possible for Y2Storage to add its own
# requirements.
#
# This is the abstract base class for both.
class Feature
include Yast::Logger
# Constructor
#
# @param id [Symbol] see {#id}
# @param packages [Array<Package>] see {#all_packages}
def initialize(id, packages)
@id = id
@all_packages = packages
end
# Symbol representation of the feature
#
# For StorageFeature objects, this has the same form than the corresponding constant
# name in libstorage-ng, eg. :UF_NTFS
#
# @return [Symbol]
attr_reader :id
alias_method :to_sym, :id
# Names of the packages that should be installed if the feature is going to be used
#
# @return [Array<String>]
def pkg_list
packages.map(&:name)
end
# Drop the cache about which packages related to the feature are available
def drop_cache
@packages = nil
end
private
# All packages that would be relevant for the feature, no matter if they are really available
# @return [Array<Feature::Package>]
attr_reader :all_packages
# List of available packages associated to the feature
#
# @return [Array<Feature::Package>]
def packages
return @packages unless @packages.nil?
unavailable, @packages = all_packages.partition(&:unavailable_optional?)
if unavailable.any?
log.warn("WARNING: Skipping unavailable support packages #{unavailable.map(&:name)}")
end
@packages
end
# Internal class to represent a package associated to a feature
class Package
Yast.import "Package"
# Constructor
#
# @param name [String] see {#name}
# @param optional [Boolean] see {#optional?}
def initialize(name, optional: false)
@name = name
@optional = optional
end
# @return [String] name of the package
attr_reader :name
# Whether installation of the package can be skipped if the package is not
# available
#
# See the comment in {StorageFeature::OPTIONAL_PACKAGES} for more details
#
# @return [Boolean]
def optional?
!!@optional
end
# Check if a package is an optional package that is unavailable.
# See also bsc#1039830
#
# @return [Boolean] true if package is optional and unavailable,
# false if not optional or if available.
def unavailable_optional?
optional? && !Yast::Package.Available(name)
end
end
end
end