• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-autoinstallation / 7347071288

28 Dec 2023 11:13AM UTC coverage: 69.009% (+0.4%) from 68.607%
7347071288

push

github

web-flow
Merge pull request #874 from yast/rubocop_update

Rubocop update

94 of 254 new or added lines in 51 files covered. (37.01%)

22 existing lines in 13 files now uncovered.

6373 of 9235 relevant lines covered (69.01%)

10.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.82
/src/modules/AutoinstFile.rb
1
# File:  modules/AutoinstFile.ycp
2
# Package:  AutoYaST
3
# Authors:  Anas Nashif (nashif@suse.de)
4
# Summary:  Handle complete configuration file dumps
5
#
6
# $Id$
7
require "yast"
1✔
8

9
module Yast
1✔
10
  class AutoinstFileClass < Module
1✔
11
    def main
1✔
12
      textdomain "autoinst"
1✔
13

14
      Yast.import "AutoinstConfig"
1✔
15
      Yast.import "Installation"
1✔
16
      Yast.import "Summary"
1✔
17

18
      Yast.include self, "autoinstall/io.rb"
1✔
19

20
      # default value of settings modified
21
      @modified = false
1✔
22

23
      @Files = []
1✔
24
    end
25

26
    # Function sets internal variable, which indicates, that any
27
    # settings were modified, to "true"
28
    def SetModified
1✔
29
      Builtins.y2milestone("SetModified")
×
30
      @modified = true
×
31

32
      nil
33
    end
34

35
    # Functions which returns if the settings were modified
36
    # @return [Boolean]  settings were modified
37
    def GetModified
1✔
38
      @modified
×
39
    end
40

41
    # Settings Summary
42
    def Summary
1✔
43
      summary = ""
×
44
      summary = Summary.AddHeader(summary, _("Configured Files:"))
×
45
      if Ops.greater_than(Builtins.size(@Files), 0)
×
46
        summary = Summary.OpenList(summary)
×
47
        Builtins.foreach(@Files) do |file|
×
48
          summary = Summary.AddListItem(
×
49
            summary,
50
            Ops.get_string(file, "file_path", "")
51
          )
52
        end
53
        summary = Summary.CloseList(summary)
×
54
      else
55
        summary = Summary.AddLine(summary, Summary.NotConfigured)
×
56
      end
57
      summary
×
58
    end
59

60
    # Import Settings
61
    def Import(settings)
1✔
62
      settings = deep_copy(settings)
3✔
63
      @Files = deep_copy(settings)
3✔
64
      true
3✔
65
    end
66

67
    # Export Settings
68
    def Export
1✔
69
      deep_copy(@Files)
×
70
    end
71

72
    # Write Settings
73
    def Write
1✔
74
      Yast.import "AutoInstall"
3✔
75
      Builtins.y2milestone("Writing Files to the system")
3✔
76
      return true if Builtins.size(@Files) == 0
3✔
77

78
      counter = 0
3✔
79
      success = false
3✔
80

81
      Builtins.foreach(@Files) do |file|
3✔
82
        alternate_location = Builtins.sformat(
4✔
83
          "%1/%2",
84
          AutoinstConfig.files_dir,
85
          counter
86
        )
87
        if Ops.subtract(
4✔
88
          Builtins.size(Ops.get_string(file, "file_path", "dummy")),
89
          1
90
        ) ==
91
            Builtins.findlastof(Ops.get_string(file, "file_path", ""), "/")
92
          # directory
93
          SCR.Execute(
2✔
94
            path(".target.mkdir"),
95
            Ops.get_string(file, "file_path", alternate_location)
96
          )
97
        elsif Ops.get_string(file, "file_contents", "") != ""
2✔
98
          Builtins.y2milestone(
1✔
99
            "AutoInstall: Copying file %1",
100
            Ops.get_string(file, "file_path", alternate_location)
101
          )
102
          SCR.Write(
1✔
103
            path(".target.string"),
104
            Ops.get_string(file, "file_path", alternate_location),
105
            Ops.get_string(file, "file_contents", "")
106
          )
107
        elsif Ops.get_string(file, "file_location", "") != ""
1✔
108
          if Builtins.issubstring(
1✔
109
            Ops.get_string(file, "file_location", ""),
110
            "relurl://"
111
          )
112
            l = Ops.get_string(file, "file_location", "")
×
113
            l = Builtins.substring(l, 9)
×
114
            newloc = ""
×
115
            if AutoinstConfig.scheme == "relurl"
×
116
              Builtins.y2milestone("autoyast profile was relurl too")
×
117
              newloc = Convert.to_string(
×
118
                SCR.Read(path(".etc.install_inf.ayrelurl"))
119
              )
120
              tok = URL.Parse(newloc)
×
121
              Builtins.y2milestone("tok = %1", tok)
×
122
              newloc = Ops.add(
×
123
                Ops.add(
124
                  Ops.add(
125
                    Ops.add(
126
                      Ops.add(Ops.get_string(tok, "scheme", ""), "://"),
127
                      Ops.get_string(tok, "host", "")
128
                    ),
129
                    "/"
130
                  ),
131
                  dirname(Ops.get_string(tok, "path", ""))
132
                ),
133
                l
134
              )
135
            else
136
              newloc = Ops.add(
×
137
                Ops.add(
138
                  Ops.add(
139
                    Ops.add(
140
                      Ops.add(AutoinstConfig.scheme, "://"),
141
                      AutoinstConfig.host
142
                    ),
143
                    "/"
144
                  ),
145
                  AutoinstConfig.directory
146
                ),
147
                l
148
              )
