Module: EnvironmentInformation

Defined in:
lib/environment_information/base/base.rb,
lib/environment_information/query/run.rb,
lib/environment_information/query/help.rb,
lib/environment_information/query/menu.rb,
lib/environment_information/query/misc.rb,
lib/environment_information/query/query.rb,
lib/environment_information/query/reset.rb,
lib/environment_information/colours/colours.rb,
lib/environment_information/project/project.rb,
lib/environment_information/query/constants.rb,
lib/environment_information/version/version.rb,
lib/environment_information/constants/constants.rb,
lib/environment_information/www/sinatra_interface.rb,
lib/environment_information/commandline/commandline.rb,
lib/environment_information/gui/jruby/environment_information.rb,
lib/environment_information/toplevel_methods/toplevel_methods.rb,
lib/environment_information/requires/require_the_toplevel_methods.rb,
lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb,
lib/environment_information/gui/shared_code/environment_information/environment_information_module.rb

Overview

#

EnvironmentInformation::GUI::UniversalWidgets::EnvironmentInformationModule

#

require ‘environment_information/gui/shared_code/environment_information/environment_information_module.rb’ include ::EnvironmentInformation::GUI::UniversalWidgets::EnvironmentInformationModule

#

Defined Under Namespace

Modules: GUI Classes: Base, Commandline, Query, Sinatra

Constant Summary collapse

PROJECT_BASE_DIRECTORY =
#

EnvironmentInformation::PROJECT_BASE_DIRECTORY

This constant may point to a target such as:

/home/Programs/Ruby/2.7.1/lib/ruby/site_ruby/2.7.0/environment_information/
#
File.absolute_path("#{__dir__}/..")+'/'
VERSION =
#

VERSION

#
'1.5.5'
LAST_UPDATE =
#

LAST_UPDATE

#
'11.04.2024'
URL_TO_THE_DOCUMENTATION =
#

URL_TO_THE_DOCUMENTATION

#
"https://www.rubydoc.info/gems/#{self.to_s.split(/(?=[A-Z])/).join('_').downcase}/#{VERSION}"
N =
#

EnvironmentInformation::N

A newline constant to simplify our life.

#
"\n"
NAMESPACE =
#

NAMESPACE

#
inspect
ARRAY_DEFAULT_PROGRAMS_ON_LINUX =
#

ARRAY_DEFAULT_PROGRAMS_ON_LINUX

#
%i(
  bash
  gcc
  binutils
  bison
  busybox
  bzip2
  coreutils
  diffutils
  findutils
  flex
  gawk
  grep
  gzip
  linux
  perl
  xz
)
ARRAY_VERSION =
#

EnvironmentInformation::ARRAY_VERSION

#
[
  /^-?-?version\??$/i
]
NOT_FOUND =
#

EnvironmentInformation::NOT_FOUND

This constant is used to denote that a component was not found.

#
'[Not available, installed or found.]'
TEMP_DIRECTORY =

← “Rescue” for most other users on linux.

'/tmp/'
ARRAY_COMPARE_PROGRAM_VERSIONS =
#

EnvironmentInformation::ARRAY_COMPARE_PROGRAM_VERSIONS

#
[
  /^-?-?compare(-|_)?to(-|_)?program(-|_)?versions$/i,
  /^-?-?compare(-|_)?program(-|_)?versions$/i,
  /^-?-?compare(-|_)?programs$/i,
  /^-?-?compare$/i,
  /^-?-?compare(-|_)?version$/i
]
NOT_INSTALLED_OR_NOT_FOUND =
#

EnvironmentInformation::NOT_INSTALLED_OR_NOT_FOUND

#
'[Not installed or not found.]'
COMMAND_NOT_FOUND =
#

EnvironmentInformation::COMMAND_NOT_FOUND

#
'command not found'
VERSION_STRING =
#

EnvironmentInformation::VERSION_STRING

#
'version'
NOT_FOUND_IN_PKG_CONFIG_SEARCH_PATH =
#

EnvironmentInformation::NOT_FOUND_IN_PKG_CONFIG_SEARCH_PATH

This constant is specifically for missing (or not found) .pc files.

#
'as not found in the pkg-config search path'
THE_PROGRAM_WAS_NOT_FOUND =
#

EnvironmentInformation::THE_PROGRAM_WAS_NOT_FOUND

#
'[The program was not found.]'
PKGCONFIG_COMMAND_NOT_FOUND =
#

EnvironmentInformation::PKGCONFIG_COMMAND_NOT_FOUND

The constant that follows next is used to determine whether pkg-config could find a corresponding .pc file. If not then pkg-config will typically report a line such as this:

Package libdr was not found in the pkg-config search path.

We will include the last part of this string, as a generic message that can be used to indicate “this package could not be found on the given computer system at hand”.

#
' was not found in the pkg-config search path.'
NO_SUCH_FILE_OR_DIRECTORY =
#

EnvironmentInformation::NO_SUCH_FILE_OR_DIRECTORY

#
'No such file or directory'
TRY_TO_MAKE_USE_OF_THE_OPN_GEM_IF_IT_IS_AVAILABLE =
#

TRY_TO_MAKE_USE_OF_THE_OPN_GEM_IF_IT_IS_AVAILABLE

This gem is closely connected to the NAMESPACE constant, so it will also reside in this file here.

#
true
ERROR_LINE =
#

ERROR_LINE

The error line is the one that can be appended to system-related queries (e. g. via system()).

#
'2>&1'
SAVE_FILE =
#

EnvironmentInformation::SAVE_FILE

Where to save stuff to. This depends on a proper setting of the toplevel variable called @temp_directory.

#
"#{@temp_directory}EnvironmentInformation.md"
UTF_ENCODING =
#

EnvironmentInformation::UTF_ENCODING

UTF-8 is the default encoding for the EnvironmentInformation namespace.

#
'UTF-8'
MAIN_ENCODING =
#

EnvironmentInformation::MAIN_ENCODING

#
UTF_ENCODING
ARRAY_TRACKED_PROGRAMS =
[]
FILE_THESE_PROGRAMS_CAN_BE_UPGRADED =
#

FILE_THESE_PROGRAMS_CAN_BE_UPGRADED

We may store which programs could be upgraded into a local file.

#
'these_programs_can_be_upgraded.yml'
ARRAY_TRACKED_XORG_COMPONENTS =
#

EnvironmentInformation::ARRAY_TRACKED_XORG_COMPONENTS (xorg tag)

#
%w(
  libevdev
  libinput
  libx11
  libxaw3d
  libxau
  libxcb
  libxcm
  libxcursor
  libxdamage
  libxi
  libxkbfile
  libxmu
  libxpm
  libxpresent
  libxtst
  libxt
  libxv
  libxvmc
  randrproto
  xextproto
  xkbcomp
  xrandr
  xstdcmap
  xf86bigfontproto
  xf86dgaproto
  xf86driproto
)
ARRAY_TRACKED_NON_PROGRAMS =
#

EnvironmentInformation::ARRAY_TRACKED_NON_PROGRAMS

#
%w(
  cpuinfo
  operating_system
  operating_system_bit_type
  cflags
  ram
  rubygems_installation_directory
  screen_resolution
)
ARRAY_SCIENCE_CLUSTER =
#

EnvironmentInformation::ARRAY_SCIENCE_CLUSTER

This is currently hardcoded here.

#
%w(
  hmmer pbbam relion samtools viennarna
)
ARRAY_LFS_TEMPORARY_PROGRAMS =
#

ARRAY_LFS_TEMPORARY_PROGRAMS

All programs that are temporary, e. g. for enabling the bootstrapping of the compiler, are stored in the following Array.

#
%i(
  binutils
  gcc
  linux_API_headers
  glibc
  libstdc++
  binutils
  tcl
  expect
  dejagnu
  m4
  ncurse
  bash
  bison
  bzip2
  coreutils
  diffutils
  file
  findutils
  gawk
  gettext
  grep
  gzip
  make
  patch
  perl
  python
  sed
  tar
  texinfo
  xz
)

Class Method Summary collapse

Class Method Details

.add_to_hash(a, b) ⇒ Object

#

EnvironmentInformation.add_to_hash

a refers to left; b refers to right.

#


77
78
79
80
81
82
83
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 77

def self.add_to_hash(a, b)
  b.strip! if b.is_a?(String) and !b.frozen?
  if b.nil? # Here we did not provide a value for b.
    ::EnvironmentInformation.register_this_component_is_missing(a)
  end
  @hash_available_programs[a] = b
end

.array_missing_components?Boolean

#

EnvironmentInformation.array_missing_components?

#

Returns:

  • (Boolean)


1526
1527
1528
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1526

def self.array_missing_components?
  @array_missing_components
end

.autogenerate_all_relevant_methods(i = tracked_components? ) ⇒ Object

#

EnvironmentInformation.autogenerate_all_relevant_methods

By default this method will scan for all tracked programs, and for the xorg-components.

#


999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 999

def self.autogenerate_all_relevant_methods(
    i = tracked_components?
  )
  i.flatten!
  # ======================================================================= #
  # Add some aliases which will be defined next.
  # ======================================================================= #
  hash_aliases = {
    atk:   :libatk,   # === EnvironmentInformation.return_version_of_libatk
    pcre2: :libpcre2, # === EnvironmentInformation.return_version_of_libpcre2
    pcre:  :libpcre,  # === EnvironmentInformation.return_version_of_libpcre
    zlib:  :libzlib   # === EnvironmentInformation.return_version_of_libzlib
  }
  # ======================================================================= #
  # Iterate over our Array next:
  # ======================================================================= #
  i.each {|this_program|
    case this_program
    when :kde
      this_program = :kde_frameworks
    end
    self.class.instance_eval {
      # =================================================================== #
      # To test this method, try to do:
      #
      #   EnvironmentInformation.return_version_of_valgrind # => "3.15.0"
      #
      # =================================================================== #
      this_method = "return_version_of_#{this_program}"
      define_method(this_method) {
        return_version_of_this_program(this_program)
      }
      if hash_aliases.has_key?(this_program)
        # ================================================================= #
        # To test this, try:
        #
        #   EnvironmentInformation.return_version_of_libzlib
        #
        # ================================================================= #
        use_this_as_the_alias_target = "return_version_of_#{hash_aliases[this_program]}"
        define_method(use_this_as_the_alias_target) {
          return_version_of_this_program(this_program)
        }
      end
    }
  }
end

.cd(i) ⇒ Object

#

EnvironmentInformation.cd (cd tag)

#


257
258
259
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 257

def self.cd(i)
  Dir.chdir(i) if File.directory? i
end

.cflags?Boolean

#

EnvironmentInformation.cflags? (cflags tag)

The following is equivalent to the value stored in the variable $CFLAGS, which on unix-like systems may be obtained by issuing the following command:

echo $CFLAGS

The output may be like this:

-O2 -fPIC -fno-strict-overflow -Wno-error
#

Returns:

  • (Boolean)


634
635
636
637
638
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 634

def self.cflags?
  _ = ENV['CFLAGS'].to_s.strip
  _ = '<none>' if _.empty? # Display special status if it is empty.
  return _
end

.clear_array_missing_componentsObject

#

EnvironmentInformation.clear_array_missing_components

#


938
939
940
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 938

def self.clear_array_missing_components
  @array_missing_components
end

.clear_hashObject

#

EnvironmentInformation.clear_hash

This method can be used to clear the main (toplevel) Hash.

#


90
91
92
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 90

def self.clear_hash
  @hash_available_programs.clear
end

.colour_for_program_not_foundObject

#

EnvironmentInformation.colour_for_program_not_found

#


93
94
95
# File 'lib/environment_information/colours/colours.rb', line 93

def self.colour_for_program_not_found
  @colour_for_program_not_found
end

.colour_for_the_left_sideObject

#

EnvironmentInformation.colour_for_the_left_side (left tag)

This method will return the colour

This could also be :limegreen rather than :forestgreen or vice versa.

#


79
80
81
# File 'lib/environment_information/colours/colours.rb', line 79

def self.colour_for_the_left_side
  @colour_for_the_left_side
end

.colour_for_the_right_sideObject

#

EnvironmentInformation.colour_for_the_right_side (right tag)

#


86
87
88
# File 'lib/environment_information/colours/colours.rb', line 86

def self.colour_for_the_right_side
  @colour_for_the_right_side
end

.cpuinfo?Boolean

#

EnvironmentInformation.cpuinfo? (cpuinfo tag)

This method currently relies on /proc/cpuinfo, thus favouring Linux-based systems.

The output will be similar to this:

AMD A8-7600 Radeon R7, 10 Compute Cores 4C+6G, 4 cores

It will become the display part of “CPU Model”, so this method is also known as the “cpu model”.

#

Returns:

  • (Boolean)


858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 858

def self.cpuinfo?
  result = '/proc/cpuinfo'
  if File.exist? result
    readlines = File.readlines(result)
    _ = readlines.grep(/model name/).first.chomp
    splitted = _.split(':')
    _ = splitted[1].strip # => "model name\t: AMD Sempron(tm) 145 Processor"
    # ====================================================================== #
    # Next, add the amount of cores. We use "nproc" for this but "lscpu"
    # also contains this information. The following regex could be used
    # for lscpu:
    #
    #   Core\(s\) per socket:    (.+)
    #
    # Ok, we use lscpu for now.
    # ====================================================================== #
    n_cores = silent_sys_command('nproc --all').to_s.strip
    case n_cores
    when '1'
      n_cores << ' core'  # Singular.
    else
      n_cores << ' cores' # Plural then.
    end
    _ << ", #{n_cores}" unless n_cores.empty?
    result = _
  else
    result = nil
  end
  result
end

.do_use_coloursObject

#

EnvironmentInformation.do_use_colours

#


110
111
112
# File 'lib/environment_information/colours/colours.rb', line 110

def self.do_use_colours
  @use_colours = i
end

.e(i = '', hash = {}) ⇒ Object

#

EnvironmentInformation.e

#


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 55

def self.e(
    i    = '',
    hash = {}
  )
  if hash and
     hash.has_key?(:display_everything_in_short_format) and
     hash[:display_everything_in_short_format]
    # ===================================================================== #
    # Display the results in a single line in this case, separated
    # via ',' tokens.
    # ===================================================================== #
    print "#{i}, "
  else # This variant here is the default.
    puts i
  end
end

.ee(i = '') ⇒ Object

#

EnvironmentInformation.ee

This is simply a wrapper over print, as well as adding a ‘, ’ to that.

#


448
449
450
451
452
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 448

def self.ee(
    i = ''
  )
  print "#{i}, "
end

.environment_information?Boolean

#

EnvironmentInformation.environment_information?

This method will return a very long string containing all information about the locally installed/available programs.

#

Returns:

  • (Boolean)


226
227
228
# File 'lib/environment_information/query/query.rb', line 226

def self.environment_information?
  ::EnvironmentInformation::Query.new(:full_be_silent).stringified
end

.file_query_to_use_for_the_individual_componentsObject

#

EnvironmentInformation.file_query_to_use_for_the_individual_components

#


272
273
274
# File 'lib/environment_information/constants/constants.rb', line 272

def self.file_query_to_use_for_the_individual_components
  "#{project_base_directory?}yaml/query_to_use_for_all_components.yml"
end

