Class: DInstaller::Software

Inherits:
Object
  • Object
show all
Includes:
WithProgress
Defined in:
lib/dinstaller/software.rb

Overview

This class is responsible for software handling

Instance Attribute Summary collapse

Attributes included from WithProgress

#progress

Instance Method Summary collapse

Methods included from WithProgress

#on_progress_change, #on_progress_finish, #start_progress

Constructor Details

#initialize(config, logger) ⇒ Software

Returns a new instance of Software.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dinstaller/software.rb', line 54

def initialize(config, logger)
  @config = config
  @logger = logger
  @languages = DEFAULT_LANGUAGES
  @products = @config.data["products"]
  if @config.multi_product?
    @product = nil
  else
    @product = @products.keys.first # use the available product as default
    @config.pick_product(@product)
  end
end

Instance Attribute Details

#languagesObject

Returns the value of attribute languages.



47
48
49
# File 'lib/dinstaller/software.rb', line 47

def languages
  @languages
end

#productObject (readonly)

Returns the value of attribute product.



42
43
44
# File 'lib/dinstaller/software.rb', line 42

def product
  @product
end

#productsArray<Array<String,Hash>> (readonly)

FIXME: what about defining a Product class?

Returns:

  • (Array<Array<String,Hash>>)

    An array containing the product ID and additional information in a hash



52
53
54
# File 'lib/dinstaller/software.rb', line 52

def products
  @products
end

Instance Method Details

#finishObject

Writes the repositories information to the installed system



133
134
135
136
137
138
139
140
141
# File 'lib/dinstaller/software.rb', line 133

def finish
  start_progress(2)
  progress.step("Writing repositories to the target system") do
    Yast::Pkg.SourceSaveAll
    Yast::Pkg.TargetFinish
    Yast::Pkg.SourceCacheCopyTo(Yast::Installation.destdir)
  end
  progress.step("Restoring original repositories") { restore_original_repos }
end

#initialize_target_reposObject



95
96
97
98
# File 'lib/dinstaller/software.rb', line 95

def initialize_target_repos
  Yast::Pkg.TargetInitialize("/")
  import_gpg_keys
end

#installObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dinstaller/software.rb', line 117

def install
  start_progress(count_packages)
  PackageCallbacks.setup(count_packages, progress)

  # TODO: error handling
  commit_result = Yast::PackageInstallation.Commit({})

  if commit_result.nil? || commit_result.empty?
    logger.error("Commit failed")
    raise Yast::Pkg.LastError
  end

  logger.info "Commit result #{commit_result}"
end

#probeObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dinstaller/software.rb', line 75

def probe
  logger.info "Probing software"

  store_original_repos
  Yast::Pkg.SetSolverFlags("ignoreAlreadyRecommended" => false, "onlyRequires" => true)

  # as we use liveDVD with normal like ENV, lets temporary switch to normal to use its repos
  Yast::Stage.Set("normal")

  start_progress(3)
  progress.step("Initialize target repositories") { initialize_target_repos }
  progress.step("Initialize sources") { add_base_repo }
  progress.step("Making the initial proposal") do
    proposal = Yast::Packages.Proposal(force_reset = true, reinit = false, _simple = true)
    logger.info "proposal #{proposal["raw_proposal"]}"
  end

  Yast::Stage.Set("initial")
end

#proposeObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/dinstaller/software.rb', line 100

def propose
  Yast::Pkg.TargetFinish # ensure that previous target is closed
  Yast::Pkg.TargetInitialize(Yast::Installation.destdir)
  Yast::Pkg.TargetLoad
  Yast::Pkg.SetAdditionalLocales(languages)
  select_base_product(@config.data["software"]["base_product"])

  add_resolvables
  proposal = Yast::Packages.Proposal(force_reset = false, reinit = false, _simple = true)
  logger.info "proposal #{proposal["raw_proposal"]}"

  solve_dependencies

  # do not return proposal hash, so intentional nil here
  nil
end

#provision_selected?(tag) ⇒ Boolean

Determine whether the given tag is provided by the selected packages

Parameters:

  • tag (String)

    Tag to search for (package names, requires/provides, or file names)

Returns:

  • (Boolean)

    true if it is provided; false otherwise



148
149
150
# File 'lib/dinstaller/software.rb', line 148

def provision_selected?(tag)
  Yast::Pkg.IsSelected(tag) || Yast::Pkg.IsProvided(tag)
end

#select_product(name) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
# File 'lib/dinstaller/software.rb', line 67

def select_product(name)
  return if name == @product
  raise ArgumentError unless @products[name]

  @config.pick_product(name)
  @product = name
end