/
filesystem_attrs.rb
194 lines (172 loc) · 5.68 KB
/
filesystem_attrs.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Copyright (c) [2020] 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 "cwm/custom_widget"
require "autoinstall/widgets/storage/filesystem"
require "autoinstall/widgets/storage/label"
require "autoinstall/widgets/storage/mount"
require "autoinstall/widgets/storage/mountby"
require "autoinstall/widgets/storage/mkfs_options"
require "autoinstall/widgets/storage/fstopt"
require "autoinstall/widgets/storage/create_subvolumes"
module Y2Autoinstallation
module Widgets
module Storage
# File system specific widgets
#
# It groups those attributes that are specific for a partition being used as file system.
#
# @see PartitionUsageTab
class FilesystemAttrs < CWM::CustomWidget
# Constructor
#
# @param section [Presenters::Partition] presenter for the partition section
def initialize(section)
textdomain "autoinst"
super()
@section = section
self.handle_all_events = true
end
# @macro seeAbstractWidget
def label
""
end
# @macro seeCustomWidget
def contents
if section.fstab_based?
VBox(*mount_widgets)
else
VBox(
*mount_widgets,
VSpacing(0.5),
*format_widgets
)
end
end
# @macro seeAbstractWidget
def init
filesystem_widget.value = section.filesystem
label_widget.value = section.label
mount_point_widget.value = section.mount
mountby_widget.value = section.mountby
fstab_options_widget.value = section.fstab_options
mkfs_options_widget.value = section.mkfs_options
create_subvolumes_widget.value = section.create_subvolumes
set_btrfs_attrs_status
end
# Returns the widgets values
#
# @return [Hash<String,Object>]
def values
{
"filesystem" => filesystem_widget.value,
"label" => label_widget.value,
"mount" => mount_point_widget.value,
"mountby" => mountby_widget.value,
"fstab_options" => fstab_options_widget.value,
"mkfs_options" => mkfs_options_widget.value,
"create_subvolumes" => btrfs? ? create_subvolumes_widget.value : nil
}
end
# @macro seeAbstractWidget
def handle(event)
set_btrfs_attrs_status if event["ID"] == filesystem_widget.widget_id
nil
end
private
# @return [Presenters::Partition] presenter for the partition section
attr_reader :section
# Whether selected files ystem is Btrfs
#
# @return [Boolean] true if selected file system is Btrfs; false otherwise
def btrfs?
filesystem_widget.value == :btrfs
end
# Update the Btrfs attrs status according to the value of #filesystem_widget
def set_btrfs_attrs_status
if btrfs?
create_subvolumes_widget.enable
else
create_subvolumes_widget.disable
end
end
# Widget for settings the filesystem type
def filesystem_widget
@filesystem_widget ||= Filesystem.new
end
# Widget for setting the partition label
def label_widget
@label_widget ||= Label.new
end
# Widget for selecting the partition mount point
def mount_point_widget
@mount_point_widget ||= Mount.new
end
# Widget for selecting the partition mount type
def mountby_widget
@mountby_widget ||= Mountby.new
end
# Widget for specifying fstab options
def fstab_options_widget
@fstab_options_widget ||= Fstopt.new
end
# Widget for specifying mkfs command options
def mkfs_options_widget
@mkfs_options_widget ||= MkfsOptions.new
end
# Widget for setting if Btrfs subvolumes should be created or not
def create_subvolumes_widget
@create_subvolumes_widget ||= CreateSubvolumes.new
end
# @see #contents
def format_widgets
[
Left(
HBox(
filesystem_widget,
HSpacing(2),
HSquash(MinWidth(15, label_widget))
)
),
VSpacing(0.5),
Left(
HSquash(MinWidth(35, mkfs_options_widget))
),
VSpacing(0.5),
Left(create_subvolumes_widget)
]
end
# @see #contents
def mount_widgets
[
Left(
HBox(
HSquash(MinWidth(15, mount_point_widget)),
HSpacing(2),
mountby_widget,
HSpacing(2),
HSquash(fstab_options_widget)
)
)
]
end
end
end
end
end