.forestgreen(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.forestgreen

#


162
163
164
165
166
167
168
# File 'lib/environment_information/colours/colours.rb', line 162

def self.forestgreen(
    i           = '',
    use_colours = @use_colours
  )
  return ::Colours.forestgreen(i) if use_colours
  return i
end

.gtk_bindingsObject

#

EnvironmentInformation.gtk_bindings

#


394
395
396
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 394

def self.gtk_bindings
   ::EnvironmentInformation::EnvironmentInformation::GUI::Gtk::EnvironmentInformation.new
end

.hash?Boolean

#

EnvironmentInformation.hash?

This method will return the Hash of all available programs.

#

Returns:

  • (Boolean)


46
47
48
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 46

def self.hash?
  @hash_available_programs
end

.internet_is_available?Boolean

#

EnvironmentInformation.internet_is_available?

#

Returns:

  • (Boolean)


457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 457

def self.internet_is_available?
  require 'resolv'
    dns_resolver = Resolv::DNS.new
  begin
    # ====================================================================== #
    # The first domain name ever. Will probably not be removed.
    # ====================================================================== #
    dns_resolver.getaddress('symbolics.com')
    return true
  rescue Resolv::ResolvError => _error
    return false
  end
end

.is_on_roebe?Boolean

#

EnvironmentInformation.is_on_roebe?

#

Returns:

  • (Boolean)


264
265
266
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 264

def self.is_on_roebe?
  ENV['IS_ROEBE'].to_i == 1
end

.is_this_component_included?(i) ⇒ Boolean

#

EnvironmentInformation.is_this_component_included?

This is a more extensive check than .is_this_program_included?()

#

Returns:

  • (Boolean)


571
572
573
574
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 571

def self.is_this_component_included?(i)
  array = tracked_components?
  array.flatten.include? i.to_sym # Need a Symbol as input.
end

.is_this_component_missing?(i) ⇒ Boolean

#

EnvironmentInformation.is_this_component_missing?

#

Returns:

  • (Boolean)


970
971
972
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 970

def self.is_this_component_missing?(i)
  !@array_missing_components.include?(i)
end

.is_this_program_included?(i) ⇒ Boolean

#

EnvironmentInformation.is_this_program_included?

This will include the two Arrays ARRAY_TRACKED_PROGRAMS and ARRAY_XORG_COMPONENTS, but it will NOT include ARRAY_TRACKED_NON_PROGRAMS.

#

Returns:

  • (Boolean)


248
249
250
251
252
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 248

def self.is_this_program_included?(i)
  (
    ARRAY_TRACKED_PROGRAMS
  ).flatten.include? i.to_sym # Need a symbol.
end

.lfs_core_programs?Boolean

#

EnvironmentInformation.lfs_core_programs?

#

Returns:

  • (Boolean)


579
580
581
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 579

def self.lfs_core_programs?
  ARRAY_LFS_CORE_PROGRAMS
end

.lightseagreen(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.lightseagreen

#


173
174
175
176
177
178
179
180
181
# File 'lib/environment_information/colours/colours.rb', line 173

def self.lightseagreen(
    i           = '',
    use_colours = @use_colours
  )
  if use_colours
    return ::Colours.lightseagreen(i)
  end
  return i
end

.lightslategrey(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.lightslategrey

#


130
131
132
133
134
135
# File 'lib/environment_information/colours/colours.rb', line 130

def self.lightslategrey(
    i = '', use_colours = @use_colours
  )
  return ::Colours.lightslategrey(i) if use_colours
  return i
end

.load_file_query_to_use_for_the_individual_components(i = ::EnvironmentInformation.project_base_directory?+ 'yaml/query_to_use_for_all_components.yml') ⇒ Object

#

EnvironmentInformation.load_file_query_to_use_for_the_individual_components

#


515
516
517
518
519
520
521
522
523
524
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 515

def self.load_file_query_to_use_for_the_individual_components(
    i = ::EnvironmentInformation.project_base_directory?+
        'yaml/query_to_use_for_all_components.yml' # FILE_QUERY_TO_USE_FOR_THE_INDIVIDUAL_COMPONENTS
  )
  if File.exist? i
    return YAML.load_file(i)
  else
    return {}
  end
end

.mediumaquamarine(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.mediumaquamarine

#


207
208
209
210
211
212
213
# File 'lib/environment_information/colours/colours.rb', line 207

def self.mediumaquamarine(
    i           = '',
    use_colours = @use_colours
  )
  return ::Colours.mediumaquamarine(i) if use_colours
  return i
end

.mediumpurple(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.mediumpurple

#


117
118
119
120
121
122
123
124
125
# File 'lib/environment_information/colours/colours.rb', line 117

def self.mediumpurple(
    i           = '',
    use_colours = @use_colours
  )
  if use_colours
    return ::Colours.mediumpurple(i)
  end
  return i
end
#

EnvironmentInformation.menu

#


121
122
123
# File 'lib/environment_information/commandline/commandline.rb', line 121

def self.menu(i = ARGV)
  EnvironmentInformation::Commandline.new(i)
end

.n_subcommands?Boolean

#

EnvironmentInformation.n_subcommands?

Return how many subcommands are available/registered. These are the tracked programs; and the xorg-components.

The non-programs will not be gathered by this method, on purpose; they are not standalone programs after all.

As of August 2020, 167 programs were tracked by this gem.

As of March 2024, 256 components were tracked by this gem, so about 250 programs, give or take.

#

Returns:

  • (Boolean)


133
134
135
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 133

def self.n_subcommands?
  ARRAY_TRACKED_PROGRAMS.size
end

.operating_system(i = 'uname -mo') ⇒ Object

#

EnvironmentInformation.operating_system (os tag)

This method is also known as “bit type”.

The return value of this method may be a String such as this one here:

"GNU/Linux"

This is then further modified a bit to drop the “GNU/” part specifically.

An alternative to “uname -mo” would be “uname -a”.

#


744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 744

def self.operating_system(
    i = 'uname -mo'
  )
  result = silent_sys_command(i).chomp
  if result.start_with? 'GNU'
    # ====================================================================== #
    # The next part removes 'GNU/' specifically. It is a simpler name
    # than "GNU Linux" and variants, just as "BSD" is simpler than
    # e. g. "FreeBSD". You can reason that it may be "less accurate",
    # but it makes the notification-part of this gem simpler.
    # ====================================================================== #
    result.sub!(/^GNU\//,'') # Experimental as of Sep 2019.
  end
  if result.include? ' '
    result = result.split(' ').last
  end
  return result
end

.operating_system_bit_type_informationObject

#

EnvironmentInformation.operating_system_bit_type_information (bit tag, bit type tag)

This method will return the bit type in use, as a String, such as “x86_64” or “x86_64 (64 bit)” specifically. The reason why this method appends ‘ (64 bit)’ is mostly so that the user can quickly see whether a computer is on 32 bit or on 64 bit.

#


778
779
780
781
782
783
784
785
786
787
788
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 778

def self.operating_system_bit_type_information
  result = silent_sys_command('uname -m')
  result.chomp!
  result = result.split(' ')[-1] if result.include?(' ')
  result = result.dup if result.frozen?
  case result
  when 'x86_64'
    result << ' (64 bit)'
  end
  return result
end

.pink(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.pink

#


151
152
153
154
155
156
157
# File 'lib/environment_information/colours/colours.rb', line 151

def self.pink(
    i           = '',
    use_colours = @use_colours
  )
  return ::Colours.pink(i) if use_colours
  return i
end

.prefix?Boolean

#

EnvironmentInformation.prefix?

#

Returns:

  • (Boolean)


163
164
165
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 163

def self.prefix?
  @prefix_to_use
end

.project_base_directory?Boolean

#

EnvironmentInformation.project_base_directory?

#

Returns:

  • (Boolean)


23
24
25
# File 'lib/environment_information/project/project.rb', line 23

def self.project_base_directory?
  PROJECT_BASE_DIRECTORY
end

.query_pkgconfig_version_for(i = :gtk2) ⇒ Object

#

EnvironmentInformation.query_pkgconfig_version_for

This toplevel-method can be used to query infromation stored in .pc files, done via the pkg-config utility.

The input-argument to this method should be the name of the program at hand; and that program should be registered in the corresponding.yml file. The query will then use “pkg-config”, which in turn queries the local .pc file for the version. So the local .pc file must be available, as otherwise this method will not find the necessary information.

#


917
918
919
920
921
922
923
924
925
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 917

def self.query_pkgconfig_version_for(
    i = :gtk2
  )
  result = silent_sys_command("pkg-config --modversion #{i}")
  if result.include? 'was not found in the pkg-config search pa'
    result = NOT_FOUND
  end
  return result
end

.ram?Boolean

#

EnvironmentInformation.ram? (ram tag)

This method will determine how much RAM the given computer host has.

The result will be given in n MB.

Alternatively we could use /proc/meminfo and look for ‘MemTotal:’.

#

Returns:

  • (Boolean)


721
722
723
724
725
726
727
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 721

def self.ram?
  result_in_n_mb = silent_sys_command('free -m').split("\n")[1]
  if result_in_n_mb and result_in_n_mb.include?(' ')
    result_in_n_mb = result_in_n_mb.split(' ')[1]
  end
  return result_in_n_mb
end

.register_this_component_is_missing(i) ⇒ Object

#

EnvironmentInformation.register_this_component_is_missing

The ideal input to this method is a Symbol, so that the Array stores only missing components that way.

#


948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 948

def self.register_this_component_is_missing(i)
  # ======================================================================== #
  # First check if we have a Symbol as input:
  # ======================================================================== #
  if i.is_a? Symbol
    copy = i.to_s
    if copy.include?('_')
      i = copy.split('_').last.to_sym
    end
  end
  i = i.to_sym unless i.is_a? Symbol
  # ======================================================================== #
  # Do not register the same missing component twice:
  # ======================================================================== #
  unless @array_missing_components.include? i
    @array_missing_components << i
  end
end

.replay_from_the_stored_file(_ = return_path_to_the_all_programs_file) ⇒ Object

#

EnvironmentInformation.replay_from_the_stored_file

To invoke this method from the commandline, try:

envi --replay
#


429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 429

def self.replay_from_the_stored_file(
    _ = return_path_to_the_all_programs_file
  )
  if File.exist? _
    e "Loading from the file #{_}."
    @hash_available_programs = YAML.load_file(_)
    @hash_available_programs.each_pair {|key, value|
      e "#{key}:"+value.to_s
    }
  else
    e "No file exists at #{_}."
  end
end

.report_versionObject

#

EnvironmentInformation.report_version

#


128
129
130
131
# File 'lib/environment_information/commandline/commandline.rb', line 128

def self.report_version
  e "#{rev}The version of the EnvironmentInformation project "\
    "in use is: #{simp(VERSION)}#{rev}"
end

.require_the_toplevel_methodsObject

#

EnvironmentInformation.require_the_toplevel_methods

#


14
15
16
# File 'lib/environment_information/requires/require_the_toplevel_methods.rb', line 14

def self.require_the_toplevel_methods
  require 'environment_information/toplevel_methods/toplevel_methods.rb'
end

.return_alias_to(i) ⇒ Object

#

EnvironmentInformation.return_alias_to

This method will return some abbreviations to programs.

#


476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 476

def self.return_alias_to(i)
  if i.is_a? Array
    i = i.first
  end
  case i.to_sym
  # ======================================================================== #
  # === :find
  # ======================================================================== #
  when :find
    i = :findutils
  # ======================================================================== #
  # === :diff
  # ======================================================================== #
  when :diff
    i = :diffutils
  # ======================================================================== #
  # === :yacc
  # ======================================================================== #
  when :yacc
    i = :bison
  end
  return i # Always return something.
end

.return_array_of_outdated_programs(hash = ::EnvironmentInformation.hash?) ⇒ Object

#

EnvironmentInformation.return_array_of_outdated_programs

This method will return all programs that are outdated - this also includes missing programs, so the method name is a slight misnomer.

Usage example:

EnvironmentInformation.initialize
array = EnvironmentInformation.return_array_of_outdated_programs
#


1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1611

def self.return_array_of_outdated_programs(
    hash = ::EnvironmentInformation.hash?
  )
  forbidden = ::EnvironmentInformation.load_file_array_tracked_non_programs
  # ======================================================================= #
  # Now find all entries that are either nil, or have a too low program
  # version.
  # ======================================================================= #
  array = hash.select {|key, value|
    if value and forbidden.include?(key) # ← we exclude entries here such as "rubygems_installation_dir".
      false
    else
      if value.nil? or value.include?('not found') or
         !(value =~ /\d+/) # ← check for at the least one number, such as "1".
        true
      else
        false
      end
    end
  }.keys
  # ======================================================================= #
  # Next, check these against the local program version:
  #  local_program_version = key
  # ======================================================================= #
  return array
end

.return_everythingObject

#

EnvironmentInformation.return_everything

#


1678
1679
1680
1681
1682
1683
1684
1685
1686
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1678

def self.return_everything
  require 'environment_information/main_class/main_class.rb'
  _ = ::EnvironmentInformation.new(:do_not_run_yet)
  _.disable_colours
  _.be_quiet
  _.menu('--really-everything')
  _.run
  return _.string
end

.return_path_to_all_programs_fileObject

#

EnvironmentInformation.return_path_to_all_programs_file

#


1534
1535
1536
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1534

def self.return_path_to_all_programs_file
  "#{temp_directory?}environment_information.yml"
end

.return_pkgconfig_based_programs(this_file = ::EnvironmentInformation.file_query_to_use_for_the_individual_components) ⇒ Object

#

EnvironmentInformation.return_pkgconfig_based_programs

This method will return all programs that are handled by pkgconfig.

In March 2024, 150 programs depended on pkg-config (.pc files).

#


981
982
983
984
985
986
987
988
989
990
991
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 981

def self.return_pkgconfig_based_programs(
    this_file = ::EnvironmentInformation.file_query_to_use_for_the_individual_components
  )
  dataset = YAML.load_file(this_file)
  return dataset.select {|key, value|
    # ====================================================================== #
    # The next query will select both :pkgconfig and :"pkg-config".
    # ====================================================================== #
    value.to_s.start_with? 'pkg'
  }.keys
end

.return_remote_gtk2_versionObject

#

EnvironmentInformation.return_remote_gtk2_version

This method can be used to obtain the latest gtk2-version, from a remote URL.

The reason why this was necessary is because the RBT project may not always keep the latest gtk2 version, since gtk3 (and so forth) is more recent. Since we may still have to find out which gtk2 version is the most recent, we need a method to do so - which is precisely what this method here is doing.

#


540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 540

def self.return_remote_gtk2_version
  # ======================================================================= #
  # We will use a hardcoded URL pointing towards gtk2:
  # ======================================================================= #
  remote_url = 'https://ftp.gnome.org/pub/GNOME/sources/gtk+/2.24/?C=M;O=D'
  require 'open-uri'
  newest_version = ''
  # ======================================================================= #
  # We will next try to obtain the remote dataset, but this would
  # fail if we have no www-connection, so we must rescue this step.
  # ======================================================================= #
  if internet_is_available?
    begin
      dataset = URI.open(remote_url).read
      use_this_regex =
        /<a href="gtk\+\-(\d.\d\d.\d\d).tar.xz"><img src=/
      scanned = dataset.scan(use_this_regex).flatten
      newest_version = scanned.first
    rescue SocketError => error
      puts "It seems as if we have no working internet "\
           "connection (#{sfancy(error.class)})"
    end
  end
  return newest_version.strip # ← And return it here.
end

.return_remote_url_of_this_program(i = ARGV) ⇒ Object

#

EnvironmentInformation.return_remote_url_of_this_program

This method will try to return the remote URL of the given program.

Note that this functionality depends on the RBT project, which explains the rescued required statement in the method. While in theory we could create a stand-alone solution, I don’t want to duplicate code I already wrote for another project, so users are encouraged to install the rbt gem - it’s what I use on my home system as well.

#


825
826
827
828
829
830
831
832
833
834
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 825

def self.return_remote_url_of_this_program(i = ARGV)
  if i.is_a? Array
    i = i.first
  end
  begin
    require 'rbt/cookbooks/url/url.rb'
    i = RBT.return_url1_of_this_program(i)
  rescue LoadError; end
  i
end

.return_simple_version_based_programs(i = file_query_to_use_for_the_individual_components) ⇒ Object

#

EnvironmentInformation.return_simple_version_based_programs

This method will return an Array, consisting of all files that can be queried via a simple –version query, via the commandline.

#


1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1510

def self.return_simple_version_based_programs(
    i = file_query_to_use_for_the_individual_components
  )
  dataset = YAML.load_file(i)
  dataset.select {|key, value|
    value = value.to_sym
    # ===================================================================== #
    # The next query will select only for :version entries.
    # ===================================================================== #
    value == :version
  }.keys
end

.return_the_most_important_infoObject

#

EnvironmentInformation.return_the_most_important_info

This method will just return a String that can be used right away in, for example, a sinatra application or a RoR application.

#


110
111
112
113
114
115
116
117
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 110

def self.return_the_most_important_info
  "Operating system:                "+
  "#{::EnvironmentInformation.operating_system}<br>"+
  "Operating system bit type:       "+
  "#{::EnvironmentInformation.operating_system_bit_type}<br>"+
  "CPU model:                       "+
  "#{::EnvironmentInformation.cpu_model}<br>"
end

.return_version_of_boostObject

#

EnvironmentInformation.return_version_of_boost

This method will either return a String (the version of boost), or nil if boost was not found.

#


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 190

def self.return_version_of_boost
  target_file = '/usr/include/boost/version.hpp'
  if File.exist?('/System/Index/include/boost/version.hpp') and
    !File.exist?(target_file) # Custom fix.
    target_file = '/System/Index/include/boost/version.hpp'
  end
  if File.exist? target_file
    dataset = File.readlines(target_file)
    version = dataset.select {|line|
      line.include? '#define BOOST_LIB_VERSION'
    }.first.sub(/#define BOOST_LIB_VERSION/,'').
            strip.delete('"').tr('_','.')
    if version.count('.') < 2
      version << '.0'
    end
  else
    version = nil
  end
  return version
end

.return_version_of_busybox(i = "busybox #{ERROR_LINE}") ⇒ Object

#

EnvironmentInformation.return_version_of_busybox (busybox tag)

#


586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 586

def self.return_version_of_busybox(
    i = "busybox #{ERROR_LINE}"
  )
  result = ::EnvironmentInformation.return_very_silent_system_output_from(i)
  if result and result.is_a?(String) and result.include?("\n")
    first_line = result.split("\n").first
    if first_line.include? ' v'
      # "BusyBox v1.32.0 (2020-11-08 04:41:56 Etc) multi-call binary.\n"
      use_this_regex = /v(\d{0,1}.\d{0,2}.\d{0,1})/ # See: https://rubular.com/r/MpnFXlalLCXXGI
      result = first_line.scan(use_this_regex).flatten.first.to_s
      return result
    end
  end
  return nil
end

.return_version_of_doubleconversion(target_file = '/usr/lib/cmake/double-conversion/double-conversionConfigVersion.cmake') ⇒ Object

#

EnvironmentInformation.return_version_of_doubleconversion

#


170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 170

def self.return_version_of_doubleconversion(
    target_file = '/usr/lib/cmake/double-conversion/double-conversionConfigVersion.cmake'
  )
  if File.exist? target_file
    dataset = File.read(target_file)
    result  = dataset.scan(
                /PACKAGE_VERSION "(.+)"/
              ).flatten.first.to_s
    return result
  else
    return nil
  end
end

.return_version_of_mpcObject

#

EnvironmentInformation.return_version_of_mpc

This method will read the version-string from a .h header file.

#


800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 800

def self.return_version_of_mpc
  target_file = '/usr/include/mpc.h'
  if File.exist? target_file
    dataset = File.read(target_file)
    use_this_regex = /MPC_VERSION_STRING "([0-9\.]+)"$/
    dataset = dataset.scan(use_this_regex).flatten
    version = dataset.first
    return version
  else
    return THE_PROGRAM_WAS_NOT_FOUND
  end
end

.return_version_of_sed?(i = :sed) ⇒ Boolean

#

EnvironmentInformation.return_version_of_sed?

This method will return the version of sed.

#

Returns:

  • (Boolean)


209
210
211
212
213
214
215
216
217
# File 'lib/environment_information/query/query.rb', line 209

def self.return_version_of_sed?(
    i = :sed
  )
  _ = ::EnvironmentInformation::Query.new(i, :do_not_run_yet) { :be_quiet }
  _.clear_old_dataset
  _.add_the_commandline_arguments
  _.do_work_through_all_the_specified_components
  return _.version?
end

.return_version_of_this_program(i, &block) ⇒ Object

#

EnvironmentInformation.return_version_of_this_program

This method will try to use –version first.

This will typically use the main binary at hand, which we thus expect to respond to –version.

Note that the method will also handle input that can NOT be generated via –version. This is usually called a “complex” version query, as far as the environment_information gem is concerned.

Usage example:

EnvironmentInformation.return_version_of_this_program(:ccache)
#


1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1157

def self.return_version_of_this_program(
    this_program,
    prefix_to_use = @prefix_to_use
  )
  prefix_to_use = prefix_to_use.dup if prefix_to_use
  version = nil # ← This is the default.
  if this_program.is_a? Array
    this_program = this_program.flatten.first
  end
  # ======================================================================= #
  # Next define a few aliases.
  # ======================================================================= #
  this_program = ::EnvironmentInformation.return_alias_to(this_program)
  if ARRAY_TRACKED_NON_PROGRAMS.include? this_program
    return ::EnvironmentInformation.send(this_program)
  elsif @query_to_use_for_the_individual_components.has_key? this_program.to_sym
    use_this_command = @query_to_use_for_the_individual_components[this_program.to_sym]
    case use_this_command
    # ===================================================================== #
    # === :mate_desktop
    #
    # This entry is special.
    # ===================================================================== #
    when :mate_desktop
      return RBT.return_mate_desktop_version_array
    # ===================================================================== #
    # === :pkgconfig
    #
    # An invocation example for this would be:
    #
    #   x = EnvironmentInformation.return_version_of_this_program(:check) # => "0.15.2"
    #
    # ===================================================================== #
    when :pkgconfig
      version = ::EnvironmentInformation::Queries::PkgConfig.new(this_program).version?
    # ===================================================================== #
    # === :custom_gtk2
    # ===================================================================== #
    when :custom_gtk2
      version = ::EnvironmentInformation::Queries::PkgConfig.new('gtk+-2.0').version?
    # ===================================================================== #
    # === :custom_mpc
    #
    # We rely on the header called mpc.h.
    # ===================================================================== #
    when :custom_mpc
      version = ::EnvironmentInformation.return_version_of_mpc
    # ===================================================================== #
    # === :custom_boost
    # ===================================================================== #
    when :custom_boost
      version = ::EnvironmentInformation.return_version_of_boost
      if version.nil?
        register_this_component_is_missing(:boost)
      end
    # ===================================================================== #
    # === :version                                            (version tag)
    #
    # This entry point is typically for "program_name --version"
    # entries. Some of them require custom modifications.
    # ===================================================================== #
    when :version
      # =================================================================== #
      # Next enable support for AppDir layout, where programs will
      # ultimately reside in the same directory.
      # =================================================================== #
      unless prefix_to_use.empty?
        prefix_to_use << "#{this_program.to_s.capitalize}/Current/bin/"
      end
      cmd = "#{prefix_to_use}#{this_program} --version #{ERROR_LINE}"
      if @debug
        e Colours.crimson('DEBUG for the prefix-value in use: ')+
          Colours.steelblue(cmd)
      end
      version = ::EnvironmentInformation::Queries::SimpleVersion.new(this_program) {{
        prefix_to_use: prefix_to_use
      }}.version?
    # ===================================================================== #
    # Next we will handle special programs, such as "swig -v" and similar.
    # This is done by class ComplexVersion since as of 29.08.2020.
    # ===================================================================== #
    else # else tag
      if use_this_command.start_with?('pkg-config')
        version = ::EnvironmentInformation::Queries::PkgConfig.new(this_program).version?
      else
        cmd = "#{@prefix_to_use}#{use_this_command} #{ERROR_LINE}"
        version = ::EnvironmentInformation::Queries::ComplexVersion.new(this_program) {{
          prefix_to_use: prefix_to_use
        }}.version?
      end
    end
  else
    e 'Not registered any key for the program: '+this_program.to_s
    e 'This is currently not allowed - please add this missing information.'
    exit
  end
  result = version
  if result
    unless result.include? COMMAND_NOT_FOUND
      result = result.dup if result.frozen?
      result.strip!
    end
  end
  if result and (result == 'found' or result == 'foud')
    register_this_component_is_missing(this_program)
  elsif result and result.include?(COMMAND_NOT_FOUND)
    register_this_component_is_missing(this_program)
  # ======================================================================= #
  # Check whether pkg-config is available or not.
  # ======================================================================= #
  elsif result and (
          result.include?(PKGCONFIG_COMMAND_NOT_FOUND) or
          result.include?(NO_SUCH_FILE_OR_DIRECTORY)
        )
    register_this_component_is_missing(this_program)
  elsif result.nil?
    register_this_component_is_missing(this_program)
  end
  return result
end

.return_version_of_xrandr(i = 'xrandr --version') ⇒ Object

#

EnvironmentInformation.return_version_of_xrandr

#


605
606
607
608
609
610
611
612
613
614
615
616
617
618
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 605

def self.return_version_of_xrandr(
    i = 'xrandr --version'
  )
  result = ::EnvironmentInformation.return_very_silent_system_output_from(i)
  if result
    version = result.strip.split("\n")
    if version.is_a?(Array)
      version = version.first.split(' ').last.strip # Assume: "xrandr program version       1.5.1"
      # or: result = splitted.first.sub(/xrandr program version/,'')
      return version.strip
    end
  end
  return nil
end

.return_version_of_xvid(target_file = '/usr/include/xvid.h') ⇒ Object

#

EnvironmentInformation.return_version_of_xvid

#


214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 214

def self.return_version_of_xvid(
    target_file = '/usr/include/xvid.h'
  )
  if File.exist?('/System/Index/include/'+File.basename(target_file)) and
    !File.exist?(target_file) # Custom fix.
    target_file = '/System/Index/include/'+File.basename(target_file)
  end
  if File.exist? target_file
    dataset = File.readlines(target_file)
    version = dataset.select {|line|
      line.include? '  XVID_MAKE_VERSION(' # #define XVID_VERSION             XVID_MAKE_VERSION(1,3,7)
    }
    if version.is_a? Array
      version = version.flatten.first.to_s
    end
    version = version.scan( # See:  https://rubular.com/r/4anuroBmb40yzh
      /XVID_MAKE_VERSION\((\d{0,1},\d{0,1},\d{0,1})/
    )
    if version.is_a? Array
      version = version.flatten.first.to_s
    end
    version.tr!(',','.')
  else
    version = nil
  end
  return version
end

.return_very_silent_system_output_from(use_this_query) ⇒ Object

#

EnvironmentInformation.return_very_silent_system_output_from (query tag)

#


2194
2195
2196
2197
2198
2199
2200
2201
2202
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 2194

def self.return_very_silent_system_output_from(
    use_this_query
  )
  @original_stderr = $stderr.clone
  $stderr.reopen('/dev/null', 'w')
  result = `#{use_this_query} 2>&1`
  $stderr.reopen(@original_stderr)
  return result
end

.rev(use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.rev (rev tag)

#


229
230
231
232
# File 'lib/environment_information/colours/colours.rb', line 229

def self.rev(use_colours = @use_colours)
  return ::Colours.rev if use_colours
  return '' # Else return an empty String.
end

.royalblue(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.royalblue

#


196
197
198
199
200
201
202
# File 'lib/environment_information/colours/colours.rb', line 196

def self.royalblue(
    i           = '',
    use_colours = @use_colours
  )
  return ::Colours.royalblue(i) if use_colours
  return i
end

.rubygems_installation_directory(prefix_to_use = @prefix_to_use) ⇒ Object

#

EnvironmentInformation.rubygems_installation_directory

This method will return the path to the rubygems installation directory, if possible (if it exists).

As this ought to be a directory, we will ensure that a trailing ‘/’ token is returned.

This method may return a String such as “/root/.gem/”.

#


653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 653

def self.rubygems_installation_directory(
    prefix_to_use = @prefix_to_use
  )
  result = silent_sys_command("#{prefix_to_use}gem env")
  unless result.include? 'not found'
    # ===================================================================== #
    # Apply a regex next.
    # ===================================================================== #
    path_to_the_rubygem_directory = result.to_s.scan(
      /INSTALLATION DIRECTORY: (.+)/ # Obtain the proper match here.
    ).flatten.first.to_s
    if File.directory? path_to_the_rubygem_directory
      path_to_the_rubygem_directory << '/' # Append the trailing '/' here.
    end unless path_to_the_rubygem_directory.end_with? '/'
    result = path_to_the_rubygem_directory
  else
    result = nil
  end
  return result
end

.run(i = ARGV, &block) ⇒ Object

#

EnvironmentInformation.run

#


233
234
235
# File 'lib/environment_information/query/query.rb', line 233

def self.run(i = ARGV, &block)
  ::EnvironmentInformation::Query.new(i, &block)
end

.run_gtkObject

#

EnvironmentInformation.run_gtk

Use this method if you wish to run the gtk-component of the EnvironmentInformation project.

#


404
405
406
407
408
409
410
411
412
413
# File 'lib/environment_information/gui/universal_widgets/environment_information/environment_information.rb', line 404

def self.run_gtk
  require 'gtk_paradise/run'
  _ = ::EnvironmentInformation.gtk_bindings
  r = ::Gtk.run
  r << _ # ← Add the widget here.
  r.add_shortcut(1, 'focus(:left)', :alt)
  r.modify_background(:normal, :white)
  r.automatic_title
  r.top_left_then_run
end

.sanitize_this_version_string(i = nil) ⇒ Object

#

EnvironmentInformation.sanitize_this_version_string (sanitize tag)

#


1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1691

def self.sanitize_this_version_string(
    i = nil
  )
  return if i.nil?
  if i.frozen?
    i = i.dup
  end
  # ======================================================================== #
  # === Handle ccache next:
  # ======================================================================== #
  if i.include? 'ccache version ' # Example: ccache version 4.8.2
    i = i.scan(/ccache version (\d{1,2}\.\d{1,2}\.\d{1,2})/).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle strace next:
  # ======================================================================== #
  if i.include? 'strace -- version '
    i = i.split('strace -- version ').last
  end
  # ======================================================================== #
  # === Handle glslang next
  #
  # We must handle e. g. 'Glslang Version: 11:14.0.0'
  # ======================================================================== #
  if i.include?('Glslang Version') and i.include?(':')# e. g. for glslang.
    i = i.split("\n").first if i.include? "\n"
    i = i.split(':').last.to_s.strip
  end
  # ======================================================================== #
  # === HMMER: we handle hmmer next here
  # ======================================================================== #
  if i.include? '# HMMER ' # ← Specifically for "hammer", e. g. 'HMMER 3.4 (Aug 2023); http://hmmer.org/'
    i = i.scan(
      /# HMMER (\d{0,2}\.\d{0,2}\.?\d{0,2})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle xstdcmap next:
  # ======================================================================== #
  if i.include? 'xstdcmap '
    i = i.split('xstdcmap').last.strip
  end
  # ======================================================================== #
  # === Handle qpdf next:
  # ======================================================================== #
  if i.include? 'qpdf version '
    i = i.split('qpdf version ').last.strip
  end
  # ======================================================================== #
  # === Handle Swig next:
  # ======================================================================== #
  if i.include? 'SWIG Version'
    i = i.scan(
      /SWIG Version (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first
  end
  # ======================================================================== #
  # === Handle Screen next
  #
  # For: Screen version 4.09.01 (GNU) 20-Aug-23
  # ======================================================================== #
  if i.include? 'Screen version'
    i = i.scan(
      /Screen version (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first
  end
  # ======================================================================== #
  # === Handle valgrind next:
  # ======================================================================== #
  if i.include? 'valgrind-'
    i = i.split('-').last
  end
  # ======================================================================== #
  # === Handle gimp next:
  #
  # The String may look like this: 'GNU Image Manipulation Program version 2.10.36' 
  # ======================================================================== #
  if i.include?('GNU Image Manipulation')
    i = i.scan(
      /GNU Image Manipulation Program version (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first
  end
  # ======================================================================== #
  # === Handle IceWM here.
  #
  # The specific substring is:
  #
  #   "IceWM 3.4.7, Copyright 1997-2012 Marko Macek, 2001 Mathias Hasselmann."
  #
  # ======================================================================== #
  if i.include? 'IceWM '
    i = i.scan(
      /IceWM (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle 'KDE Frameworks: 5.73.0'
  # ======================================================================== #
  if i.include? 'KDE Frameworks: '
    i = i.scan(
      /KDE Frameworks: (\d{0,2}\.\d{0,3}\.\d{0,2})/ # Must match e. g. "KDE Frameworks: 5.115.0".
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle 'lighttpd' next
  # ======================================================================== #
  if i.include? '- a light and fast webserver'
    i = i.split('- a light and fast webserver').first
    i = i.split('/').last if i.include?('/')
  end
  # ======================================================================== #
  # === Handle flatpak next:
  # ======================================================================== #
  if i.include? 'Flatpak '
    i = i.split('Flatpak ').last
  end
  # ======================================================================== #
  # === Handle xinput next:
  # ======================================================================== #
  if i.include? 'xinput version '
    i = i.split(' ').last
  end
  # ======================================================================== #
  # === Handle vim next
  # ======================================================================== #
  if i.include? 'IMproved ' # For Vim.
    i = i.scan(
      /VIM - Vi IMproved (\d{1,2}\.\d{1,2})/
    ).flatten.first
  end
  # ======================================================================== #
  # === Handle xfs next:
  # ======================================================================== #
  if i.include? 'xfs_info'
    i.sub!(/xfs_info/,'')
  end
  # ======================================================================== #
  # === Handle rsync next:
  # ======================================================================== #
  if i.include? 'rsync  version '
    i = i.split('rsync  version ').last
    i = i.split(' ').first if i.include?(' ')
  end
  # ======================================================================== #
  # === Handle clang next:
  # ======================================================================== #
  if i.include? 'clang version ' # clang version 18.1.2
    i = i.split('clang version ').last.strip
  end
  # ======================================================================== #
  # === Handle git next:
  # ======================================================================== #
  if i.include? 'git version ' # git version
    i = i.split('git version ').last
  end
  # ======================================================================== #
  # === Handle gnuplot next:
  # ======================================================================== #
  if i.include? 'gnuplot ' # gnuplot version
    i = i.split('gnuplot ').last
  end
  # ======================================================================== #
  # === Handle gperf next:
  # ======================================================================== #
  if i.include? 'gperf ' # gperf version
    i = i.split('gperf ').last
  end
  # ======================================================================== #
  # === Handle re2c next:
  # ======================================================================== #
  if i.include? 're2c '
    i = i.split('re2c ').last
  end
  # ======================================================================== #
  # === Handle plzip next:
  # ======================================================================== #
  if i.include? 'plzip '
    i = i.split('plzip ').last
  end
  # ======================================================================== #
  # === Handle PHP next:
  # ======================================================================== #
  if i.include? 'PHP '
    i = i.scan(
      /PHP (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first
  end
  # ======================================================================== #
  # === Handle dhcpcd next:
  # ======================================================================== #
  if i.include? 'dhcpcd '
    i = i.split('dhcpcd ').last
  end
  # ======================================================================== #
  # === Handle bubblewrap next:
  # ======================================================================== #
  if i.include? 'bubblewrap '
    i = i.split('bubblewrap ').last
  end
  # ======================================================================== #
  # === Handle cmake next:
  # ======================================================================== #
  if i.include? 'cmake version '
    i = i.split('cmake version ').last
  elsif i.include? 'cmake '
    i = i.split('cmake ').last
  end
  # ======================================================================== #
  # === Handle flex next:
  # ======================================================================== #
  if i.include? 'flex '
    i = i.split('flex ').last
  end
  # ======================================================================== #
  # === Handle file next:
  # ======================================================================== #
  if i.include? 'file-'
    i = i.split('file-').last
  end
  # ======================================================================== #
  # === Handle gzip next:
  # ======================================================================== #
  if i.include? 'gzip '
    i = i.split('gzip ')[1]
  end
  # ======================================================================== #
  # === Handle groff next:
  # ======================================================================== #
  if i.include? 'groff '
    i = i.split('groff ')[1]
    if i.include? 'version'
      i = i.split('version').last.strip
    end
  end
  # ======================================================================== #
  # === Handle ethtool next:
  # ======================================================================== #
  if i.include? 'ethtool '
    i = i.split('ethtool ')[1]
  end
  # ======================================================================== #
  # === Handle tmux next:
  # ======================================================================== #
  if i.include? 'tmux '
    i = i.split('tmux').last.strip
  end
  # ======================================================================== #
  # === Handle sysstag next:
  # ======================================================================== #
  if i.include? 'sysstat version '
    i = i.split('sysstat version').last.to_s.strip
  end
  # ======================================================================== #
  # === Handle samtools next:
  # ======================================================================== #
  if i.include? 'samtools '
    i = i.split('samtools ').last.to_s.strip
  end
  # ======================================================================== #
  # === Handle the Linux kernel next
  # ======================================================================== #
  if i.start_with?('Linux ')
    i = i.scan(
      /(\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle the xz-utils next:
  # ======================================================================== #
  if i.include? 'xz (XZ Utils)'
    i = i.split('xz (XZ Utils)').last
  end
  # ======================================================================== #
  # === Handle xterm next:
  # ======================================================================== #
  if i.include? 'XTerm('
    i = i.split('XTerm(').last.delete(')')
  end
  # ======================================================================== #
  # === Handle gnuplot:
  # ======================================================================== #
  if i.include? ' patchlevel'
    i = i.split('patchlevel').first
  end
  # ======================================================================== #
  # === Handle patch next:
  # ======================================================================== #
  if i.include? 'GNU patch '
    i = i.split('GNU patch ').last
  end
  # ======================================================================== #
  # === Handle simple-scan:
  # ======================================================================== #
  if i.include? 'simple-scan '
    i = i.split('simple-scan').last
  end
  # ======================================================================== #
  # === Handle ffmpeg next:
  # ======================================================================== #
  if i.include? 'ffmpeg version'
    # ffmpeg version N-114276-g7f4b8d2f5e Copyright (c) 2000-2024 the FFmpeg developers
    i = i.scan(/ffmpeg version (.+) /).flatten.first.to_s
    i = i.split(' ').first if i.include? ' '
    if i.include? '-'
      i = i.scan(
        /-(\d{5,6})-/
      ).flatten.first.to_s
    end
  end
  # ======================================================================== #
  # === Handle GCC next:
  #
  # The String we are looking for is like:
  #
  #   "gcc version: 14.0.1 20240326 (experimental)"
  #
  # ======================================================================== #
  if i.include?('gcc (GCC)') or i.include?('gcc version')
    first_line = i.split("\n").first
    i = first_line.split('gcc (GCC) ').last.strip
    if i.include? ' '
      i = i.split(' ').first
    end
  end
  # ======================================================================== #
  # === Handle Lynx next
  # ======================================================================== #
  if i.include? 'Lynx Version ' # Lynx Version 2.9.0 (15 Jan 2024)
    i = i.scan(
      /Lynx Version (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === openjdk
  # ======================================================================== #
  if i.include? 'openjdk'
    i = i.scan(/openjdk version "(\d{1,2}\.\d{1,2}\.\d{1,2})"/).flatten.first
  end
  # ======================================================================== #
  # if i.include? 'GNOME Document Viewer'
  #   i.sub!(/GNOME Document Viewer/,'') # For evince specifically.
  # end
  # ======================================================================== #
  if i.include? 'GNU'
    i.gsub!(/GNU/,'')
  end
  # ======================================================================== #
  # === Handle ruby 'ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]'
  # ======================================================================== #
  if i.include? 'ruby '
    i = i.scan(
      /^ruby (\d{1,1}\.\d{1,1}\.\d{1,1})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle 'ncurses 6.2.20200212' aka ncurses
  # ======================================================================== #
  if i.include? 'ncurses '
    i = i.scan(
      /ncurses (\d{1,1}\.\d{1,1})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle Imagemagick: 'Version: ImageMagick 7.0.10-28'
  # ======================================================================== #
  if i.include? 'Version: ImageMagick '
    i = i.scan(
      /Version: ImageMagick (\d{0,2}\.\d{0,2}\.\d{0,2}-\d{0,2})/
    ).flatten.first.to_s.tr('-','.')
  end
  # ======================================================================== #
  # === Handle Qt next:
  # ======================================================================== #
  if i.include? 'uic ' # uic 5.15.12
    i = i.split('uic ').last
  elsif i.include? 'Using Qt version' # Using Qt version 6.6.3 in
    i = i.scan(
      /Using Qt version (\d{1,2}\.\d{1,2}\.\d{1,2})/
    ).flatten.first
  end
  # ======================================================================== #
  # === Handle perl next:
  # ======================================================================== #
  if i.include?('This is perl') and i.include?('(v') # "This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-linux",
    # ====================================================================== #
    # Alternatively we could use this regex:
    #
    #   /\(v(\d{0,2}\.?\d{0,2}\.\d{0,2})\)/
    #
    # ====================================================================== #
    i = i.scan(
      /\((v\d{1,2}\.\d{1,2}\.\d{1,2})\)/
    ).flatten.first.to_s.dup
  end
  # ======================================================================== #
  # === Handle awk next:
  # ======================================================================== #
  if i.include? 'Awk '
    i = i.scan(/Awk (\d{1,2}\.\d{1,2}\.\d{1,2})/).flatten.first
  end
  # ======================================================================== #
  # === Handle patchelf '0.12.20200827.8d3a16e'
  #
  # This can also include output such as "patchelf 0.14.3".
  # ======================================================================== #
  if i.include? 'patchelf '
    i = i.scan(
      /^patchelf (\d{1,1}\.\d{1,2}\.?\d{0,2})/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Work on NASM next:
  # ======================================================================== #
  if i.include? 'NASM ' # "NASM version 2.16.01 compiled on Mar 23 2024"
    scanned = i.scan(
      /NASM\s*version\s*(\d{1,2}\.\d{1,2}\.\d{1,2})/
    )
    i = scanned.flatten.first.to_s.strip
  end
  # ======================================================================== #
  # === Handle bzip2 next:
  # ======================================================================== #
  if i.include? 'bzip2, a block'
    i = i.scan(
      /Version (\d{1,2}\.\d{1,2}\.\d{1,2}),/
    ).flatten.first.to_s
  end
  # ======================================================================== #
  # === Handle emacs next:
  # ======================================================================== #
  if i.include? 'Emacs '
    i.sub!(/Emacs/,'')
  end
  # ======================================================================== #
  # === bzip2recover
  # ======================================================================== #
  if i.include? 'extracts blocks from damag'
     i = i.scan(
      /bzip2recover (\d{0,2}\.\d{0,2}\.\d{0,2}): extracts blocks from damaged .bz2 files/
    ).flatten.first.to_s.dup
  end
  # ======================================================================== #
  # === Handle Python next:
  # ======================================================================== #
  if i.include? 'Python ' # Python 3.11.7
    i.sub!(/Python /,'')
  end
  # ======================================================================== #
  # === Remove "built on linux-gnu":
  # ======================================================================== #
  if i.include? ' built on linux-gnu.'
    i.gsub!(/ built on linux-gnu\./, '') # Fixing wget specifically.
  end
  # ======================================================================== #
  # === Remove 'Wget' substring:
  # ======================================================================== #
  if i.include? 'Wget'
    i.sub!(/Wget/,'')
    i.strip!
  end
  if i.include? 'built on'
    i = i.split(/built on/).first
  end
  # ======================================================================== #
  # === Handle "Midnight Commander" next:
  # ======================================================================== #
  if i.include? 'Midnight Commander'
    i.gsub!(/Midnight Commander/, '')
  end
  # ======================================================================== #
  # === Eliminate '.git'
  # ======================================================================== #
  if i.include? '.git'
    i.sub!(/\.git/,'')
  end 
  # ======================================================================== #
  # === Remove the substring 'GNU' next; this should come fairly late:
  # ======================================================================== #
  if i.include? 'GNU'
    i.sub!(/GNU/,'')
  end
  # ======================================================================== #
  # === For rsync specifically
  # ======================================================================== #
  if i.include? 'protocol version'
    i = i.split('protocol version').first
  end
  # ======================================================================== #
  # === Remove '#'
  # ======================================================================== #
  if i.include? ' #' # Handle "uname -a" aka Linux darkstar.example.net 5.4.50 #1 SMP
    i = i.split(' #').first.strip 
  end
  if i.start_with? 'v'
    i = i.dup
    i[0,1] = ''
  end
  return i
end

.science_cluster?Boolean

#

EnvironmentInformation.science_cluster?

#

Returns:

  • (Boolean)


321
322
323
# File 'lib/environment_information/constants/constants.rb', line 321

def self.science_cluster?
  ARRAY_SCIENCE_CLUSTER
end

.screen_resolutionObject

#

EnvironmentInformation.screen_resolution (screen tag)

This method will typically make use of xdpyinfo first, as it also works in a .cgi environment. For non-cgi environments, on linux, we could use xrandr, which is a bit more elegant.

On success, the method here will return a String such as “1920x1080”.

#


687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 687

def self.screen_resolution
  result = '(unknown)' # This is the default return-value, then.
  # ======================================================================= #
  # === Check for linux as host OS first
  # ======================================================================= #
  if RUBY_PLATFORM.downcase.include? 'linux'
    # ================================================================= #
    # We have to be careful as xdpyinfo may not be installed on the
    # given computer system.
    # ================================================================= #
    # resolution = `xdpyinfo #{ERROR_LINE}`.scan(/dimensions:.+$/).first # The error here may be: "xdpyinfo:  unable to open display"
    resolution = silent_sys_command('xdpyinfo').scan(/dimensions:.+$/).first # The error here may be: "xdpyinfo:  unable to open display"
    if resolution and resolution.include? ':'
      result = resolution.split(':').last.strip.split('pixels').first.strip # Or split on: /(\d{1,5}x\d{1,4})/
    end
  # ======================================================================= #
  # === Else simply assume the computer to run windows here
  # ======================================================================= #
  else
    result = `wmic desktopmonitor get screenheight,screenwidth #{ERROR_LINE}`
  end
  return result
end

.set_prefix_to_use(i) ⇒ Object

#

EnvironmentInformation.set_prefix_to_use

#


156
157
158
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 156

def self.set_prefix_to_use(i)
  @prefix_to_use = i.to_s.dup
end

.set_use_colours(i = true) ⇒ Object

#

EnvironmentInformation.set_use_colours

Determine whether the EnvironmentInformation project will use colours or whether it will not.

#


103
104
105
# File 'lib/environment_information/colours/colours.rb', line 103

def self.set_use_colours(i = true)
  @use_colours = i
end

.sfancy(i = '') ⇒ Object

#

EnvironmentInformation

#


245
246
247
248
# File 'lib/environment_information/colours/colours.rb', line 245

def self.sfancy(i = '')
  return ::Colours.sfancy(i) if Object.const_defined? :Colours
  return i
end

.sfile(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.sfile

#


218
219
220
221
222
223
224
# File 'lib/environment_information/colours/colours.rb', line 218

def self.sfile(
    i           = '',
    use_colours = @use_colours
  )
  return ::Colours.sfile(i) if use_colours
  return i
end

.show_all_available_components(n_ljust = 18, show_these_components = tracked_programs?, , use_colours = use_colours? ) ⇒ Object

#

EnvironmentInformation.show_all_available_components

This method will quickly and easily show all available (registered) components. If you need more fine-tuning when you wish to display the main dataset at hand, then you should use other methods that are also a bit more complex. This method here is really just a fast version-display overview.

The second argument to this method contains the programs that we wish to display through this method.

#


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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
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
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 280

def self.show_all_available_components(
    n_ljust               = 18,
    show_these_components = tracked_programs?,
    use_colours           = use_colours?
  )
  clear_main_hash
  if show_these_components.is_a? Array
    show_these_components.flatten!
  end
  # ======================================================================= #
  # The next variable determines whether we will also compare the
  # program versions.
  # ======================================================================= #
  compare_program_versions = false
  default_nljust_value = 30 # ← Detemine default padding.
  if n_ljust.is_a?(Array) and n_ljust.empty?
    n_ljust = default_nljust_value # Use the default value in this case.
  end
  # ======================================================================= #
  # First we will treat n_ljust as a commandline-flag if it is a String
  # and additionally begins with "--".
  # ======================================================================= #
  if n_ljust.is_a?(Array) and n_ljust.first.start_with?('--')
    _ = n_ljust.first
    case _
    # ===================================================================== #
    # === --help
    #
    # Invocation example:
    #
    #   showcomponents --help
    #
    # ===================================================================== #
    when /^-?-?help$/i
      e 'The following options are available for bin/fast_envi (fenvi):'
      e
      e '   --xorg                        # show only the xorg-components'
      e '   --compare-to-program-versions # also compare the program versions'
      e
      exit
    # ===================================================================== #
    # === --compare-to-program-versions
    #
    # To invoke this, try:
    #
    #   show_components --compare
    #   envi --compare-version
    #
    # ===================================================================== #
    when *ARRAY_COMPARE_PROGRAM_VERSIONS
      compare_program_versions = true
      n_ljust = default_nljust_value
    # ===================================================================== #
    # === --xorg
    # ===================================================================== #
    when /^-?-?xorg$/i
      show_these_components = ::EnvironmentInformation.xorg_components?
      n_ljust = default_nljust_value
    end
  end
  e
  uniq = show_these_components.uniq
  uniq.sort.each {|this_program|
    use_this_name_for_send = "return_version_of_#{this_program}"
    # ===================================================================== #
    # Next, add the name of the program at hand, onto the left hand side:
    # ===================================================================== #
    result = this_program.to_s.ljust(n_ljust)
    if use_colours
      result = ::EnvironmentInformation.colourize_and_pad_the_left_side(result)
    end
    # ===================================================================== #
    # Some components may not be installed on the user's computer system,
    # which we have to keep in mind in the following code. This is
    # why we will first apply the .send(), before checking whether
    # the program at hand is actually missing or not.
    # ===================================================================== #
    result_of_send = send(use_this_name_for_send)
    if result_of_send
      result_of_send = result_of_send.dup if result_of_send.frozen?
      result_of_send.strip!
    end
    @hash_available_programs[this_program.to_sym] = result_of_send.to_s
    right_component = ''.dup
    if @array_this_component_is_missing.include?(this_program.to_sym)
      right_component << "not installed (or otherwise not found)".ljust(12)
    else
      right_component << result_of_send.ljust(12) if result_of_send
    end
    if use_colours
      # =================================================================== #
      # We will distinguish between components that have been found and
      # components that have not been found.
      # =================================================================== #
      if right_component.include?('not installed')
        right_component = ::Colours.send(:mediumslateblue, right_component)
      else
        right_component = ::Colours.send(colour_for_the_right_side, right_component)
      end
    end
    result = result.dup if result.frozen?
    result << right_component
    if compare_program_versions
      if is_this_program_included?(this_program)
        registered_local_version = RBT.swift_return_version_of_this_program(this_program.to_sym).to_s.dup
        if registered_local_version.include? 'v'
          # =============================================================== #
          # Modify entries such as 'v12.15.0' into '12.15.0'.
          # =============================================================== #
          registered_local_version.delete!('v')
        end
        case this_program.to_s
        when 'gtk2'
          registered_local_version = query_pkgconfig_version_for(:gtk2)
        else
          if result_of_send.nil?
            # ^^^ This is missing, then, so it will be ignored.
          elsif registered_local_version <= result_of_send 
            # This is ok.
          else
            result << 
              royalblue(
                "\n    "\
                "^^^ This could be updated; the version in "\
                "RBT is: #{mediumpurple(registered_local_version)}"
              )
          end
        end
      end
    end
    # ===================================================================== #
    # Finally display our findings to the end user.
    # ===================================================================== #
    e result
  }
  e
  if is_on_roebe? # And store it on my home system too.
    ::EnvironmentInformation.store_relevant_files
  end
end

.show_detailed_information_about_all_available_componentsObject

#

EnvironmentInformation.show_detailed_information_about_all_available_components

This method is mostly for testing purposes only; for real use for the project you should consider making use of Environment.silent_run instead.

Do note that this method will always show all available components; if you need more fine-tuned control then you have to use the class EnvironmentInformation instead.

#


1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1549

def self.show_detailed_information_about_all_available_components
  @hash_available_programs = {} # Clear it every time this method is run. 
  work_on_these_programs = []
  work_on_these_programs << tracked_components?
  e
  work_on_these_programs.each {|this_program|
    version_of_this_program = ::EnvironmentInformation.return_version_of_this_program(this_program)
    # ===================================================================== #
    # Do a little sanitizing next:
    # ===================================================================== #
    case this_program.to_s
    when 'kde_frameworks'
      this_program = 'KDE Frameworks'.to_sym
    end
    left_side = colourize_and_pad_the_left_side(this_program)
    case version_of_this_program
    when COMMAND_NOT_FOUND,
         ''
      version_of_this_program = nil
      colour_for_the_right_side = :orange
    else
      colour_for_the_right_side = :notify_if_missing
    end
    # ===================================================================== #
    # Next register this program into the main hash.
    # ===================================================================== #
    @hash_available_programs[this_program] = version_of_this_program
    right_side = colourize_and_pad_the_right_side(
      version_of_this_program,
      colour_for_the_right_side
    )
    e "  #{left_side} #{right_side}"
  }
  e
  # ======================================================================= #
  # Report missing programs.
  # ======================================================================= #
  _ = missing_components?
  unless _.empty?
    e 'The following components were not found:'
    e
    _.each {|this_component|
      e lightseagreen("  #{this_component}")
    }
    e
  end
  consider_storing_these_results_into_a_local_file
end

.show_remote_url_of_this_program(i = ARGV) ⇒ Object

#

EnvironmentInformation.show_remote_url_of_this_program

This method will try to show the remote URL of the given program.

#


841
842
843
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 841

def self.show_remote_url_of_this_program(i = ARGV)
  puts return_remote_url_of_this_program(i)
end

.silent_runObject

#

Environment.silent_run

#


1641
1642
1643
1644
1645
1646
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1641

def self.silent_run
  _ = ::EnvironmentInformation.new { :do_not_run_yet }
  _.be_silent
  _.run
  return _.hash?
end

.simp(i = '') ⇒ Object

#

EnvironmentInformation.simp

#


237
238
239
240
# File 'lib/environment_information/colours/colours.rb', line 237

def self.simp(i = '')
  return ::Colours.simp(i) if Object.const_defined? :Colours
  return i
end

.start_gtk_componentObject

#

EnvironmentInformation.start_gtk_component

We have to rescue the code so to notify the user what exactly may have failed.

#


1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1136

def self.start_gtk_component
  begin
    this_file = 'environment_information/gui/gtk3/environment_information.rb'
    require this_file
  rescue LoadError => error
    e "An error happened - file #{sfile(this_file)} could not be found."
    pp error
  end
  ::EnvironmentInformation.run_gtk
end

.start_sinatra_interfaceObject

#

EnvironmentInformation.start_sinatra_interface

This method can be used to start the sinatra interface.

#


207
208
209
210
# File 'lib/environment_information/www/sinatra_interface.rb', line 207

def self.start_sinatra_interface
  puts 'Trying to start the sinatra-interface of EnvironmentInformation next.'
  ::EnvironmentInformation::Sinatra.run!
end

.steelblue(i = '') ⇒ Object

#

EnvironmentInformation.steelblue

#


186
187
188
189
190
191
# File 'lib/environment_information/colours/colours.rb', line 186

def self.steelblue(i = '')
  if @use_colours
    return ::Colours.steelblue(i)
  end
  return i
end

.store_this_hash_into_a_local_file(hash = hash_available_programs?, , this_file = return_path_to_all_programs_file, be_verbose = false) ⇒ Object

#

EnvironmentInformation.store_this_hash_into_a_local_file

This method will always take the dataset stored in the main Hash when saving the yaml file at hand.

The file will be stored under the temp_directory.

This variant is silent by default.

#


1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 1661

def self.store_this_hash_into_a_local_file(
    hash       = hash_available_programs?,
    this_file  = return_path_to_all_programs_file,
    be_verbose = false
  )
  unless hash.empty?
    what = YAML.dump(hash)
    e "#{rev}Storing these #{royalblue(hash.size)} "\
      "#{rev}components into: #{sfile(this_file)}" if be_verbose
    ::EnvironmentInformation.write_what_into(what, this_file)
  end
end

.temp_directory?(i = @temp_directory) ⇒ Boolean

#

EnvironmentInformation.temp_directory?

This method will refer to the temp-directory in use for this project.

It is advised to make use of the method, rather than the TEMP_DIRECTORY constant, as that is more convenient in the long run.

#

Returns:

  • (Boolean)


104
105
106
107
108
# File 'lib/environment_information/constants/constants.rb', line 104

def self.temp_directory?(
    i = @temp_directory
  )
  i.squeeze('/').dup
end

.tomato(i = '', use_colours = @use_colours) ⇒ Object

#

EnvironmentInformation.tomato

#


140
141
142
143
144
145
146
# File 'lib/environment_information/colours/colours.rb', line 140

def self.tomato(
    i           = '',
    use_colours = @use_colours
  )
  return ::Colours.tomato(i) if use_colours
  return i
end

.tracked_components?Boolean

#

EnvironmentInformation.tracked_components?

#

Returns:

  • (Boolean)


292
293
294
295
296
297
# File 'lib/environment_information/constants/constants.rb', line 292

def self.tracked_components?
  [
    ARRAY_TRACKED_PROGRAMS+
    ARRAY_TRACKED_NON_PROGRAMS
  ].flatten
end

.tracked_non_programs?Boolean

#

EnvironmentInformation.tracked_non_programs?

Simpler toplevel-method to find out which non-programs are registered within the EnvironmentInformation project.

#

Returns:

  • (Boolean)


305
306
307
# File 'lib/environment_information/constants/constants.rb', line 305

def self.tracked_non_programs?
  ARRAY_TRACKED_NON_PROGRAMS
end

.tracked_programs?Boolean

#

EnvironmentInformation.tracked_programs?

Simpler toplevel-method to find out which programs are registered within the EnvironmentInformation project.

#

Returns:

  • (Boolean)


370
371
372
# File 'lib/environment_information/constants/constants.rb', line 370

def self.tracked_programs?
  ARRAY_TRACKED_PROGRAMS
end

.tracked_xorg_components?Boolean

#

EnvironmentInformation.tracked_xorg_components?

#

Returns:

  • (Boolean)


264
265
266
# File 'lib/environment_information/constants/constants.rb', line 264

def self.tracked_xorg_components?
  ARRAY_TRACKED_XORG_COMPONENTS
end

.use_colours?Boolean

#

EnvironmentInformation.use_colours?

#

Returns:

  • (Boolean)


33
34
35
# File 'lib/environment_information/colours/colours.rb', line 33

def self.use_colours?
  @use_colours
end

.verbose_truth(i) ⇒ Object

#

Environment.verbose_truth

#


503
504
505
506
507
508
509
510
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 503

def self.verbose_truth(i)
  case i
  when /true/
    'Yes.'
  when /false/
    'No.'
  end
end

.write_what_into(what, into) ⇒ Object

#

EnvironmentInformation.write_what_into

#


896
897
898
899
900
901
902
# File 'lib/environment_information/toplevel_methods/toplevel_methods.rb', line 896

def self.write_what_into(
    what,
    into
  )
  what = what.join("\n") if what.is_a? Array
  File.open(into, 'w+') {|entry| entry.write(what) }
end