149
            end
150
            Ops.set(file, "file_location", newloc)
×
151
            Builtins.y2milestone("changed relurl to %1 for file", newloc)
×
152
          end
153
          file_location = File.join(Installation.destdir, file["file_path"] || alternate_location)
1✔
154
          Builtins.y2milestone(
1✔
155
            "trying to get file from %1 storing in %2",
156
            Ops.get_string(file, "file_location", ""),
157
            file_location
158
          )
159
          if GetURL(
1✔
160
            Ops.get_string(file, "file_location", ""),
161
            file_location
162
          )
UNCOV
163
            Builtins.y2milestone("file was retrieved")
×
164
          else
165
            Builtins.y2error("file could not be retrieved")
1✔
166
          end
167
        end
168
        if Ops.get_string(file, "file_permissions", "") != ""
4✔
169
          SCR.Execute(
3✔
170
            path(".target.bash"),
171
            Builtins.sformat(
172
              "chmod %1 %2",
173
              Ops.get_string(file, "file_permissions", ""),
174
              Ops.get_string(file, "file_path", alternate_location)
175
            )
176
          )
177
        end
178
        if Ops.get_string(file, "file_owner", "") != ""
4✔
179
          SCR.Execute(
3✔
180
            path(".target.bash"),
181
            Builtins.sformat(
182
              "chown %1 %2",
183
              Ops.get_string(file, "file_owner", ""),
184
              Ops.get_string(file, "file_path", alternate_location)
185
            )
186
          )
187
        end
188
        script = Ops.get_map(file, "file_script", {})
4✔
189
        if script != {}
4✔
190
          current_logdir = AutoinstConfig.logs_dir
×
191
          name_tok = Builtins.splitstring(
×
192
            Ops.get_string(file, "file_path", alternate_location),
193
            "/"
194
          )
195
          scriptName = ""
×
196
          if Ops.greater_than(Builtins.size(name_tok), 0)
×
197
            name = Ops.get_string(
×
198
              name_tok,
199
              Ops.subtract(Builtins.size(name_tok), 1),
200
              ""
201
            )
202
            scriptName = Ops.add("script_", name)
×
203
          end
204
          scriptPath = Builtins.sformat(
×
205
            "%1/%2",
206
            AutoinstConfig.scripts_dir,
207
            scriptName
208
          )
209
          Builtins.y2milestone("Writing (file) script into %1", scriptPath)
×
210
          got_script = false
×
211
          if Ops.get_string(script, "location", "") != ""
×
212
            Builtins.y2milestone(
×
213
              "getting script: %1",
214
              Ops.get_string(script, "location", "")
215
            )
NEW
216
            if GetURL(Ops.get_string(script, "location", ""), scriptPath)
×
NEW
217
              got_script = true
×
218
            else
UNCOV
219
              Builtins.y2error(
×
220
                "script %1 could not be retrieved",
221
                Ops.get_string(script, "location", "")
222
              )
223
            end
224
          end
225
          if !got_script
×
226
            SCR.Write(
×
227
              path(".target.string"),
228
              scriptPath,
229
              Ops.get_string(script, "source", "echo Empty script!")
230
            )
231
          end
232
          scriptInterpreter = Ops.get_string(script, "interpreter", "shell")
×
233
          executionString = ""
×
NEW
234
          case scriptInterpreter
×
235
          when "shell"
UNCOV
236
            executionString = Builtins.sformat(
×
237
              "/bin/sh -x %1  2&> %2/%3.log",
238
              scriptPath,
239
              current_logdir,
240
              scriptName
241
            )
242
            SCR.Execute(path(".target.bash"), executionString)
×
243
          when "perl"
244
            executionString = Builtins.sformat(
×
245
              "/usr/bin/perl %1  2&> %2/%3.log",
246
              scriptPath,
247
              current_logdir,
248
              scriptName
249
            )
250
            SCR.Execute(path(".target.bash"), executionString)
×
251
          when "python"
252
            executionString = Builtins.sformat(
×
253
              "/usr/bin/python %1  2&> %2/%3.log",
254
              scriptPath,
255
              current_logdir,
256
              scriptName
257
            )
258
            SCR.Execute(path(".target.bash"), executionString)
×
259
          else
260
            Builtins.y2error("Unknown interpreter: %1", scriptInterpreter)
×
261
          end
262
          Builtins.y2milestone("Script Execution command: %1", executionString)
×
263
        end
264
        success = SCR.Execute(
4✔
265
          path(".target.bash"),
266
          Builtins.sformat(
267
            "cp %1 %2",
268
            Ops.get_string(file, "file_path", alternate_location),
269
            AutoinstConfig.files_dir
270
          )
271
        ) == 0
272
        counter = Ops.add(counter, 1)
4✔
273
      end
274
      success
3✔
275
    end
276

277
    publish variable: :modified, type: "boolean"
1✔
278
    publish function: :SetModified, type: "void ()"
1✔
279
    publish function: :GetModified, type: "boolean ()"
1✔
280
    publish variable: :Files, type: "list <map>"
1✔
281
    publish function: :Summary, type: "string ()"
1✔
282
    publish function: :Import, type: "boolean (list <map>)"
1✔
283
    publish function: :Export, type: "list <map> ()"
1✔
284
    publish function: :Write, type: "boolean ()"
1✔
285
  end
286

287
  AutoinstFile = AutoinstFileClass.new
1✔
288
  AutoinstFile.main
1✔
289
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc