Module: Yast::ProductCreatorCommandlineInclude

Defined in:
../../src/include/product-creator/commandline.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) callbackTrue_boolean_map_integer(dummy_map, dummy)

dummy function to return true when callback is invoked (from AutoInstall.ycp)



47
48
49
50
# File '../../src/include/product-creator/commandline.rb', line 47

def callbackTrue_boolean_map_integer(dummy_map, dummy)
  dummy_map = deep_copy(dummy_map)
  true
end

- (Object) CreateConfigHandler(params)

Command line handler for Create Config action: create new product configuration



312
313
314
315
316
317
318
# File '../../src/include/product-creator/commandline.rb', line 312

def CreateConfigHandler(params)
  params = deep_copy(params)
  Builtins.y2milestone("CreateConfigHandler parameters: %1", params)
  ProcessConfigFileOption(params)

  ProcessParameters(params, "create")
end

- (Object) CreateIsoHandler(params)

Command line handler for Create ISO action



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File '../../src/include/product-creator/commandline.rb', line 223

def CreateIsoHandler(params)
  params = deep_copy(params)
  Builtins.y2milestone("CreateIsoHandler parameters: %1", params)

  ProcessConfigFileOption(params)

  name = Ops.get_string(params, "name", "")

  if name != ""
    CommandLine.PrintVerbose(
      Builtins.sformat(_("Loading configuration %1..."), name)
    )
    # load the requested configuration

    if !ProductCreator.LoadConfig(name)
      # command line error message
      CommandLine.Print(
        Builtins.sformat(_("Cannot load configuration %1."), name)
      )
      return false
    end

    file = Ops.get_string(params, "passphrase_file", "")
    if file != nil && file != ""
      Builtins.y2milestone("Reading passphrase from file %1...", file)
      ProductCreator.gpg_passphrase = Convert.to_string(
        SCR.Read(path(".target.string"), file)
      )
    end

    if Builtins.haskey(params, "passphrase")
      ProductCreator.gpg_passphrase = Ops.get_string(
        params,
        "passphrase",
        ""
      )
    end

    # disable the progress
    progress = Progress.set(false)

    # verify the destination
    if VerifyDialog() != :next
      # command line error message
      CommandLine.Print("Cannot verify the destination")
      return false
    end

    # copy packages, create ISO image
    TreeDialog()

    # reset the passphrase
    ProductCreator.gpg_passphrase = ""

    iso_name = Ops.add(
      Ops.add(
        Ops.get_string(ProductCreator.Config, "iso-directory", ""),
        "/"
      ),
      Ops.get_string(ProductCreator.Config, "isofile", "")
    )
    image_size = Convert.to_integer(
      SCR.Read(path(".target.size"), iso_name)
    )
    if Ops.less_than(SCR.Read(path(".target.size"), iso_name), 0)
      # command line error message (%1 is path)
      CommandLine.Print(
        Builtins.sformat(_("Cannot create ISO image %1."), iso_name)
      )
      return false
    else
      # command line info message
      CommandLine.Print(
        Builtins.sformat(_("ISO image %1 has been written."), iso_name)
      )
    end

    Progress.set(progress)
  else
    # command line error message
    Report.Error(_("Configuration name cannot be empty."))
    return false
  end

  true
end

- (Object) DeleteConfigHandler(params)

Command line handler for Delete Config action



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File '../../src/include/product-creator/commandline.rb', line 321

def DeleteConfigHandler(params)
  params = deep_copy(params)
  Builtins.y2milestone("DeleteConfigHandler parameters: %1", params)
  name = Ops.get_string(params, "name", "")

  if name == ""
    # command line error message
    Report.Error(_("Configuration name is missing."))
    return false
  end
  ProductCreator.Configs = Builtins.filter(ProductCreator.Configs) do |k, v|
    k != name
  end
  true
end

- (Object) EditConfigHandler(params)

Command line handler for Edit Config action



338
339
340
341
342
343
344
# File '../../src/include/product-creator/commandline.rb', line 338

def EditConfigHandler(params)
  params = deep_copy(params)
  Builtins.y2milestone("EditConfigHandler parameters: %1", params)
  ProcessConfigFileOption(params)

  ProcessParameters(params, "edit")
end

- (Object) initialize_product_creator_commandline(include_target)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File '../../src/include/product-creator/commandline.rb', line 30

def initialize_product_creator_commandline(include_target)
  Yast.import "Pkg"
  Yast.import "UI"
  Yast.import "CommandLine"
  Yast.import "FileUtils"
  Yast.import "Progress"
  Yast.import "ProductCreator"
  Yast.import "RichText"
  Yast.import "SourceManager"
  Yast.import "Report"

  Yast.include include_target, "product-creator/complex.rb"

  textdomain "product-creator"
end

- (Object) ListHandler(params)

Command line handler for List action: list available configurations



210
211
212
213
214
215
216
217
218
219
220
# File '../../src/include/product-creator/commandline.rb', line 210

def ListHandler(params)
  params = deep_copy(params)
  ProcessConfigFileOption(params)

  Builtins.foreach(ProductCreator.Configs) do |name, conf|
    CommandLine.Print(name)
  end 


  false # = do not try to write
end

- (Object) ProcessConfigFileOption(params)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File '../../src/include/product-creator/commandline.rb', line 52

def ProcessConfigFileOption(params)
  params = deep_copy(params)
  if Builtins.haskey(params, "configfile")
    new_config = Ops.get_string(params, "configfile", "")

    if new_config != nil && new_config != ""
      Builtins.y2milestone("Using config file: %1", new_config)

      # TODO FIXME: set the config file path in "initialize" handler,
      # don't read the default config file if the "configfile" option is used
      ProductCreator.ConfigFile = new_config
      ProductCreator.Read
    end
  end

  nil
end

- (Object) ProcessParameters(params, action)

Go through the command line parameters map, verify the validity and fill appropriate gloal values

Parameters:

  • params (Hash)

    map with command line parameters

  • action (String)

    for what action are the parameters intended (create/edit)



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
195
196
197
198
199
200
201
202
203
204
205
206
207
# File '../../src/include/product-creator/commandline.rb', line 74

def ProcessParameters(params, action)
  params = deep_copy(params)
  name = Ops.get_string(params, "name", "")
  if name == ""
    # command line error message
    Report.Error(_("Configuration name is missing."))
    return false
  end
  _Config = { "name" => name }

  if action != "create" && !Builtins.haskey(ProductCreator.Configs, name)
    # command line error message, %1 is a name
    Report.Error(Builtins.sformat(_("There is no configuration %1."), name))
    return false
  end
  if action == "edit" || action == "show"
    ProductCreator.LoadConfig(name)
    _Config = deep_copy(ProductCreator.Config)
  end
  return true if action == "show"

  # first, handle required parameters
  if Ops.get_string(params, "output_dir", "") != ""
    Ops.set(
      _Config,
      "iso-directory",
      Ops.get_string(params, "output_dir", "")
    )
  elsif action == "create"
    # command line error message
    Report.Error(_("Path to output directory is missing."))
    return false
  end

  repos = Builtins.splitstring(
    Ops.get_string(params, "repositories", ""),
    ","
  )
  if repos != []
    Ops.set(_Config, "sources", repos)
  elsif action == "create"
    # command line error message
    Report.Error(_("List of package repositories is empty."))
    return false
  end

  if Ops.get_string(params, "profile", "") != ""
    Ops.set(_Config, "profile", Ops.get_string(params, "profile", ""))
  elsif action == "create"
    # command line error message
    Report.Error(_("Path to AutoYaST profile is missing."))
    return false
  end
  if Builtins.haskey(params, "copy_profile")
    Ops.set(_Config, "copy_profile", true)
  end

  # there is no manual way for selecting packages:
  if action == "create" || Ops.get_string(params, "profile", "") != ""
    Ops.set(_Config, "pkgtype", "autoyast")
    ProductCreator.profile_parsed = false
  end

  if Ops.get_string(params, "iso_name", "") != ""
    Ops.set(_Config, "isofile", Ops.get_string(params, "iso_name", ""))
  elsif action == "create"
    Ops.set(_Config, "isofile", Ops.add(name, ".iso"))
  end

  if Builtins.haskey(params, "create_iso")
    Ops.set(_Config, "result", "iso")
  elsif action == "create"
    Ops.set(_Config, "result", "tree")
  end

  if Builtins.haskey(params, "savespace")
    Ops.set(_Config, "savespace", true)
  end

  if Ops.get_string(params, "gpg_key", "") != ""
    Ops.set(_Config, "gpg_key", Ops.get_string(params, "gpg_key", ""))
  end

  # no selections
  Ops.set(_Config, "type", :patterns) if action == "create"

  if Ops.get_string(params, "isolinux_path", "") != ""
    file = Ops.get_string(params, "isolinux_path", "")
    if !FileUtils.Exists(file)
      # command line error message
      Report.Error(Builtins.sformat(_("File %1 does not exist."), file))
      return false
    end
    if Ops.greater_than(SCR.Read(path(".target.size"), file), 0)
      cont = Convert.to_string(SCR.Read(path(".target.string"), file))
      Ops.set(_Config, "bootconfig", cont) if cont != nil
    end
  end

  ProductCreator.Config = deep_copy(_Config)

  # read default isolinux (Config needs to be saved already to
  # ProductCreator::Config, it is used by Readisolinux)
  if Ops.get_string(params, "isolinux_path", "") == "" && action == "create"
    Ops.set(
      ProductCreator.Config,
      "bootconfig",
      ProductCreator.Readisolinux
    )
  end

  if action != "show"
    # initialize the sources before commiting configuration

    ProductCreator.ResetArch
    # unload all active sources (reset the internal state, see bnc#469191)
    Pkg.SourceFinishAll

    SourceManager.ReadSources

    # automatically import GPG keys when adding repository
    Pkg.CallbackImportGpgKey(
      fun_ref(
        method(:callbackTrue_boolean_map_integer),
        "boolean (map <string, any>, integer)"
      )
    )
  end

  # save the new configuration into global map, parse autoyast profile
  ProductCreator.CommitConfig

  nil
