Class: Yast::UIPluginInfo

Inherits:
SharedLibInfo show all
Includes:
Logger
Defined in:
library/system/src/lib/yast2/ui_plugin_info.rb

Overview

Class to get information about UI plug-ins used by a process (by default the current process) from its /proc/self/maps file.

You can also get information for a different process by specifying its /proc/$pid/maps file.

For testing, a fixed file can be used.

The information stored in this class is only a snapshot in the life time of the process. As new shared libs are loaded (e.g. plug-ins are loaded with dlopen()), this information may become outdated. In that case, simply let the old instance go out of scope and create a new one.

More information: https://github.com/yast/yast-yast2/pull/1194

Instance Attribute Summary

Attributes inherited from SharedLibInfo

#shared_libs

Instance Method Summary collapse

Methods inherited from SharedLibInfo

build_lib_name, #clear, lib_basename, #parse_maps_line, #read, #shared_lib?, so_major, so_number, split_lib_name

Constructor Details

#initialize(maps_file = "/proc/self/maps") ⇒ UIPluginInfo

Constructor.

Parameters:

  • maps_file (String) (defaults to: "/proc/self/maps")

    name of the maps file to use



39
40
41
42
43
44
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 39

def initialize(maps_file = "/proc/self/maps")
  super
  # Lazy init for those member variables
  @ui_plugins = nil
  @main_ui_plugin_complete = nil
end

Instance Method Details

#main_ui_pluginString?

Return the short name of the main UI plug-in, i.e. without path, "libyui-" prefix and SO number Several UI plug-ins might be loaded; the main plug-in is generally the one with the shortest lib base name ("qt", "qt-pkg", "qt-graph"; "ncurses", "ncurses-pkg").

Returns:

  • (String, nil)

    Short name of the main UI plug-in



93
94
95
96
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 93

def main_ui_plugin
  name = SharedLibInfo.lib_basename(main_ui_plugin_complete)
  name&.gsub!(/^libyui-/, "")
end

#main_ui_plugin_completeString?

Return the complete name (with path and SO number) of the main UI plug-in. Several UI plug-ins might be loaded; the main plug-in is generally the one with the shortest lib base name ("qt", "qt-pkg", "qt-graph"; "ncurses", "ncurses-pkg").

Returns:

  • (String, nil)

    Complete name of the main UI plug-in



76
77
78
79
80
81
82
83
84
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 76

def main_ui_plugin_complete
  return nil if ui_plugins.empty?

  relevant_plugins = ui_plugins.grep_v(/rest-api/)
  @main_ui_plugin_complete ||= relevant_plugins.min do |a, b|
    SharedLibInfo.lib_basename(a).size <=> SharedLibInfo.lib_basename(b).size
  end
  @main_ui_plugin_complete
end

#short_name(ui_plugin) ⇒ String

Return the short name of a UI plug-in, i.e. only the lib base name with any leading "libyui-" removed, i.e. something like "qt", "ncurses".

Parameters:

  • ui_plugin (String)

    full name (with or without path) of the UI plug-in

Returns:

  • (String)

    corresponding short name



64
65
66
67
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 64

def short_name(ui_plugin)
  name = SharedLibInfo.lib_basename(ui_plugin)
  name&.gsub(/^libyui-/, "")
end

#ui_extension_pkg(ext) ⇒ String

Return the package name (with standard SUSE libyui package naming conventions) for a UI extension for the current UI main plug-in.

Example: "pkg" for "libyui-qt.so.15.0.0" -> "libyui-qt-pkg15" "pkg" for "libyui-ncurses.so.15.0.0" -> "libyui-ncurses-pkg15"

Parameters:

  • ext (String)

    Short name for the UI extension ("pkg", "graph")

Returns:

  • (String)

    package name for that extension and the current UI



157
158
159
160
161
162
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 157

def ui_extension_pkg(ext)
  ui = main_ui_plugin
  return nil if ui.nil?

  "libyui-#{ui}-#{ext}#{ui_so_major}"
end

#ui_extension_plugin(ext) ⇒ String

Return the name of a UI extension plug-in with SO number for the current UI main plug-in.

Example: "pkg" for "libyui-qt.so.15.0.0" -> "libyui-qt-pkg.so.15.0.0" "pkg" for "libyui-ncurses.so.15.0.0" -> "libyui-ncurses-pkg.so.15.0.0"

Parameters:

  • ext (String)

    Short name for the UI extension ("pkg", "graph")

Returns:

  • (String)

    lib name without path for that extension and the current UI



124
125
126
127
128
129
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 124

def ui_extension_plugin(ext)
  (ui_name, so_number) = SharedLibInfo.split_lib_name(main_ui_plugin_complete)
  return nil if ui_name.nil?

  SharedLibInfo.build_lib_name("#{ui_name}-#{ext}", so_number)
end

#ui_extension_plugin_complete(ext) ⇒ String

Return the complete name (with path) of a UI extension plug-in with SO number for the current UI main plug-in.

Example: "pkg" for "/usr/lib64/yui/libyui-qt.so.15.0.0" -> "/usr/lib64/yui/libyui-qt-pkg.so.15.0.0" "pkg" for "/usr/lib64/yui/libyui-ncurses.so.15.0.0" -> "/usr/lib64/yui/libyui-ncurses-pkg.so.15.0.0"

Parameters:

  • ext (String)

    Short name for the UI extension ("pkg", "graph")

Returns:

  • (String)

    lib name with path for that extension and the current UI



141
142
143
144
145
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 141

def ui_extension_plugin_complete(ext)
  return nil if main_ui_plugin_complete.nil?

  File.join(File.dirname(main_ui_plugin_complete), ui_extension_plugin(ext))
end

#ui_pluginsArray<String>

Find the UI plug-ins among the shared libs.

Returns:

  • (Array<String>)

    Complete paths of the UI plug-ins



50
51
52
53
54
55
56
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 50

def ui_plugins
  if @ui_plugins.nil?
    @ui_plugins = shared_libs.grep(/yui\/libyui-/)
    log.info("UI plug-ins: #{@ui_plugins}")
  end
  @ui_plugins
end

#ui_so_majorString?

Find the SO major number of the UI main plug-in.

Returns:

  • (String, nil)

    SO number (e.g. "15")



110
111
112
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 110

def ui_so_major
  SharedLibInfo.so_major(main_ui_plugin_complete)
end

#ui_so_numberString?

Find the SO number of the UI main plug-in.

Returns:

  • (String, nil)

    SO number (e.g. "15.0.0")



102
103
104
# File 'library/system/src/lib/yast2/ui_plugin_info.rb', line 102

def ui_so_number
  SharedLibInfo.so_number(main_ui_plugin_complete)
end