class EnvironmentInformation::EnvironmentInformation
Constants
- THE_PROGRAM_IS_NOT_INSTALLED_OR_COULD_NOT_BE_FOUND
#¶ ↑
THE_PROGRAM_IS_NOT_INSTALLED_OR_COULD_NOT_BE_FOUND
¶ ↑#¶ ↑
- THIS_FILE
#¶ ↑
EnvironmentInformation::EnvironmentInformation::THIS_FILE
¶ ↑THIS_FILE
= __FILE__We hardcode this since it is only relevant on my home system, anyway.
#¶ ↑
- TRY_TO_USE_HTML_COLOURS
#¶ ↑
EnvironmentInformation::EnvironmentInformation::TRY_TO_USE_HTML_COLOURS
¶ ↑If true then we will try to use the konsole-colours, when possible.
These are part of the colours gem, so this adds a dependency on the colours gem.
#¶ ↑
Public Class Methods
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 76 def initialize( commandline_arguments = nil, run_already = true ) register_sigint reset # ======================================================================= # # Next, we handle special run-mode variants. # ======================================================================= # case run_already when :do_show_everything do_show_everything run_already = true end # ======================================================================= # # And set @run_already, so that menu() can overrule it lateron. # ======================================================================= # @run_already = run_already set_commandline_arguments( commandline_arguments ) # ======================================================================= # # === Handle blocks # # Next blocks will be handled. This must come after the reset() method. # ======================================================================= # if block_given? yielded = yield case yielded # case tag # ===================================================================== # # === :do_not_use_rbt # ===================================================================== # when :do_not_use_rbt @internal_hash[:may_we_try_to_use_rbt] = false # ===================================================================== # # === :disable_colours # ===================================================================== # when :disable_colours disable_colours # ===================================================================== # # === :disable_colours_and_do_not_store_into_a_local_file # ===================================================================== # when :disable_colours_and_do_not_store_into_a_local_file disable_colours do_not_save_anything # ===================================================================== # # === :do_not_run_yet # ===================================================================== # when :do_not_run_yet @run_already = false else # =================================================================== # # Handle Hashes given in the block. # =================================================================== # if yielded.is_a? Hash # ================================================================= # # === :use_n_tokens # ================================================================= # if yielded.has_key? :use_n_tokens set_use_n_tokens(yielded.delete(:use_n_tokens)) # ================================================================= # # === :n_tokens # ================================================================= # elsif yielded.has_key? :n_tokens set_use_n_tokens(yielded.delete(:n_tokens)) end # ================================================================= # # === :use_colours # ================================================================= # if yielded.has_key? :use_colours set_use_colours(yielded.delete(:use_colours)) end # ================================================================= # # === :be_silent # ================================================================= # if yielded.has_key? :be_silent set_be_silent(yielded.delete(:be_silent)) end # ================================================================= # # === :show_ruby_stuff # ================================================================= # if yielded.has_key? :show_ruby_stuff if yielded.delete(:show_ruby_stuff) == false dont_show_ruby_stuff end end end end end # ======================================================================= # # First, we will add the default programs on a linux computer. The # later invocation to menu() can change this, but we also want to # provide "useful defaults" for users to benefit from this gem. # ======================================================================= # add_the_default_programs_on_a_linux_computer # ======================================================================= # # Add the ruby components next. This must come before menu(). # ======================================================================= # consider_adding_the_ruby_components # ======================================================================= # # Invoke menu() to query and honour the commandline arguments. # ======================================================================= # menu run if @run_already end
Public Instance Methods
#¶ ↑
add (add tag)¶ ↑
This method can be used to add individual entries to the main array called @array_report_these_programs.
The format for add() contains only one component, which appears on the left side, and denotes the name of the program or component that we wish to query, such as “php” or “ruby” and so forth.
Some Symbols will be used as a “pointer” towards an Array of registered programs.
Note that (1) will be converted into a Symbol if it is a String.
If the second entry (2) is nil, then the version will be inferred at “runtime” within the method display(). Otherwise display() will simply use the passed version (which should be a String in that case, then).
Before we can add an entry to the main dataset, we have to check whether it is a registered entry altogether. If it is not registered, the user has to be notified about this fact. This notification will ONLY happen if the associated version is nil; if a specific version is supplied then this method will assume that the program should be displayed anyway.
An Array can also be supplied to this method, if necessary.
#¶ ↑
# File lib/environment_information/class/class.rb, line 415 def add( i ) if i.is_a?(String) and i.include?(',') # ===================================================================== # # Strings containing ',' will be split accordingly. # ===================================================================== # i = i.split(',') elsif i.is_a?(String) and i.include?('-') # ===================================================================== # # Strings containing '-' will lose that '-'. # ===================================================================== # i = i.dup if i.frozen? i.delete!('-') end [i].flatten.compact.each {|entry| case entry # ===================================================================== # # === :everything # # This entry point is meant for simply adding everything. # ===================================================================== # when :everything entry = return_every_registered_component # ===================================================================== # # === Rubygems installation directory # ===================================================================== # when :rubygems_installation_directory, /^rubygems( |_)?installation( |_)?directory\??$/i entry = 'rubygems_installation_directory' # ===================================================================== # # === cflags # ===================================================================== # when :cflags, /^cflags$/i entry = 'CFLAGS in use' # ===================================================================== # # === screen_resolution # ===================================================================== # when :screen_resolution, /^screen( |_)?resolution$/i entry = 'Screen Resolution' # ===================================================================== # # === ram # ===================================================================== # when :ram, /^ram$/i entry = 'RAM' # ===================================================================== # # === cpuinfo # ===================================================================== # when :cpuinfo, /^cpuinfo$/i entry = 'CPU Model' # ===================================================================== # # === operating_system_bit_type # ===================================================================== # when :operating_system_bit_type, /^operating(_|-)?system(_|-)?bit(_|-)?type$/i entry = 'Operating system bit type' # ===================================================================== # # === :operating_system # ===================================================================== # when :operating_system, /^operating(_|-)?system$/i, /^operating(_|-)?system(_|-)?in(_|-)?use$/i entry = 'Operating system' # ===================================================================== # # === cpflags # ===================================================================== # when /^cflags$/i, /^CFLAGS in use$/i entry = 'CFLAGS in use' # ===================================================================== # # === :pkgconfig_entries # ===================================================================== # when :pkgconfig_entries entry = ::EnvironmentInformation.return_pkgconfig_based_programs # ===================================================================== # # === :all_xorg_components # ===================================================================== # when :all_xorg_components entry = return_all_xorg_components # ===================================================================== # # === envi --science # ===================================================================== # when :science_cluster entry = ARRAY_SCIENCE_CLUSTER # ===================================================================== # # === envi --lfs_core_programs # ===================================================================== # when :lfs, :lfs_core_programs entry = ::EnvironmentInformation.lfs_core_programs? # ===================================================================== # # === :linux_kernel # ===================================================================== # when :linux_kernel i = :linux # ===================================================================== # # === :RAM # ===================================================================== # when :RAM entry = :ram # Just the "alias" to the real entry. end unless @array_report_these_programs.include? entry @array_report_these_programs << entry @array_report_these_programs.flatten! end } end
#¶ ↑
add_the_default_programs_on_a_linux_computer
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 534 def add_the_default_programs_on_a_linux_computer # ======================================================================= # # Add the default programs on a linux computer. # ======================================================================= # add( return_default_programs_on_a_linux_computer ) end
#¶ ↑
add_this_to_the_toplevel_hash
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 555 def add_this_to_the_toplevel_hash(a, b) a = a.to_sym unless a.is_a? Symbol ::EnvironmentInformation.hash?[a] = b end
#¶ ↑
assign_components_for_the_short_format
¶ ↑
We will only display 6 components when we use the short variant.
#¶ ↑
# File lib/environment_information/class/class.rb, line 898 def assign_components_for_the_short_format clear_old_dataset dont_show_ruby_stuff add(%i( operating_system operating_system_bit_type cpuinfo cflags RAM screen_resolution )) end
#¶ ↑
be_silent
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1012 def be_silent @be_silent = true end
#¶ ↑
compare_program_versions?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1481 def compare_program_versions? @internal_hash[:compare_program_versions] end
#¶ ↑
consider_adding_the_ruby_components
¶ ↑
This method can be used to consider adding the ruby-components, which means “ruby” itself, rubygems “gem”, and the rubygems installation directory.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1632 def consider_adding_the_ruby_components if @show_ruby_version_and_gem_version add( return_all_ruby_components # Combine three calls into one here - all related to ruby. ) end end
#¶ ↑
consider_storing_the_components_that_were_displayed
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 846 def consider_storing_the_components_that_were_displayed if store_the_results_into_local_files? ::EnvironmentInformation.consider_storing_these_results_into_a_local_file end end
#¶ ↑
consider_storing_which_programs_are_not_up_to_date
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1341 def consider_storing_which_programs_are_not_up_to_date if shall_we_really_store_which_programs_are_not_up_to_date? into = FILE_THESE_PROGRAMS_CAN_BE_UPGRADED what = YAML.dump(@array_these_programs_not_up_to_date) if File.directory?('/home/Temp/rbt/') into = "/home/Temp/rbt/#{File.basename(into)}" else into = "#{log_dir?}#{File.basename(into)}" end opnn; e 'We will also store which programs are not up to date.' opnn; e "These will be stored into the file at `#{sfile(into)}`." ::EnvironmentInformation.write_what_into(what, into) end end
#¶ ↑
dataset_as_string
¶ ↑
This method must return the dataset in String format. That String must already be properly “formatted”.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1191 def dataset_as_string _ = ''.dup # Put the information onto that String here. main_dataset?.each {|entry| if entry.is_a? Array entry = entry.first # The second entry is ignored in that event. end # ===================================================================== # # Before we can use .send() we have to check whether EnvironmentInformation # actually responds to that method. If not then we will simply skip # this snippet for now; but this may have to be changed at some # point in the future, to more elegantly handle failure. (Sep 2019). # ===================================================================== # use_this_method = "return_version_of_#{entry}".to_sym if ::EnvironmentInformation.respond_to? use_this_method program_version = ::EnvironmentInformation.send( use_this_method ) entry = " #{entry}:" _ << "#{entry} #{program_version}#{N}" end } return _ # And return the generated String. end
#¶ ↑
disable_colours
¶ ↑
Call this method when you wish to disable the colours. Note that this will disable colours on the toplevel.
#¶ ↑
# File lib/environment_information/class/colours.rb, line 79 def disable_colours ::EnvironmentInformation.use_colours = false end
#¶ ↑
display_these_components?¶ ↑
Note that @display_these_components is a Hash.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1771 def display_these_components? @array_report_these_programs end
#¶ ↑
do_compare_the_program_version
¶ ↑
This method can be used if the user wishes to also compare the program version of the installed programs. This functionality depends on the rbt gem, and the RBT namespace.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1468 def do_compare_the_program_version( be_verbose = true ) if be_verbose @array_show_this_to_the_user << 'The program versions will also be compared.' end @internal_hash[:compare_program_versions] = true end
#¶ ↑
do_display_in_a_short_format
¶ ↑
The short-format means that we will use only a compact set of programs to display. For example, “make” and “bash” will not be displayed, neither “binutils” or “ruby”.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1565 def do_display_in_a_short_format @display_everything_in_short_format = true end
#¶ ↑
do_generate_a_html_file
(html tag)¶ ↑
The action-method that will generate the html file. This depends on the gem html_tags, with module HtmlTags though.
To invoke this method, do:
envi --generate-html-file
#¶ ↑
# File lib/environment_information/class/class.rb, line 664 def do_generate_a_html_file( styling_instructions = :none ) # ======================================================================= # # === Ensure that the html_tags project is available # ======================================================================= # unless Object.const_defined? :HtmlTags begin require 'html_tags' rescue LoadError e 'html_tags is not available. Considering installing it via:' e e ' gem install html_tags' e end end # ======================================================================= # # === Define where to store the .html file in question # ======================================================================= # this_html_file = "#{::EnvironmentInformation.temp_directory?}environment_information.html" # ======================================================================= # # Obtain the main dataset next. # ======================================================================= # what = dataset_as_string case styling_instructions when :bold what = HtmlTags.b(what) end what = HtmlTags.html( HtmlTags.title('Information about the local environment')+ HtmlTags.body( HtmlTags.h1( 'Your environment', css_style: 'margin-top: 0.5em; margin-bottom: 0.5em; padding: 2px;' )+ HtmlTags.pre( what, css_style: 'font-weight: bold; font-size: 2em; padding-left: 1.0em; margin-top:2px;' ) ) ) ::EnvironmentInformation.write_what_into(what, this_html_file) # ======================================================================= # # Notify the user what has been done. # ======================================================================= # if File.exist? this_html_file opnn; e "Generated a HTML file at `#{sfile(this_html_file)}`." end end
#¶ ↑
do_not_run_already
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1098 def do_not_run_already @run_already = false end
#¶ ↑
do_not_save_anything
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1550 def do_not_save_anything @shall_the_results_be_saved = false # ======================================================================= # # We will also avoid saving the results into a local yaml file. # ======================================================================= # @internal_hash[:store_the_results_into_local_files] = false end
#¶ ↑
do_not_show_the_ruby_components
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1643 def do_not_show_the_ruby_components @show_ruby_version_and_gem_version = false end
#¶ ↑
do_rename_kde_konsole
¶ ↑
This will attempt to rename the KDE Konsole tab, but only if we are on roebe.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1051 def do_rename_kde_konsole( use_this_title = 'Environment Information' ) begin require 'roebe/requires/require_kde_konsole.rb' rescue LoadError; end if try_to_rename_the_kde_konsole_tab? and is_on_roebe? and Object.const_defined?(:Roebe) and Roebe.const_defined?(:KdeKonsole) Roebe.rename_konsole(use_this_title) end end
#¶ ↑
do_show_almost_everything_excluding_the_default_linux_programs
¶ ↑
This is similar to do_show_everything
() but it will not show the default linux programs.
#¶ ↑
# File lib/environment_information/class/class.rb, line 813 def do_show_almost_everything_excluding_the_default_linux_programs these_programs = return_every_registered_component default_programs = return_default_programs # ======================================================================= # # Next subtract those that are part in the default_programs. # ======================================================================= # these_programs.reject! {|entry| default_programs.include? entry } add(these_programs) end
#¶ ↑
do_show_everything
(everything tag, full tag)¶ ↑
This method can be used when the user wishes to enable seeing full information about his local environment (on the computer).
This will always display EVERY registered component.
Commandline invocation:
envi --everything
#¶ ↑
# File lib/environment_information/class/class.rb, line 838 def do_show_everything add(:everything) # Simply add everything. end
#¶ ↑
do_show_help
(help tag)¶ ↑
Show the commandline-usage through this method here.
To invoke this, try:
envi --help
#¶ ↑
# File lib/environment_information/class/class.rb, line 588 def do_show_help e lpad = "#{col1} " e "#{rev}The following options are available for "\ "#{simp('class EnvironmentInformation:')}#{rev}#{N}#{N}" if ASCIITABLE_IS_AVAILABLE e col1+' asciitable '+rev+'# Print in Ascii Table format' end e lpad+'html '+rev+'# Save the environment information '\ 'into a .html file' e lpad+'gui '+rev+'# Start the GTK gui bindings; some '\ 'aliases are possible such as --GUI' e lpad+'nocolours '+rev+'# Disable colours '\ '(--disable-colours also works)' e lpad+'noruby '+rev+'# dont show ruby-related environment '\ 'information' e lpad+'help '+rev+'# show some help' e lpad+'xorg '+rev+'# show some xorg-specific '\ 'components (also --xorg-components)' e lpad+'OS '+rev+'# show the OS then exit' e lpad+'full '+rev+'# show full information, including '\ 'GTK, Glib, Atk and Pango Version' e ' # ^^^ This is probably the most useful usage.' e lpad+'openssl '+rev+'# display openssl option' e lpad+'REALLY_ALL '+rev+'# also compare the program_versions '\ '(--really-everything is an alias to this)' e lpad+'save '+rev+'# display the result, then '\ 'save it into a file' e lpad+'sinatra '+rev+'# start the sinatra-interface '\ 'of the environment_information project' e lpad+'version '+rev+'# show the version of '\ 'EnvironmentInformation in use' e lpad+'--show-remote-url '+rev+'# show the remote URLs '\ 'of a program (requires the RBT project)' e lpad+'padding=value '+rev+'# set to another padding value' e lpad+'--one-liner '+rev+'# show everything compacted, without a newline' e lpad+'--nentries? '+rev+'# feedback how many entries are tracked in total' e rev+N+'The above commands should be commandline arguments, '\ 'such as: "'+teal('envi full')+rev+'".' e e "#{rev}Do note that you can prefix the above commands via "\ "a leading --, of course." e # ======================================================================= # # Show a simple usage example next: # ======================================================================= # e 'Usage example:' e e steelblue( ' envi --version' ) e e rev+'If you wish to show only some programs, you could '\ 'use the following:' e e steelblue( ' envi --use-these-programs=bash,binutils,bison,yacc,bzip2,coreutils,diff,find,gawk,gcc' ) e steelblue( ' envi --use-these-programs=:lfs' ) e true_rev # Reset via Colours.rev here. do_exit_the_program end
#¶ ↑
do_show_only_the_xorg_components
¶ ↑
This method will essentially clear the old dataset before adding all xorg-components to the display-part of this class.
The components that are appended here, are defined in the file constants/array_tracked_components.rb - so if you wish to add new xorg-related entries, you should modify the entries in that .rb file.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1128 def do_show_only_the_xorg_components clear_old_dataset do_not_show_the_ruby_components add(:all_xorg_components) end
#¶ ↑
do_sort_alphabetically
(sort tag)¶ ↑
Some entries are Symbols, which is why we have to call .to_s in the method here.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1540 def do_sort_alphabetically( display_these_components = display_which_components? ) _ = display_these_components.sort_by {|name, version| name.to_s } set_main_array(_) end
#¶ ↑
dont_show_ruby_stuff
¶ ↑
Disable showing ruby + gem information.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1608 def dont_show_ruby_stuff # Dont show ruby stuff. @show_ruby_version_and_gem_version = false end
#¶ ↑
e (e tag)¶ ↑
The e() method is the general output-method for this class.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1713 def e(i = '') unless @be_silent if use_one_line_to_show_the_result? # This will just use "print". ::EnvironmentInformation.ee(i) else ::EnvironmentInformation.e( i, display_everything_in_short_format: @display_everything_in_short_format ) end end end
#¶ ↑
is_a_registered_component?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 785 def is_a_registered_component?(i) ::EnvironmentInformation.is_this_component_included?(i) end
#¶ ↑
load_dataset_from_this_file
¶ ↑
This method can be used to read which programs will be displayed from a local file, rather than rely on the pre-set default.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1327 def load_dataset_from_this_file(i) if File.exist? i File.readlines(i).map {|entry| entry.delete('-').strip # ← Clean up the input a little bit. } else opnn; e "No file exists at `#{sfile(i)}`." end end
#¶ ↑
operating_system?¶ ↑
To quickly test this method, try:
EnvironmentInformation::EnvironmentInformation.new { :do_not_run_yet }.operating_system?
#¶ ↑
# File lib/environment_information/class/class.rb, line 1317 def operating_system? ::EnvironmentInformation.send(__method__) end
#¶ ↑
opnn¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1586 def opnn if TRY_TO_MAKE_USE_OF_THE_OPN_GEM_IF_IT_IS_AVAILABLE and Object.const_defined?(:Opn) Opn.opn({ namespace: NAMESPACE, use_colours: use_colours? }) end end
#¶ ↑
register_the_available_components_and_show_them_at_once
(report tag)¶ ↑
This method can be used to register information about the various components. It will also instantly display the component at hand, to avoid “lagging” behaviour on the commandline.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1800 def register_the_available_components_and_show_them_at_once( report_these_programs = @array_report_these_programs ) if report_these_programs.empty? opn; e 'There are no components that can be displayed.' # And this ends here. else # ===================================================================== # # Always clear the main Array before proceeding here. # ===================================================================== # clear_missing_components toplevel_hash = ::EnvironmentInformation.hash? hash_use_this_for_the_query = ::EnvironmentInformation.all_the_queries # ===================================================================== # # Iterate over the registered programs next. # ===================================================================== # report_these_programs.each {|this_program| # =================================================================== # # First, determine the left_side and the right_side. # =================================================================== # left_side = this_program.to_s.dup right_side = nil case this_program # =================================================================== # # === RAM # =================================================================== # when :ram, /^RAM$/i right_side = ram?.to_s.dup right_side = right_side.dup if right_side.frozen? # ================================================================= # # Append 'MB RAM' in orange colour next, with some padding. # This is just a small visual "enhancement" that I quite like. # ================================================================= # right_side << orange(' MB RAM') # =================================================================== # # === Rubygems installation directory # =================================================================== # when :rubygems_installation_directory, /^rubygems( |_)?installation( |_)?directory\??$/i right_side = rubygems_installation_directory? # =================================================================== # # === cflags # =================================================================== # when :cflags, /^cflags$/i, /^cflags(_|-| )?in(_|-| )?use$/i right_side = cflags_in_use? # =================================================================== # # === Screen resolution # # This is a bit "special" in the sense that we will colourize # the middle 'x', if found, and if colours are used. # =================================================================== # when :screen_resolution, /^screen( |_)?resolution$/i right_side = screen_resolution? if right_side.include?('x') and use_colours? splitted = right_side.split('x') right_side = colourize_this_in_the_right_side_colour(splitted.first)+ royalblue('x')+ colourize_this_in_the_right_side_colour(splitted.last) end # =================================================================== # # === CPU Model # =================================================================== # when /^cpuinfo$/i, /^CPU(_|-| )?Model/ right_side = cpu_model? # =================================================================== # # === Operating system bit type # =================================================================== # when /^operating(_|-| )?system(_|-| )?bit(_|-| )?type$/i right_side = bit_type? # =================================================================== # # === Operating system # =================================================================== # when /^Operating(_|-| )?system$/i, :operating_system right_side = ::EnvironmentInformation.operating_system end # =================================================================== # # Find the corresponding entry next while including aliases: # =================================================================== # this_program = this_program.to_sym # These are stored as symbol. this_program = ::EnvironmentInformation.return_alias_to(this_program) _ = hash_use_this_for_the_query[this_program] # This holds the instruction for the program at hand. if hash_use_this_for_the_query.has_key? this_program if _.to_s.start_with? 'pkg' # =============================================================== # # === :pkgconfig # # This is by far the simplest solution. # =============================================================== # right_side = @pkg_config_query.return_version_of(this_program) add_this_to_the_toplevel_hash(left_side, right_side) # ================================================================= # # === :version # # Here we will handle simple versions, e. g. "lftp --version" # entries, and similar. # ================================================================= # elsif (_ == :version) or (_ == :short_version) # =============================================================== # # Pass into class EnvironmentInformation::Queries::SimpleVersion next: # =============================================================== # right_side = @simple_version_query.return_version_of(this_program) add_this_to_the_toplevel_hash(left_side, right_side) # ================================================================= # # The next entry is specifically for the program called # double-conversion: # ================================================================= # elsif _ == :special_entry_for_doubleconversion right_side = nil target_file = '/usr/lib/cmake/double-conversion/double-conversionConfigVersion.cmake' if File.exist? target_file dataset = File.read(target_file) right_side = dataset.scan( /PACKAGE_VERSION "(.+)"/ ).flatten.first.to_s end if right_side add_this_to_the_toplevel_hash(left_side, right_side) end else # =============================================================== # # Else we will pass through class ComplexVersion: # =============================================================== # right_side = @complex_version_query.return_version_of(this_program) add_this_to_the_toplevel_hash(left_side, right_side) end # =================================================================== # # The next clause has been written specifically to allow querying # the mate-desktop components. # =================================================================== # elsif toplevel_hash.has_key?(this_program) and toplevel_hash[this_program] # ← This is thus non-nil. right_side = toplevel_hash[this_program] end if right_side.nil? register_unavailable_program(this_program) end # =================================================================== # # === @internal_hash[:report_the_remote_urls] # # Next, honour @internal_hash[:report_the_remote_urls] if it is # set to true. # =================================================================== # if report_the_remote_urls? and is_rbt_available? and RBT.respond_to?(:remote_url_for?) version = ''.dup _ = this_program.to_s.delete('-').downcase.strip.to_sym if RBT.does_include?(_) remote_url = RBT.remote_url_for?(_, :return_as_string) if is_a_registered_component? _ if version.frozen? version = version.dup end version << lightgreen(remote_url) if right_side # We can only continue if the program is available. # In theory we could show the URL anyway, but for the time # being, at the least, we will not show the URL. right_side = right_side.dup if right_side.frozen? right_side << " #{olive('→')} #{version}" end end end end # =================================================================== # # The next method is defined in base.rb. # =================================================================== # report_left_right( left_side, right_side, :default_colour, :default_colour, :default_colour, !use_one_line_to_show_the_result? ) # =================================================================== # # Next compare the program versions with the local versions. # =================================================================== # if compare_program_versions? and is_rbt_available_and_may_we_try_to_use_rbt? and RBT.respond_to?(:swift_return_version_of_this_program) and RBT.does_include?(left_side.to_s.strip) # ================================================================= # # Example: # # RBT.swift_return_version_of_this_program(:gettext) # # ================================================================= # registered_local_version = RBT.swift_return_version_of_this_program( left_side.to_s.strip.to_sym ).to_s # ================================================================= # # We ignore gtk2 when it comes to the version-check. # ================================================================= # next if this_program == :gtk2 # ================================================================= # # Next use Gem::Version to compare them, but not if the version # is nil. # ================================================================= # unless right_side.nil? # =============================================================== # # The .delete('v') is specifically for libuv or node. # =============================================================== # registered_local_version = registered_local_version.to_s. delete('v'). tr('_','.') a = compare_via_gem_version(registered_local_version) b = compare_via_gem_version(right_side) if a and b and (a > b) result = ''.dup if use_one_line_to_show_the_result? result << mediumaquamarine(' ← ') else # else this is the default. result << lightblue(' ^^^^ ') end result << slateblue('This program could be '\ 'upgraded, to the version ')+ steelblue(registered_local_version) e result end if registered_local_version =~ /\d+/ end end } end end
#¶ ↑
report_the_installed_KDE_software_suite
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 723 def report_the_installed_KDE_software_suite begin require 'rbt/toplevel_methods/toplevel_methods.rb' require 'rbt/toplevel_methods/try_to_return_a_special_compile_component.rb' require 'rbt/toplevel_methods/swift_return_version_of_this_program.rb' array = RBT.return_kde_apps append_this = ''.dup if array and !array.empty? e 'Now working through all registered KDE applications, trying to' e 'show their version on the commandline:' e array.each {|this_program| append_this.clear # ================================================================= # # The next line of code was added in August 2022 because ksmoothdock # is misbehaving. At a later time we may have to review this; # ideally we should not need any such ad-hoc exceptions ever. # ================================================================= # next if this_program == 'ksmoothdock' print gold( (' '+this_program+':').ljust(40) ) cmd_to_use = "#{this_program} --version 2>&1" version = `#{cmd_to_use}` if version.include? "command not found\n" version = THE_PROGRAM_IS_NOT_INSTALLED_OR_COULD_NOT_BE_FOUND else if version # Remove the name of the program here e. g. "kcachegrind 21.12.1" version.sub!(/#{this_program}/,'') most_recent_version = ::RBT.swift_return_version_of_this_program(this_program.strip.downcase) if RBT.is_this_version_higher_than_that_version?( most_recent_version.to_s, version.to_s, :do_not_report_any_errors ) append_this << orange( "\n ^^^ This program could "\ "be updated to version "+ most_recent_version.to_s ) end end end version.strip! if version.include? 'The program is not installed' e lightblue(version)+append_this else e steelblue(version)+append_this end } e else e 'The array appears to be empty.' end exit rescue LoadError; end end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 185 def reset # ======================================================================= # # === @internal_hash # ======================================================================= # @internal_hash = {} # ======================================================================= # # === :report_the_remote_urls # # If this instance variable is set to true then the remote URLs will # be shown as well, on the commandline. # ======================================================================= # @internal_hash[:report_the_remote_urls] = false # ======================================================================= # # === :try_to_rename_the_kde_konsole_tab # # The following instance variable will determine as to whether we will # try to make use of the KDE Konsole and rename the tab of the konsole # there. # # Since as of October 2018 we will not use the KDE konsole by default # anymore. This may change at a later moment in time, though. # ======================================================================= # @internal_hash[:try_to_rename_the_kde_konsole_tab] = false # ======================================================================= # # === :generate_a_html_file # # If the next instance variable is set to true then a html file will # be generated. By default this will not happen, though. # ======================================================================= # @internal_hash[:generate_a_html_file] = false # ======================================================================= # # === :store_the_results_into_local_files # # If the following variable is set to true then the project will # generate local files too, e. g. yaml files and what not. # ======================================================================= # @internal_hash[:store_the_results_into_local_files] = true # ======================================================================= # # === :use_ascii_table # # Whether to use an ASCII table or whether we will not: # ======================================================================= # @internal_hash[:use_ascii_table] = false # ======================================================================= # # === :table # ======================================================================= # @internal_hash[:table] = nil # The ascii table. # ======================================================================= # # === :compare_program_versions # # This instance variable can be used to also compare the program # versions, if the RBT project is available. # # By default this will not be done, though. # ======================================================================= # @internal_hash[:compare_program_versions] = false # ======================================================================= # # === :use_one_line_to_show_the_result # ======================================================================= # @internal_hash[:use_one_line_to_show_the_result] = false # ======================================================================= # # === :sort_alphabetically # # Whether to sort the main Hash alphabetically or not. # ======================================================================= # @internal_hash[:sort_alphabetically] = false # ======================================================================= # # === @pkg_config_query # ======================================================================= # @pkg_config_query = ::EnvironmentInformation::Queries::PkgConfig.new # ======================================================================= # # === @simple_version_query # ======================================================================= # @simple_version_query = ::EnvironmentInformation::Queries::SimpleVersion.new # ======================================================================= # # === @complex_version_query # ======================================================================= # @complex_version_query = ::EnvironmentInformation::Queries::ComplexVersion.new # ======================================================================= # # === @array_report_these_programs # # This Array denotes which programs are to be reported. # # By default it is empty. # ======================================================================= # @array_report_these_programs = [] # ======================================================================= # # === @array_unavailable_programs # # Programs which could not be found can be registered into the following # Array. # ======================================================================= # @array_unavailable_programs = [] # ======================================================================= # # === @runmode # # The @runmode variable can be :commandline or :gui or :www. # ======================================================================= # @runmode = :commandline # ======================================================================= # # === @show_everything # # If the following instance variable is set to true then this class # will try to show every registered (and thus, available) component. # # By default this is not wanted, so it is disabled. The user has to # specifically enable this option via the commandline, if so # desired, and thus overrule this default value. # ======================================================================= # @show_everything = false # ======================================================================= # # === @display_result # # If the following instance variable is true, which is the case by # default, then this class will report to the user on the commandline. # # If it is set to false then nothing will be displayed; this is # useful when you only want to obtain the dataset, without # showing anything to the user. # ======================================================================= # @display_result = true # ======================================================================= # # === @be_silent # # By default, this class is not silent, meaning that it will display # information to the user. # ======================================================================= # @be_silent = false # ======================================================================= # # === :may_we_try_to_use_rbt # # Whether we may query RBT for additional help or not. By default # we will try to make use of RBT. # ======================================================================= # @internal_hash[:may_we_try_to_use_rbt] = true # ======================================================================= # # === @array_show_this_to_the_user # # The following Array can be used to show messages to the user. # ======================================================================= # @array_show_this_to_the_user = [] # ======================================================================= # # === @array_display_these_components # # This Array will display the components on the commandline. # # Take note that the order is important: the entries that appear first # will be displayed earlier. In other words: first entries will be # shown first as well. # ======================================================================= # @array_display_these_components = [] # ======================================================================= # # === @show_ruby_version_and_gem_version # # This instance variable determines whether class EnvironmentInformation # will display the ruby version and the gem version. # # By default we will do so, but there may be situations where this # may be unwanted, or not a good idea, such as in a minimal system # where no ruby is running, or if the user only wants to display # very little information. # ======================================================================= # @show_ruby_version_and_gem_version = true # ======================================================================= # # === @display_everything_in_short_format # # This variable determines whether we will use a compact-display or # whether there will be one-entry-per-program instead. # ======================================================================= # @display_everything_in_short_format = false # ======================================================================= # # === @run_already # # This variable will be true by default. # ======================================================================= # @run_already = true # ======================================================================= # # === @show_help # # If this variable is set to true, then we will only show help, then # exit the program. # ======================================================================= # @show_help = false # ======================================================================= # # === @do_exit_the_program # # The following variable can determine when we exit from this class. # By default we will not exist early. # ======================================================================= # @do_exit_the_program = false # ======================================================================= # # === @array_these_programs_not_up_to_date # # This Array can be used to save into a local file which programs # are not up to date. # ======================================================================= # if is_on_roebe? @array_these_programs_not_up_to_date = [] end end
#¶ ↑
result_as_array
¶ ↑
The lines that we will have inside of this method, may look like this:
" operating_system: GNU/Linux\n"
#¶ ↑
# File lib/environment_information/class/class.rb, line 1159 def result_as_array _ = dataset_as_string splitted = _.split("\n") splitted.map! {|inner_line| inner_line.split(': ').map {|entry| entry.strip } } return splitted end
#¶ ↑
return_default_programs_on_linux
¶ ↑
This method should return the “main” programs on a linux computer, the most important entries.
#¶ ↑
# File lib/environment_information/class/class.rb, line 802 def return_default_programs_on_linux ARRAY_DEFAULT_PROGRAMS_ON_LINUX end
#¶ ↑
return_every_registered_component
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1409 def return_every_registered_component array = ::EnvironmentInformation.tracked_programs?+ ::EnvironmentInformation.tracked_non_programs?+ ::EnvironmentInformation.science_cluster?+ ::EnvironmentInformation.xorg_components? array = array.flatten.uniq # ======================================================================= # # === The mate-desktop # # Since as of 31.03.2019 we will also try to show the mate-desktop # components if the RBT project is available/installed. # ======================================================================= # if can_we_query_the_mate_desktop? # ===================================================================== # # Keep in mind that this Array is nested, so the name is # included as well as the version. # ===================================================================== # _ = RBT.return_mate_desktop_version_array _.each {|a,b| # array << [a, b] array << a register_onto_the_main_hash(a, b) } end return array # Return our findings. end
#¶ ↑
return_remote_gtk2_version
¶ ↑
Be wary when using this method, as it may slow down the whole application, due to making remote web-based queries.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1457 def return_remote_gtk2_version ::EnvironmentInformation.return_remote_gtk2_version end
#¶ ↑
return_version_of_awk
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1221 def return_version_of_awk? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_binutils
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1228 def return_version_of_binutils? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_bison
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1298 def return_version_of_bison? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_boost
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1509 def return_version_of_boost? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_busyboxy
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1502 def return_version_of_busyboxy? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_coreutils
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1235 def return_version_of_coreutils? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_diffutils
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1242 def return_version_of_diffutils? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_flex
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1305 def return_version_of_flex? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_gcc
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1249 def return_version_of_gcc? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_glibc
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1270 def return_version_of_glibc? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_gnupg
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1291 def return_version_of_gnupg? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_grep
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1284 def return_version_of_grep? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_intltool
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1277 def return_version_of_intltool? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_linux_kernel
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1256 def return_version_of_linux_kernel? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_ruby
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1657 def return_version_of_ruby? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_rubygems
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1650 def return_version_of_rubygems? ::EnvironmentInformation.send(__method__) end
#¶ ↑
return_version_of_xvid
?¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1516 def return_version_of_xvid? ::EnvironmentInformation.send(__method__) end
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 2495 def run # ======================================================================= # # Try to rename the KDE konsole first. This will happen on # roebe-systems only. # ======================================================================= # do_rename_kde_konsole # ======================================================================= # # ^^^ This check happens here again because menu() is allowed to # toggle this variable. # ======================================================================= # if @display_everything_in_short_format assign_components_for_the_short_format # Handle the short format here. end do_sort_alphabetically if sort_alphabetically? # ← Must come before the report-step. unless @do_exit_the_program # ===================================================================== # # === Report step # # We may only display the components if @display_result is true. # ===================================================================== # if @display_result register_the_available_components_and_show_them_at_once end end # ======================================================================= # # === Consider generating a .html file # # The user may want to generate a .html file, so the following # functionality allows the user to do so. This check should # ideally come before other local files are generated. # ======================================================================= # do_generate_a_html_file if @internal_hash[:generate_a_html_file] if commandline? and store_the_results_into_local_files? # ===================================================================== # # Only store local files if the variable # @store_the_results_into_local_files is true. # ===================================================================== # consider_storing_the_components_that_were_displayed consider_storing_which_programs_are_not_up_to_date end end
#¶ ↑
shall_we_really_store_which_programs_are_not_up_to_date?¶ ↑
This method will also honour whether the user is on a roebe-like system or whether the user is not.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1147 def shall_we_really_store_which_programs_are_not_up_to_date? is_on_roebe? and !@array_these_programs_not_up_to_date.empty? end
#¶ ↑
show_n_registered_entries
¶ ↑
Invoke this via:
envi --n_entries
#¶ ↑
# File lib/environment_information/class/class.rb, line 887 def show_n_registered_entries e "#{true_rev}The EnvironmentInformation project contains "\ "#{sfancy(::EnvironmentInformation.tracked_programs?.size)} "\ "#{true_rev}registered entries." end
#¶ ↑
show_the_registered_components
¶ ↑
#¶ ↑
# File lib/environment_information/class/class.rb, line 1737 def show_the_registered_components( i = tracked_programs? ) e e 'The following programs will be tracked:' e use_one_line_to_show_the_result = use_one_line_to_show_the_result? i.each_with_index {|this_program, index| index += 1 if use_one_line_to_show_the_result padded_index = index.to_s+') ' else padded_index = ' '+(index.to_s+') ').rjust(5) end colourized_and_padded_index = seagreen(padded_index) e colourized_and_padded_index+ steelblue(this_program) } e end
#¶ ↑
start_gtk_component
¶ ↑
To invoke this method from the commandline, do:
envi --start-gtk
#¶ ↑
# File lib/environment_information/class/class.rb, line 1528 def start_gtk_component require 'environment_information/gui/gtk3/environment_information.rb' ::EnvironmentInformation.run_gtk @do_exit_the_program = true end
#¶ ↑
use_ascii_table
¶ ↑
We will display in ascii-table format here.
#¶ ↑
# File lib/environment_information/class/class.rb, line 1070 def use_ascii_table disable_colours # Can't use colours right now. Perhaps at a later time. extend Terminal::Table::TableHelper @table = table ['Name', 'Version'] @table.style = { padding_left: 2, width: 110 # Set the width here. } @use_ascii_table = true end
#¶ ↑
work_on_the_programs_directory_only
¶ ↑
This works on the /home/Programs/ directory directly.
Invocation example:
envi --work-on-programs-directory-only
#¶ ↑
# File lib/environment_information/class/class.rb, line 935 def work_on_the_programs_directory_only( use_this_as_programs_directory = '/home/Programs/' ) # ======================================================================= # # 1) First, we have to determine which programs are available. # ======================================================================= # e "#{rev}Determining which programs are available at the prefix "\ "#{steelblue(use_this_as_programs_directory)}:" array_these_programs_are_available = [] tracked_programs?.each {|entry| target = "#{use_this_as_programs_directory}#{entry.capitalize}" if File.directory?(target) # =================================================================== # # In this case we know that this target exists. # =================================================================== # array_these_programs_are_available << entry end } # ======================================================================= # # 2) Checking these programs next. # ======================================================================= # clear_main_dataset add(array_these_programs_are_available) ::EnvironmentInformation.set_prefix_to_use(use_this_as_programs_directory) end