end

- (Object) ShowConfigHandler(params)

Command line handler for Show Config action



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File '../../src/include/product-creator/commandline.rb', line 347

def ShowConfigHandler(params)
  params = deep_copy(params)
  Builtins.y2milestone("EditConfigHandler parameters: %1", params)
  ProcessConfigFileOption(params)
  return false if !ProcessParameters(params, "show")

  # summary caption
  CommandLine.Print(_("Package Source"))
  Builtins.foreach(Ops.get_list(ProductCreator.Config, "sources", [])) do |s|
    CommandLine.Print(Ops.add("* ", s))
  end


  #         // summary line (%1 is number)
  #         CommandLine::Print (sformat(_("Selected %1 packages"),
  #     size (ProductCreator::Config["packages"]:[])));
  # // currently does not have sense: packages from patterns would need
  # // to be counted as well
  if Ops.get_string(ProductCreator.Config, "profile", "") != ""
    # summary line (%1 is file path)
    CommandLine.Print(
      Builtins.sformat(
        _("Using AutoYaST profile %1"),
        Ops.get_string(ProductCreator.Config, "profile", "")
      )
    )
  end


  if Ops.get_string(ProductCreator.Config, "result", "tree") == "iso"
    # summary line (%1/%2 is file path)
    CommandLine.Print(
      Builtins.sformat(
        _("Creating ISO image %1/%2"),
        Ops.get_string(ProductCreator.Config, "iso-directory", ""),
        Ops.get_string(ProductCreator.Config, "isofile", "")
      )
    )
  else
    # summary line (%1/%2 is file path)
    CommandLine.Print(
      Builtins.sformat(
        _("Creating directory tree in %1/%2"),
        Ops.get_string(ProductCreator.Config, "iso-directory", ""),
        Ops.get_string(ProductCreator.Config, "name", "")
      )
    )
  end

  gpgkey = Ops.get_string(ProductCreator.Config, "gpg_key", "")

  if gpgkey != ""
    privatekeys = GPG.PrivateKeys
    uid = ""
    Builtins.foreach(privatekeys) do |key|
      if Ops.get_string(key, "id", "") == gpgkey
        uid = Builtins.mergestring(Ops.get_list(key, "uid", []), ", ")
      end
    end 

    uid = Builtins.sformat(" (%1)", uid) if uid != ""

    # summary text - %1 is GPG key ID (e.g. ABCDEF01), %2 is GPG key user ID (or empty if not defined)
    CommandLine.Print(
      Builtins.sformat(
        _("Digitally sign the medium with GPG key %1%2"),
        gpgkey,
        uid
      )
    )
  else
    # summary text
    CommandLine.Print(_("The medium will not be digitally signed"))
  end
  false
end