module ProgramInformation
#¶ ↑
#¶ ↑
require ‘program_information/constants/regex.rb’
#¶ ↑
#¶ ↑
#¶ ↑
require ‘program_information/menu.rb’
#¶ ↑
#¶ ↑
require ‘program_information/project/project_base_directory.rb’
#¶ ↑
#¶ ↑
#¶ ↑
require ‘program_information/reset.rb’
#¶ ↑
#¶ ↑
require ‘program_information/run.rb’
#¶ ↑
#¶ ↑
#¶ ↑
require ‘program_information/toplevel_methods/remove_archive_type.rb’
#¶ ↑
#¶ ↑
require ‘program_information/version/version.rb’
#¶ ↑
#¶ ↑
require ‘program_information/www/embeddable_interface.rb’ include ProgramInformation::EmbeddableInterface
#¶ ↑
Constants
- ARRAY_TEST_THIS_AS_INPUT
#¶ ↑
ProgramInformation::ARRAY_TEST_THIS_AS_INPUT
¶ ↑The character ‘|’ is not allowed to be part of any program name, so we wil use this as special token.
We will insert it at the boundary level.
#¶ ↑
- PROJECT_BASE_DIRECTORY
#¶ ↑
ProgramInformation::PROJECT_BASE_DIRECTORY
¶ ↑#¶ ↑
- REGEX_FOR_ACL_LIKE_INPUT
#¶ ↑
REGEX_FOR_ACL_LIKE_INPUT
¶ ↑Valid input should be ‘acl_2.2.47-1’ or ‘e_dbus-1.7.10’ or ‘wpa_supplicant-2.6’ or ‘SDL2_gfx-1.0.1’ or ‘libatomic_ops-7.4.2’ or ‘mod_python-11.10.2017’ or ‘mini_portile2-2.3.0.gem’.
#¶ ↑
- REGEX_FOR_BOOST_LIKE_INPUT
#¶ ↑
REGEX_FOR_BOOST_LIKE_INPUT
¶ ↑Valid input should be ‘ncbi_cxx-12_0_0’ or ‘icu4c-61_1’.
#¶ ↑
- REGEX_FOR_INPUT_CONTAINING_TWO_HYPHENS_AND_ONE_UNDERSCORE
#¶ ↑
REGEX_FOR_INPUT_CONTAINING_TWO_HYPHENS_AND_ONE_UNDERSCORE
¶ ↑This is input for programs such as ‘ntfs-3g_ntfsprogs-2017.3.23’.
#¶ ↑
- REGEX_FOR_INPUT_HAVING_ONLY_DOTS
#¶ ↑
REGEX_FOR_INPUT_HAVING_ONLY_DOTS
¶ ↑This is valid for strange input such as ‘expect5.45.3’ or ‘sendmail.8.15.2’. These have no ‘-’ and no ‘_’.
#¶ ↑
- REGEX_FOR_THREE_OR_MORE_HYPHENS
#¶ ↑
REGEX_FOR_THREE_OR_MORE_HYPHENS
¶ ↑This is for input such as ‘akonadi-calendar-tools-17.08.1’ or ‘boost-build-2014-10’ or ‘xf86-video-i810-1.7.4’ or or ‘xfce4-statusnotifier-plugin-0.2.0’ or ‘mime-types-data-3.2016.0521’ or ‘XML-LibXML-Simple-0.98’ or ‘kismet-2016-07-R1.tar.xz’ or ‘polkit-kde-agent-1-5.15.2’ or ‘xf86-video-amd-2.7.7.7’ or ‘xf86-video-s3virge-1.11.0’.
See: rubular.com/r/lCrdU01HE7MRV4
#¶ ↑
- REGEX_FOR_TWO_HYPHENS
#¶ ↑
REGEX_FOR_TWO_HYPHENS
¶ ↑This is valid for input such as ‘lynx-2.8.8-rel2’ or ‘gobject-introspection-1.53.4’ or ‘subtle-0.11.3224-xi’ or ‘dvd+rw-tools-7.1’ or ‘Archive-Zip-1.46’ or ‘btrfs-progs-v4.12.1’ or ‘color-tools-1.3.0’ or ‘libedit-20170329-3.1’ or ‘ncbi-blast-2.6.0+’ or ‘b43-fwcutter-015’ or ‘wcd-6.0.1-beta3’ or ‘oxygen-icons5-5.37.0’ or ‘btrfs-progs-v4.13.2’ or ‘Archive-Zip-1.46’ or ‘wcd-6.0.1-beta3’ or ‘openobex-1.7.1-Source’ or ‘youtube-dl-2019.06.27’.
See:
https://rubular.com/r/u9Yy3qcxrlp5uG
#¶ ↑
Public Class Methods
#¶ ↑
ProgramInformation.remove_archive_type
¶ ↑
This method will remove the “archive type”, e. g. “.tar.xz” or “.tar.bz2” or “.tar.lz”.
#¶ ↑
# File lib/program_information/toplevel_methods/remove_archive_type.rb, line 15 def self.remove_archive_type(i) i = i.dup if i.frozen? i.sub!(/\.tar\.gz$/,'') i.sub!(/\.tar\.xz$/,'') i.sub!(/\.tar\.bz2$/,'') i.sub!(/\.run$/,'') if i.end_with? '.run' i.sub!(/\.bz2$/,'') if i.end_with? '.bz2' i.sub!(/\.tar\.lz$/,'') if i.end_with? '.tar.lz' i.sub!(/\.gem$/,'') i.sub!(/\.tgz$/,'') i.sub!(/\.zip$/,'') i.sub!(/\.jar$/,'') i.sub!(/\.js$/,'') i.sub!(/\.stable$/,'') return i end
#¶ ↑
ProgramInformation.return_array_name_and_version¶ ↑
This will return the short_name and the version, as Array.
Usage example:
ProgramInformation::ProgramInformation.return_array_name_and_version( "font-sony-misc-1.0.3") => ["font-sony-misc", "1.0.3"]
#¶ ↑
# File lib/program_information/toplevel_methods.rb, line 104 def self.return_array_name_and_version(i) array = [ ::ProgramInformation.return_short_name(i), ::ProgramInformation.return_program_version(i) ] return array end
#¶ ↑
ProgramInformation.return_program_version¶ ↑
This module-method will return the program version of a given input.
For example, if the input to this method is ‘gobject-introspection-1.52.1.tar.xz’, then this method will return the String ‘1.52.1’.
We must also handle the case when the version passed to us is incomplete or wrong, such as “2.1.0-source”. In that case, the proper program version would be 2.1.0.
Usage examples, using the shorter variant instead:
ProgramInformation.return_version('/opt/ffmpeg-2.3.tar.xz') # => "2.3" ProgramInformation.return_version 'ophcrack-3.6.0' # => "3.6.0" ProgramInformation.return_version 'gobject-introspection-1.52.1.tar.xz' # => "1.52.1"
#¶ ↑
# File lib/program_information/toplevel_methods.rb, line 34 def self.return_program_version(of_this_program = '') if of_this_program.nil? or of_this_program.empty? opnn; e 'Please provide some input to the method '\ 'ProgramInformation.return_program_version.' else _ = ::ProgramInformation::ProgramInformation.new(of_this_program) _.program_version? end end
#¶ ↑
ProgramInformation.return_proper_pipe_token_to_this_input
¶ ↑
Most of the content of this method has to be put into a begin/require clause, as errors may happen, which could propagate downstream, leading to confusion. So we will rescue the error, and notify the user as to what has happened.
#¶ ↑
# File lib/program_information/toplevel_methods/return_proper_pipe_token_to_this_input.rb, line 21 def self.return_proper_pipe_token_to_this_input( entry ) if entry.is_a? Array entry = entry.first end entry = remove_archive_type(entry) use_this_replacement_token = '|' return if entry.to_s.empty? begin # ===================================================================== # # === Check for input such as 'unieject-6', containing one '-' and 0 '_' # ===================================================================== # if (entry.count('-') == 1) and (entry.count('_') == 0) entry[entry.index('-'),1] = use_this_replacement_token # ===================================================================== # # === Check for input such as 'p7zip_16.02_src_all.tar.bz2' with # 3 '_' and at the least one '.' and no '-' # ===================================================================== # elsif (entry.count('_') == 3) and (entry.count('.') > 0) and (!entry.include?('-')) entry[entry.index('_'),1] = use_this_replacement_token # ===================================================================== # # === Input such as 'mod_python_3.3.1', with two '_' and no '-'. # ===================================================================== # elsif (entry.count('_') == 2) and (entry.count('-') == 0) entry[entry.rindex('_'),1] = use_this_replacement_token # ===================================================================== # # === Input such as 'unzip60' without any '-' or '_' # ===================================================================== # elsif (entry.count('-') == 0) and (entry.count('_') == 0) and (!entry.include?('.')) entry[entry.index(/\d/), 0] = '|' # ===================================================================== # # === Check for input such as 'artemis_v16.0.11' or 'dpkg_1.18.22' # with one '_' and no '-'. # ===================================================================== # elsif (entry.count('_') == 1) and (entry.count('-') == 0) entry[entry.index('_'),1] = use_this_replacement_token # ===================================================================== # # === Input such as 'sendmail.8.15.2' or 'expect5.45.3', without # any '-' or '_'. # ===================================================================== # elsif (entry.count('-') == 0) and (entry.count('_') == 0) and (entry.include?('.')) entry =~ REGEX_FOR_INPUT_HAVING_ONLY_DOTS entry = $1.to_s.dup+use_this_replacement_token+$2.to_s.dup # ===================================================================== # # For input such as 'boost-1_54_0' or 'ncbi_cxx-12_0_0' or # 'boost_1.56.6'. So it contains exactly one '-' character. # ===================================================================== # elsif ((entry.count('-') == 1) and (entry.count('_') > 1) and # More than 1 '_' (entry =~ REGEX_FOR_BOOST_LIKE_INPUT)) or # or the second condition. ((entry.count('_') == 3) and (entry.count('-') == 0) and (entry =~ REGEX_FOR_BOOST_LIKE_INPUT)) entry =~ REGEX_FOR_BOOST_LIKE_INPUT # =================================================================== # # We here need only the first and the third match. # =================================================================== # entry = "#{$1.to_s.dup}#{use_this_replacement_token}#{$3.to_s.dup}" # ===================================================================== # # For input such as 'acl_2.2.47-1' or 'e_dbus-1.7.10' or # 'SDL2_gfx-1.0.1' or 'domain_name-0.5.20170404.gem' or # 'libatomic_ops-7.4.2' or 'icu4c-62_1'. # ===================================================================== # elsif (entry.count('_') == 1) and (entry.count('-') == 1) and (entry =~ REGEX_FOR_ACL_LIKE_INPUT) regex_to_use = REGEX_FOR_ACL_LIKE_INPUT entry =~ regex_to_use # =================================================================== # # Here we also only need to match towards the first and the third # entry. # =================================================================== # entry = $1.to_s.dup+use_this_replacement_token+$3.to_s.dup # ===================================================================== # # === Input such as 'did_you_mean-1.1.2' with one '-' and two '_' # ===================================================================== # elsif (entry.count('-') == 1) and (entry.count('_') == 2) entry[entry.index('-'),1] = use_this_replacement_token # ===================================================================== # # === Input such as 'ntfs-3g_ntfsprogs-2017.3.23' for 2 '-' and # 1 '_'. # ===================================================================== # elsif (entry.count('-') == 2) and (entry.count('_') == 1) regex_to_use = REGEX_FOR_INPUT_CONTAINING_TWO_HYPHENS_AND_ONE_UNDERSCORE entry =~ regex_to_use entry = $1.to_s.dup+use_this_replacement_token+$3.to_s.dup # ===================================================================== # # For input such as 'lynx-2.8.8-rel2' or 'subtle-0.11.3224-xi' or # 'gobject-introspection-1.53.4' or 'dvd+rw-tools-7.1' or # 'Archive-Zip-1.46' or 'b43-fwcutter-015' or 'wcd-6.0.1-beta3' # or 'oxygen-icons5-5.37.0'. These entries have two '-' and zero # '_'. # ===================================================================== # elsif (entry.count('-') == 2) and (entry.count('_') == 0) regex_to_use = REGEX_FOR_TWO_HYPHENS entry =~ regex_to_use entry = $1.to_s.dup+use_this_replacement_token+$2.to_s.dup # ===================================================================== # # For input such as 'polkit-qt-1-0.112.0' or # 'font-bitstream-75dpi-1.0.3' or 'boost-build-2014-10' or # 'xf86-video-i810-1.7.4' or 'gnome-internet-radio-locator-0.9.0' # or 'mime-types-data-3.2016.0521' or 'polkit-kde-agent-1-5.15.2' # or 'xf86-video-amd-2.7.7.7'. # # This input will NOT have any '_' token; and at the least 3 # '-' tokens. # ===================================================================== # elsif (!entry.include?('_')) and (entry.count('-') >= 3) regex_to_use = REGEX_FOR_THREE_OR_MORE_HYPHENS entry =~ regex_to_use entry = $1.to_s.dup+ use_this_replacement_token+ $2.to_s.dup else e 'ERROR in program_information.rb! This should never happen.' e "The input was: #{entry}" end rescue Exception => error opnn; e 'An error happened (line: '+__LINE__.to_s+'), for '\ 'the entry `'+entry.to_s+'`.' pp error pp error.class opnn; e 'The caller stack was:' pp caller() end return entry end
#¶ ↑
ProgramInformation.return_real_short_name¶ ↑
This method will return the real short name.
Usage example:
ProgramInformation.return_real_short_name('iso-codes-3.50.tar.xz')
The above would return “isocodes”.
#¶ ↑
# File lib/program_information/toplevel_methods.rb, line 56 def self.return_real_short_name(of_this_program = '') if of_this_program.nil? or of_this_program.empty? opnn; e 'Please provide some input to the method '\ 'ProgramInformation.return_real_short_name.' else _ = ::ProgramInformation::ProgramInformation.new(of_this_program) _.real_short_name? end end
#¶ ↑
ProgramInformation.return_real_short_name_and_version
¶ ↑
This method will return two results, in Array form:
The @real_short_name and the @program_version
The optional second argument can be used to downcase the program name that is returned.
#¶ ↑
# File lib/program_information/toplevel_methods.rb, line 123 def self.return_real_short_name_and_version( i, optional_downcase = false ) case optional_downcase when :downcase optional_downcase = true end real_short_name = ::ProgramInformation.return_real_short_name(i) if optional_downcase real_short_name.downcase! end program_version = ::ProgramInformation.return_program_version(i) return [ real_short_name, program_version ] end
#¶ ↑
ProgramInformation.return_short_name
¶ ↑
This method will ultimately return the value of @short_name value.
Usage examples:
ProgramInformation.return_short_name('ffmpeg-2.1.tar.xz') # => "ffmpeg" ProgramInformation.return_short_name('/Users/x/SRC/gobjectintrospection/gobject-introspection-1.53.4.tar.xz') # => "gobjectintrospection"
In the first example, it will return ‘ffmpeg’, but keep in mind that we allow to keep ‘-’ characters. In the second example, the ‘-’ MUST be preserved.
#¶ ↑
# File lib/program_information/toplevel_methods/return_short_name.rb, line 25 def self.return_short_name( of_this_program = '' ) if of_this_program.nil? or of_this_program.empty? opnn; e 'Please provide some input to the method '\ 'ProgramInformation.return_short_name.' else _ = ::ProgramInformation::ProgramInformation.new(of_this_program) _.short_name? end end
#¶ ↑
ProgramInformation.return_short_name_and_program_version¶ ↑
This will return an Array with two entries - the short name, and the program version.
#¶ ↑
# File lib/program_information/toplevel_methods.rb, line 75 def self.return_short_name_and_program_version( i, replace_input = true ) case replace_input when :do_not_modify_input replace_input = false end _ = ::ProgramInformation::ProgramInformation.new(i, :dont_run_yet) _.do_not_replace_anything unless replace_input _.run # ======================================================================= # # Assemble the Array here. # ======================================================================= # array = [ _.short_name?, _.program_version? ] return array end