class RBT::Base
Constants
- ALL_COLOUR_METHODS
#¶ ↑
ALL_COLOUR_METHODS
¶ ↑#¶ ↑
- ARRAY_KDE_KONSOLE_COLOURS_IN_USE
#¶ ↑
ARRAY_KDE_KONSOLE_COLOURS_IN_USE
¶ ↑Next, we will define the KONSOLE Colours that can be used.
#¶ ↑
- DAY_NAMES
#¶ ↑
DAY_NAMES
¶ ↑The addition of this constant was necessary due to upstream MRI ruby removing the RFC2822_DAY_NAME constant from time.rb.
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/initialize.rb, line 14 def initialize( i = ARGV, run_already = true, &block ) reset set_commandline_arguments(i) # ======================================================================= # # Next handle blocks given. # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :no_colours # ===================================================================== # when :no_colours disable_colours else # =================================================================== # # === Handle Hash given in blockform # =================================================================== # if yielded.is_a? Hash # ================================================================= # # === :use_colours # ================================================================= # if yielded.has_key? :use_colours _ = yielded.delete :use_colours if _ == false disable_colours end end end end end run if run_already end
Public Instance Methods
#¶ ↑
action¶ ↑
Simpler wrapper over the actions.
#¶ ↑
# File lib/rbt/base/misc.rb, line 651 def action( action_that_is_desired = nil, optional_argument1 = ARGV, # This is typically the main input to this method. options_hash = {}, &block ) unless ::RBT.respond_to? :action require 'rbt/requires/require_actions.rb' end ::RBT.action( action_that_is_desired, optional_argument1, options_hash, &block ) end
#¶ ↑
add_to_the_commandline_arguments
¶ ↑
Simply append to the commandline options through this method here.
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 84 def add_to_the_commandline_arguments(i) # ======================================================================= # # First check whether the input is a Hash: # ======================================================================= # if i.is_a? Hash if i.has_key? :commandline_arguments i = i.delete(:commandline_arguments) end end @internal_hash[:commandline_arguments] << i @internal_hash[:commandline_arguments].flatten! end
#¶ ↑
append_onto_the_internal_hash
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 511 def append_onto_the_internal_hash(i) @internal_hash.update(i) end
#¶ ↑
capitalize_first_alphabetical_character
¶ ↑
This method will capitalize on the given input, but it will act on the first alphabetical character. So for example, if we input a string such as “/programs” then this method will return “/Programs”.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 745 def capitalize_first_alphabetical_character( i = '/programs' ) new_string = ''.dup capitalized_already = false i.chars.each {|char| if capitalized_already else if char =~ /[a-zA-Z]/ char.upcase! capitalized_already = true end end new_string << char } new_string end
#¶ ↑
capitalize_program_names?¶ ↑
#¶ ↑
# File lib/rbt/base/misc.rb, line 448 def capitalize_program_names? RBT.configuration?.capitalize_program_names end
#¶ ↑
cd_back_to_the_current_working_directory
¶ ↑
This method can be used to ensure that we are back in the old “current working directory”, after invoking the given block.
#¶ ↑
# File lib/rbt/base/misc.rb, line 773 def cd_back_to_the_current_working_directory working_directory = return_pwd if block_given? yield end cd(working_directory) end
#¶ ↑
change_directory
(cd tag)¶ ↑
Change into the given directory.
The second argument to this method can be used to do additional tasks, such as creating the directory if it does not yet exist.
#¶ ↑
# File lib/rbt/base/prototype/change_directory.rb, line 21 def change_directory( i, optional_arguments = nil ) be_verbose = false # ======================================================================= # # First, handle Symbol-keywords given as first argument. # ======================================================================= # case i when :log_directory i = log_directory? end if block_given? yielded = yield case yielded when :be_verbose be_verbose = true end end # ======================================================================= # # Past this point, the variable `i` ought to be a String. # ======================================================================= # i = i.to_s unless i.is_a? String case optional_arguments # ======================================================================= # # === :be_quiet # ======================================================================= # when :be_quiet, :quiet, :silent, :be_silent, :do_not_report_anything be_verbose = false when true, :be_verbose be_verbose = true # ======================================================================= # # === :create_the_directory_if_it_does_not_exist # ======================================================================= # when :create_the_directory_if_it_does_not_exist FileUtils.mkdir_p(i) unless File.directory? i # ======================================================================= # # === :verbose_create_the_directory_if_it_does_not_exist # ======================================================================= # when :verbose_create_the_directory_if_it_does_not_exist, :ensure_that_the_directory_exists unless File.directory? i if be_verbose opne "The directory at `#{sdir(i)}` does not exist." opne 'We will create it now.' end FileUtils.mkdir_p(i) end end i = i.dup if i.frozen? i << '/' unless i.end_with? '/' i = rds(i) # Added this here as of May 2014. # ======================================================================= # # Perform the cd-action next. # ======================================================================= # if File.directory? i if be_verbose e "Changing into the directory `#{sdir(i.to_s)}` now." end Dir.chdir(i) if File.directory? i # This is the actual cd-action. end end
#¶ ↑
change_permission
(chown tag)¶ ↑
This simple method can be used to change permissions, by making use of FileUtils.chown().
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 864 def change_permission( file = 'test', use_this_uid_number = '1000' ) FileUtils.chown(use_this_uid_number, use_this_uid_number, file) # Hardcoded right now. end
#¶ ↑
cheering_person
?¶ ↑
This is just an ASCII “person” that is presently cheering. It is meant to indicate success and/or happiness. For instance, if a compilation-run has succeeded then we may display such a cheering ASCII “person”.
I found this to be cute and neat - and it is also somewhat useful, as I tend to use the colour gold for this. Thus it is a slight visual cue, e. g.:
e steelblue('All went well!' )+gold(cheering_person?)
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1014 def cheering_person? '\o/' end
#¶ ↑
chop_off_archive
¶ ↑
Remove the trailing part of an archive, for the most part. This isn’t very sophisticated but it “just works” for most cases (TM).
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 107 def chop_off_archive(i) if i.include? '#' # Chop off at '#' characters. i = i[0..(i.index('#')-1)] end i.sub!(/\.source$/,'') if i.include? 'source' i.sub!(/-stable$/,'') if i.end_with? '-stable' return RBT.remove_file_extension(i) end
#¶ ↑
clear_commandline_options
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 75 def clear_commandline_options @internal_hash[:commandline_arguments] = [] end
#¶ ↑
coloured_and_padded_e
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/esystem.rb, line 66 def coloured_and_padded_e( i, use_colours = use_colours?, optional_arguments = nil ) case use_colours # ======================================================================= # # === :default # ======================================================================= # when :default use_colours = use_colours? end # ======================================================================= # # Next, modify this command if it includes "--prefix=". # In that event we will colourize it a bit; the prefix will # be colourized in another colour. # ======================================================================= # if i and i.include?('--prefix=') and use_colours i = i.dup # ===================================================================== # # === Colourize the prefix, in cornflowerblue(). # ===================================================================== # i.sub!(/(--prefix=)(\/.+?)\s/, # See: https://rubular.com/r/Df8OzLqXGd '\1'+ cornflowerblue('\2 ')+ ::Colours.remove_escape_sequences( teal('') ) ) end case optional_arguments # ======================================================================= # # === :inner_padding # # Also use inner-padding here. # ======================================================================= # when :inner_padding i = i.dup i.prepend(' ') end e e i, :fancy_colours # or: teal(i) e end
#¶ ↑
coloured_and_padded_esystem
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/esystem.rb, line 14 def coloured_and_padded_esystem( i, use_colours = use_colours?, optional_arguments = nil ) case use_colours # ======================================================================= # # === :default # ======================================================================= # when :default use_colours = use_colours? end # ======================================================================= # # Next, modify this command if it includes "--prefix=". # In that event we will colourize it a bit; the prefix will # be colourized in another colour. # ======================================================================= # if i and i.include?('--prefix=') and use_colours i = i.dup # ===================================================================== # # === Colourize the prefix, in cornflowerblue(). # ===================================================================== # i.sub!(/(--prefix=)(\/.+?)\s/, # See: https://rubular.com/r/Df8OzLqXGd '\1'+ cornflowerblue('\2 ')+ ::Colours.remove_escape_sequences( teal('') ) ) end case optional_arguments # ======================================================================= # # === :inner_padding # # Also use inner-padding here. # ======================================================================= # when :inner_padding i = i.dup i.prepend(' ') end e e i, :fancy_colours # or: teal(i) e system i end
#¶ ↑
coloured_esystem
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/esystem.rb, line 114 def coloured_esystem(i) esystem i, :fancy_colours end
#¶ ↑
colourize_directory_for_system_results
¶ ↑
This method is to colourize directories that are given via system() or similar calls. In theory, we could use sdir(), but I wanted to have another colour.
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 181 def colourize_directory_for_system_results(i) lightslategray(i) end
#¶ ↑
colourize_this_file_path
¶ ↑
This method will colourize a “file path”. So for example, if you have a file path such as “/opt/foo/bar.rb”, then this method will colourize the directory in one colour, and the file itself (bar.rb) in another colour.
The whole idea behind this is to be easily able to separate which part is the directory and which part is the file.
If no ‘/’ has been given then the input will be returned unmodified.
The colour for this can be controlled by the input-arguments.
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 212 def colourize_this_file_path( i, colour1 = :slateblue, # ← This is the colour for the directory. colour2 = :royalblue # ← This is the colour for the file. ) if i.include? '/' if use_colours? dirname = File.dirname(i) basename = File.basename(i) dirname = send(colour1, dirname+'/') basename = send(colour2, basename) i = "#{dirname}#{basename}" end end i end
#¶ ↑
colourize_this_warning
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 259 def colourize_this_warning(i) return firebrick(i) if use_colours? return i end
#¶ ↑
commandline_arguments?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 62 def commandline_arguments? @internal_hash[:commandline_arguments] end
#¶ ↑
commandline_arguments_without_hyphens?¶ ↑
As above, but reversed.
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 113 def commandline_arguments_without_hyphens?( i = commandline_arguments? ) i.select {|entry| entry and !entry.start_with?('--') } end
#¶ ↑
consider_reporting_how_many_programs_are_registered
¶ ↑
#¶ ↑
# File lib/rbt/base/misc.rb, line 791 def consider_reporting_how_many_programs_are_registered( shall_we_report = false ) if shall_we_report require 'rbt/utility_scripts/report_the_registered_programs.rb' ::RBT.report_the_registered_programs end end
#¶ ↑
convert_env_variable
¶ ↑
This method can be used to convert a ENV variable, such as $BLA, into its corresponding “real” value.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 809 def convert_env_variable(i) RBT.convert_global_env(i) end
#¶ ↑
cookbook_directory¶ ↑
This method will return a String such as:
/Programs/Ruby/2.5.1/lib/ruby/site_ruby/2.5.0/rbt/yaml/individual_cookbooks/
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 420 def cookbook_directory? return RBT.cookbook_directory? end
#¶ ↑
cookbook_files?¶ ↑
This method will return all available cookbook files in an Array.
Usage example:
cookbook_files?(:show_full_path)
#¶ ↑
# File lib/rbt/base/misc.rb, line 393 def cookbook_files?(show_how = :show_only_name) result = Dir["#{individual_cookbooks_directory?}*yml"].sort case show_how when :show_only_name # In this case, show only the name. result.map! {|entry| File.basename(entry).gsub( File.extname(entry), '' ) } when :show_full_path # In this case make no modifications. end return result end
#¶ ↑
copy_directory
¶ ↑
This method can be used to copy a directory from a certain location to the specified (second argument) target directory.
#¶ ↑
# File lib/rbt/base/prototype/directory_related_methods.rb, line 158 def copy_directory( from, to = return_pwd, be_verbose = false ) case to when :be_verbose to = return_pwd be_verbose = true end case be_verbose when :be_verbose be_verbose = true end if be_verbose e "Now copying the directory `#{sdir(from)}` to `#{sdir(to)}`." end FileUtils.cp_r(from, to) end
#¶ ↑
copy_files
(copy tag, cp tag, copy file tag)¶ ↑
Use this if you need to copy a file.
#¶ ↑
# File lib/rbt/base/prototype/file_related_methods.rb, line 92 def copy_files( from, to = return_pwd, be_verbose = false, use_namespace = true ) if block_given? yielded = yield case yielded when :be_verbose be_verbose = true end end case be_verbose # case tag when :be_verbose be_verbose = true end case to when '.' to = return_pwd end # ======================================================================= # # The next method is defined in the file 'prototype.rb'. # ======================================================================= # from = sanitize_for_environment_variable(from) if from.include? '$' to = sanitize_for_environment_variable(to) if to.include? '$' # ======================================================================= # # Since as of June 2011, we will also automatically create # the base directory should it not yet exist. # ======================================================================= # unless File.exist? File.dirname(to) create_directory(File.dirname(to)) end if File.exist? from if be_verbose if use_namespace opne "#{rev}Now copying the file `#{sfile(from)}`" opne "to `#{sfile(to)}`." else e "#{rev}Now copying the file `#{sfile(from)}`" e "to `#{sfile(to)}`." end end FileUtils.cp(from, to) else e "Can not copy the file `#{sfile(from)}` as it "\ "does not appear to exist." end end
#¶ ↑
create_directory
(mkdir tag)¶ ↑
Consistently use this when you want to create a directory for the RBT-Project.
#¶ ↑
# File lib/rbt/base/prototype/directory_related_methods.rb, line 21 def create_directory( i = '/Users/Packages/', be_verbose = :be_quiet, permissions = :default, &block ) yielded = nil # Will be filled up if a block is given. unless i.end_with? '/' i = i.dup if i.frozen? i << '/' end # ========================================================================= # # === Handle blocks next # ========================================================================= # if block_given? yielded = yield case yielded # ======================================================================= # # === :be_quiet # ======================================================================= # when :be_quiet be_verbose = false # ======================================================================= # # === :be_verbose # ======================================================================= # when :be_verbose be_verbose = true end end unless File.directory? i if be_verbose.is_a? Hash # =================================================================== # # We have to handle other keys first, in particular the permissions # key: # =================================================================== # if be_verbose.has_key? :permissions permissions = be_verbose.delete(:permissions) end if be_verbose.has_key? :be_quiet be_verbose = be_verbose.delete(:be_quiet) elsif be_verbose.has_key? :verbosity be_verbose = be_verbose.delete(:verbosity) end end case be_verbose # ===================================================================== # # === :be_quiet # ===================================================================== # when :be_quiet, :be_silent be_verbose = false end unless File.directory? i if be_verbose opne "Creating the directory `#{sdir(i)}` now." end RBT.create_directory( i, permissions, :be_quiet, :do_not_use_opn ) { yielded } # ^^^ We are already verbose above, and handle opn on # our own. end end end
#¶ ↑
current_hour?¶ ↑
Consistently use this method whenever you wish to return the current hour.
#¶ ↑
# File lib/rbt/base/time.rb, line 114 def current_hour? ::Time.now.strftime('%H:%M:%S') # '04:21:14' end
#¶ ↑
dd_mmm_yyy
¶ ↑
This method-format is specifically the default for cookbook-files.
#¶ ↑
# File lib/rbt/base/time.rb, line 138 def dd_mmm_yyy current_day = ::Time.now.strftime('%d') # This will return a string such as "30". return current_day+ ' '+ Date::MONTHNAMES[Date.today.month][0,3].capitalize+ ' '+ ::Time.now.strftime('%Y') end
#¶ ↑
delete_code_of_conduct?¶ ↑
Query method over as to whether we will try to remove code-of-conduct files.
#¶ ↑
# File lib/rbt/base/misc.rb, line 723 def delete_code_of_conduct? if is_on_roebe? true else # else try to check for the config file. if config? config?.automatically_delete_code_of_conduct_files_when_repackaging else false end end end
#¶ ↑
determine_appdir_prefix_from_this_input
¶ ↑
This method has to return a String, which constitutes the AppDir prefix of the target program at hand.
#¶ ↑
# File lib/rbt/base/misc.rb, line 28 def determine_appdir_prefix_from_this_input( i = nil, program_version = nil ) return RBT.determine_appdir_prefix_from_this_input( i, program_version ) end
#¶ ↑
disable_colours
¶ ↑
Use this method if you wish to disable colours. Invoke it only when you really do wish to disable the colours.
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 354 def disable_colours @internal_hash[:use_colours] = false end
#¶ ↑
display_md5sum?¶ ↑
#¶ ↑
# File lib/rbt/base/misc.rb, line 555 def display_md5sum? RBT.display_md5sum? end
#¶ ↑
does_this_expanded_cookbook_file_exist_for_this_program?¶ ↑
This method can be used to determine whether an expanded cookbook dataset exists for a given program at hand.
#¶ ↑
# File lib/rbt/base/prototype/expanded_cookbooks.rb, line 76 def does_this_expanded_cookbook_file_exist_for_this_program?(i) return File.exist?(path_to_this_expanded_cookbooks_dataset(i)) end
#¶ ↑
e (e tag)¶ ↑
The second argument can be a Symbol such as :fancy_colours.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 43 def e( i = '', optional_colours = nil, use_colours = use_colours? ) if use_colours case optional_colours # =================================================================== # # === :fancy_colours # =================================================================== # when :fancy_colours optional_colours = :mediumslateblue else puts i end puts ::Colours.send(optional_colours, i)+ ::Colours.rev if optional_colours else puts i end end
#¶ ↑
enable_colours
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 343 def enable_colours @internal_hash[:use_colours] = true end
#¶ ↑
ensure_main_encoding_for
¶ ↑
The input to this method should be a String object.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 573 def ensure_main_encoding_for( i, use_this_encoding = USE_MAIN_ENCODING ) unless i.encoding.to_s.include? use_this_encoding i = i.force_encoding(use_this_encoding) end return i end
#¶ ↑
exit_program
(exit tag)¶ ↑
This is a wrapper to exit, that is, to exit a program. Either we just exit; or we return the special symbol :break
A few Symbols may be passed as block to this method, indicating special behaviour. For instance, the Symbol :exit_no_matter_what shall indicate that this method ought to exit at all times, no matter what.
#¶ ↑
# File lib/rbt/base/prototype/exit_program.rb, line 22 def exit_program( symbol_exit = :standalone, optional_message = nil, use_this_as_exit_value = 0, &block ) e optional_message if optional_message # ======================================================================= # # If we give a number, assume this to be the exit code which we will # use for exiting there. # ======================================================================= # if symbol_exit.to_s =~ /\d+/ use_this_as_exit_value = symbol_exit.to_i end if block_given? symbol_exit = yield # This variable may now be a Symbol, such as: :exit_no_matter_what end case symbol_exit # ======================================================================= # # === :connected # ======================================================================= # when :connected, :chained, :continue return :break # i.e. when you run it from a shell. Return the Symbol :break. # ======================================================================= # # === :standalone # ======================================================================= # when :standalone, # ← Added because I like to read the symbol :standalone. :may_we_exit, :exit_no_matter_what, :default, 'default', 'def', true exit(use_this_as_exit_value) else # this is the default, just like with :standalone too exit(use_this_as_exit_value) end end
#¶ ↑
expanded_cookbooks_directory_exists?¶ ↑
This method will try and check to see if the expanded-cookbooks directory exists. If this directory exists then this method will return true; otherwise this method will return false.
#¶ ↑
# File lib/rbt/base/prototype/expanded_cookbooks.rb, line 64 def expanded_cookbooks_directory_exists? target = directory_expanded_cookbooks? return File.directory?(target) end
#¶ ↑
file_dirname_retaining_trailing_slash
¶ ↑
This method will invoke File.dirname(), but it will ensure that the last character of the result returned will be a ‘/’, if the given input also ended with a ‘/’ token.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1083 def file_dirname_retaining_trailing_slash(i) if i.end_with?('/') return "#{File.dirname(i)}/" else return File.dirname(i) end end
#¶ ↑
file_predefined_installation_instructions
?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 726 def file_predefined_installation_instructions? RBT.file_predefined_installation_instructions end
#¶ ↑
find_this_yaml_file
¶ ↑
This method can be used to find a proper yaml file.
We will delegate to Cookbooks
for this though.
We will return the absolute path to the .yml file in question.
Usage example:
find_this_yaml_file(:poppler) # => "/home/x/programming/ruby/src/rbt/lib/rbt/yaml/individual_cookbooks/poppler.yml"
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 844 def find_this_yaml_file(i = :poppler) i = i.to_s # ======================================================================= # # The next check has to be explicit for File.file? as well, because # a local directory with that name may exist, which we would not # want to have. # ======================================================================= # if File.exist?(i) and File.file?(i) i else RBT.return_location_of_this_yaml_file(i) end end
#¶ ↑
first_argument?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 40 def first_argument? @internal_hash[:commandline_arguments].first end
#¶ ↑
first_non_hyphen_argument?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 102 def first_non_hyphen_argument?( i = commandline_arguments_without_hyphens? ) i.first end
#¶ ↑
gem_version
¶ ↑
This method is a wrapper over Gem::Version.new()
The reason as to why this resides in a method is so that we can do some input-sanitizing, and easier rescue, if this is necessary one day.
#¶ ↑
# File lib/rbt/base/misc.rb, line 608 def gem_version(i) i = i.to_s.delete('vr') begin if i =~ /\d+/ # Must have at the least one number. return Gem::Version.new(i) end rescue ArgumentError => error opne 'An error occurred in gem_version()' pp error end nil # Indicate "failure" aka unable to parse this version. end
#¶ ↑
get_all_directories_from
¶ ↑
This method can be used to obtain all directories from the given (first) input argument.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 394 def get_all_directories_from( here = return_pwd, return_full_path = false ) RBT.get_all_directories_from(here, return_full_path) end
#¶ ↑
get_all_files_from
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 408 def get_all_files_from(i) return RBT.get_all_files_from(i) end
#¶ ↑
go_to_base_dir
¶ ↑
Simply go to the temp-directory.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 627 def go_to_base_dir( be_verbose = true ) _ = temp_dir? if be_verbose opne "Changing to `#{sdir(_)}`." end cd(_) end
#¶ ↑
host_system?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 797 def host_system? RBT.determine_host_architecture end
#¶ ↑
infer_the_namespace
¶ ↑
This will assume the true namespace from the inspectable name.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1051 def infer_the_namespace _ = inspect.to_s.delete('<') if _.include? ' ' _ = _.split(' ').first.delete('#') if _.include? ':' _ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::') end end set_the_namespace(_) # And assign it here. end
#¶ ↑
is_a_64bit_system?¶ ↑
This method will return true if the underlying system is a 64-bit system.
#¶ ↑
# File lib/rbt/base/is_a_64_bit_system.rb, line 17 def is_a_64bit_system? RUBY_PLATFORM.include? '_64' # Due to → "x86_64-linux". end
#¶ ↑
is_an_archive?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1120 def is_an_archive?(i) return RBT.is_an_archive?(i) end
#¶ ↑
is_ccache_available?¶ ↑
This method queries as to whether ccache is available or whether it is not.
#¶ ↑
# File lib/rbt/base/misc.rb, line 147 def is_ccache_available? result = true begin check_for_ccache = `ccache 2>&1` if check_for_ccache.include? 'command not found' result = false end rescue Errno::ENOENT # ===================================================================== # # This clause can happen when there is no # /bin/sh symlink. # ===================================================================== # check_for_ccache = false end result end
#¶ ↑
is_github_url?¶ ↑
This method will return true if the main url (url1) is a github url.
#¶ ↑
# File lib/rbt/base/misc.rb, line 680 def is_github_url?( i = url1? ) i and (i.start_with?('https://github.com/') or i.start_with?('http://github.com/')) end
#¶ ↑
is_on_gobolinux?¶ ↑
The method is_on_gobolinux? can be used to query whether the host system is using GoboLinux (a linux distribution) or whether it is not.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 779 def is_on_gobolinux? RBT.is_on_gobolinux? end
#¶ ↑
is_on_windows?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 915 def is_on_windows? RBT.is_on_windows? end
#¶ ↑
is_porg_available?¶ ↑
This method is required to determine whether porg is available or not.
#¶ ↑
# File lib/rbt/base/misc.rb, line 203 def is_porg_available? result = `porg 2>&1`.include? 'porg: command not found' return !result end
#¶ ↑
is_roebe?¶ ↑
If we are on our local computer, or on another computer.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 957 def is_roebe? RBT.is_roebe? end
#¶ ↑
is_this_a_library?¶ ↑
This method will check whether the given input is assumed to be a library or whether it is not. If the input ends with .so or .a then this is considered to be a library, by this method.
The check inside of the method body will ensure this.
#¶ ↑
# File lib/rbt/base/misc.rb, line 534 def is_this_a_library?(i) ( i.strip.end_with?('.so') or i.strip.end_with?('.a') or i.strip.end_with?('.o') or i.strip.include?('.so.') # <- For e. g. "libfoo.so.1.2.3" ) end
#¶ ↑
is_this_program_included?¶ ↑
Use this method to query whether a program is included or whether it is not.
The second argument is, by default, nil. It can be a symbol such as :include_abbreviations, in which case we will include abbreviations.
Usage example:
is_this_program_included?(:htop, :include_abbreviations)
#¶ ↑
# File lib/rbt/base/misc.rb, line 749 def is_this_program_included?( i, optional_arguments = nil ) RBT.is_this_program_included?(i, optional_arguments) # bl $RBT/toplevel_methods/available_programs.rb end
#¶ ↑
load_dataset_from_this_expanded_cookbook
¶ ↑
This method will attempt to load the dataset from an expanded cookbook dataset. In order for this to work, the file must exist locally.
#¶ ↑
# File lib/rbt/base/prototype/expanded_cookbooks.rb, line 88 def load_dataset_from_this_expanded_cookbook( i, &block ) i = i.to_s unless i.is_a? String # We need Strings. if File.file?(i) use_this_file = i.dup else use_this_file = path_to_this_expanded_cookbooks_dataset(i) end if File.exist? use_this_file load_yaml(use_this_file) else no_file_exists_at(use_this_file, &block) return nil end end
#¶ ↑
load_yaml_file_from_the_cookbook_directory_for_this_program
¶ ↑
This method can be used to load the specific .yml file from the cookbook directory.
#¶ ↑
# File lib/rbt/base/prototype/load_yaml.rb, line 27 def load_yaml_file_from_the_cookbook_directory_for_this_program(i) target_file = "#{RBT.cookbook_directory?}#{i}.yml" load_yaml(target_file) end
#¶ ↑
move_file
(move tag, mv tag)¶ ↑
Move a file via this method here. Use this consistently whenever you move a file. Could also be done via File.mv().
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 941 def move_file( this_file, where_to, be_verbose = true ) if be_verbose e "#{rev}Moving from #{sfile(this_file)} to #{sfile(where_to)}." end FileUtils.mv(this_file, where_to) end
#¶ ↑
n_programs_available
?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 767 def n_programs_available? RBT.n_programs_available? end
#¶ ↑
new_cookbook_instance_for
¶ ↑
Use a slightly shorter wrapper to access class Cookbook.
Note that you still have to require class Cookbook on your own, prior to calling this method.
The argument to this method should be the name of the program whose cookbook-dataset you wish to access/manipulate.
#¶ ↑
# File lib/rbt/base/misc.rb, line 113 def new_cookbook_instance_for(name_of_the_program) RBT::Cookbooks::SanitizeCookbook.new(name_of_the_program) { :fast } end
#¶ ↑
no_opn
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/opn.rb, line 44 def no_opn @internal_hash[:use_opn] = false end
#¶ ↑
no_such_file_exists
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 671 def no_such_file_exists( i, be_verbose = true, &block ) if block_given? yielded = yield case yielded when :be_quiet be_verbose = false end end if be_verbose e "No file called `#{sfile(i)}` appears to exist." end end
#¶ ↑
open_in_editor
¶ ↑
This will open a cookbook .yml file in the editor.
#¶ ↑
# File lib/rbt/base/editor.rb, line 19 def open_in_editor(i) if i.is_a? Array i.each {|entry| open_in_editor(entry) } else i = i.to_s.dup unless i.end_with? '.yml' i << '.yml' end if is_on_roebe? # =================================================================== # # On my home system. # =================================================================== # unless i.start_with?(RUBY_SRC_RBT_COOKBOOKS) or i.include?('/') i.prepend RUBY_SRC_RBT_COOKBOOKS end else unless i.include? individual_cookbooks_dir? i.prepend(individual_cookbooks_dir?) end end esystem "#{editor?} #{i}" end end
#¶ ↑
opnn (opnn tag)¶ ↑
The abbreviation “opn” stands for “output program name”. This also describes the major functionality of this method - we will try to display the name of the program that generates a particular output, so that the user can understand which component may have went wrong.
#¶ ↑
# File lib/rbt/base/prototype/opn.rb, line 96 def opnn( i = namespace?, use_opn = use_opn?, &block ) if use_opn if i.is_a? String i = { namespace: i, use_colours: use_colours? } end RBT.opnn(i, &block) # ← Let that method handle this. end end
#¶ ↑
path_to_this_expanded_cookbooks_dataset
¶ ↑
This method shall attempt to return the full path to the expanded cookbooks directory dataset of a given program.
For example, if the input to this method is ‘htop’ then this method should return ‘htop.yml’, or rather, ‘/home/Temp/rbt/expanded_cookbooks/htop.yml’.
#¶ ↑
# File lib/rbt/base/prototype/expanded_cookbooks.rb, line 36 def path_to_this_expanded_cookbooks_dataset(i) i = i.dup i = remove_archive_at_the_end( File.basename(i) ) # ======================================================================= # # The next check leads to problems for input such as "0install.yml". # Unfortunately I did not explain why I added the following line, # so I have removed it on 13.09.2019 again. # # If it is to be re-added, it has to be explained why it is there; # and if not, then it is suggested to remove the code eventually. # ======================================================================= # # if i =~ /\d+/ # i = ProgramInformation.return_program_name(i) # end # ======================================================================= # i << '.yml' unless i.end_with? '.yml' "#{directory_expanded_cookbooks?}#{i}" end
#¶ ↑
populate_the_internal_hash_with_default_values
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/reset.rb, line 38 def populate_the_internal_hash_with_default_values # ======================================================================= # # === :namespace # # We must initialize this variable here so that subclasses can make # use of it from the very beginning. # ======================================================================= # set_the_namespace( { namespace: NAMESPACE } ) # ======================================================================= # # === :commandline_arguments # ======================================================================= # @internal_hash[:commandline_arguments] = [] # ======================================================================= # # === :be_verbose # ======================================================================= # @internal_hash[:be_verbose] = true # ======================================================================= # # === :use_colours # ======================================================================= # @internal_hash[:use_colours] = RBT.use_colours? # Use the default value for RBT. # ======================================================================= # # === :run_simulation # # This variable will determine whether we run in simulation mode or not. # ======================================================================= # @internal_hash[:run_simulation] = RBT.configuration?.run_simulation # ======================================================================= # # === :use_opn # ======================================================================= # @internal_hash[:use_opn] = true # ======================================================================= # # === :debug # ======================================================================= # @internal_hash[:debug] = RBT.shall_we_debug? end
#¶ ↑
program_exists?¶ ↑
Use this method to find out whether the given program, as input to this method, exists.
Usage example:
if program_exists? :htop
#¶ ↑
# File lib/rbt/base/misc.rb, line 254 def program_exists?(this_program) does_program_exist = false # Defaults to false - the program is not installed. this_program = this_program.to_s.dup #. downcase # sanitize. downcase is BAD, it breaks stuff like "Esetroot" if this_program.include? ' ' # split it, and take the first word in this case. this_program = this_program.split(' ').first end path_variable_file = "#{RUBY_SRC_DIR}rcfiles/lib/rcfiles/yaml/path_variable.yml" if File.exist? path_variable_filelib array_available_paths = load_yaml(path_variable_file)['path'].strip.split(' ') array_available_paths.each {|path| _ = "#{path}/#{this_program}" does_program_exist = true if File.exist?(_) } end # Hack - an exception for configure: does_program_exist = true if this_program.include? '/configure' return does_program_exist end
#¶ ↑
programs_dir?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 922 def programs_dir? RBT.programs_directory? end
#¶ ↑
project_base_directory?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 248 def project_base_directory? RBT.project_base_directory? end
#¶ ↑
read_file
(read tag)¶ ↑
Use this method whenever you want to read in a file.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1159 def read_file(i) File.read(i) if File.exist? i end
#¶ ↑
read_file_in_default_encoding
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1166 def read_file_in_default_encoding( i, use_this_encoding = ::RBT.encoding? ) if File.exist? i File.read( i, encoding: use_this_encoding ) else e "Can not read file `#{i}` as it does not exist." end end
#¶ ↑
readlines_with_proper_encoding
¶ ↑
File.readlines() variant with proper encoding.
#¶ ↑
# File lib/rbt/base/prototype/readlines.rb, line 26 def readlines_with_proper_encoding( i, use_this_encoding = main_encoding? ) File.readlines( i, encoding: use_this_encoding ) end
#¶ ↑
remove (remove tag)¶ ↑
General remove entry-method. If you wish to delete a file or a directory or a symlink, use this method.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 436 def remove( this_target, be_verbose = false ) if this_target.is_a? Array this_target.each {|entry| remove(entry, be_verbose) } else # ===================================================================== # # The next check requires a rescue clause, because the file may no # longer exist. # ===================================================================== # begin type = File.ftype(this_target) rescue Errno::ENOENT type = 'missing_entry' end if File.exist? this_target case type # case tag # =================================================================== # # === remove_symlink # =================================================================== # when 'link','missing_entry' # This entry is for symlinks. remove_symlink(this_target) # =================================================================== # # === remove_file # =================================================================== # when 'file' remove_file(this_target, be_verbose) # =================================================================== # # === remove_directory # =================================================================== # when 'directory' remove_directory(this_target) else # This else clause will not be entered, I think. ewarn "Not removing `#{simp(this)}` as \"#{simp(type)}\" is "\ "not registered." end else if be_verbose opne swarn('WARNING: file ')+ this_target.to_s+ swarn(' does not exist.') opne swarn('Thus, it can not be removed.') end end end end
#¶ ↑
remove_archive_from_the_end
¶ ↑
This method will remove the “archive part” of the given input, such as by removing “.tar.xz” from the given input argument (which ought to be a String).
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 716 def remove_archive_from_the_end(i) RBT.remove_archive_from_the_end(i) end
#¶ ↑
remove_comments_from_each_line
¶ ↑
This method will remove each comment from a given line. Assume multiline input that will have trailing “ # foobar” comments which will be removed.
#¶ ↑
# File lib/rbt/base/misc.rb, line 178 def remove_comments_from_each_line(i) if i.include? ' # ' i = i.split(N).map {|line| if line.include? ' # ' line = line[0 .. (line.index('#') - 1)] line.strip! end line }.join(N) end i end
#¶ ↑
remove_directory
¶ ↑
Consistently use this method in order to remove one or more directories.
#¶ ↑
# File lib/rbt/base/prototype/directory_related_methods.rb, line 97 def remove_directory( this_directory, be_verbose = false ) if block_given? yielded = yield case yielded # ===================================================================== # # === :be_verbose # ===================================================================== # when :be_verbose be_verbose = true end end if this_directory.is_a? Array this_directory.each {|entry| # Recursive call here. remove_directory(entry, be_verbose) } elsif this_directory.is_a? String case be_verbose when :be_verbose be_verbose = true end this_directory = rds(this_directory).strip # Don't want double slashes in it. if File.directory? this_directory case this_directory # case tag # =================================================================== # # / can never be removed through this method here - at the least # this is our intent. # =================================================================== # when '/' # We will never remove '/', ever. e "The #{sdir('/')} directory can not be removed "\ "via this method." # Tiny "safeguard". # =================================================================== # # RBT.temp_directory? # =================================================================== # when RBT.temp_directory? e "Will not remove directory `#{sdir(this_directory)}`." # Another tiny "safeguard". else if File.exist?(this_directory) and (this_directory.size > 1) if be_verbose e "Removing the directory `#{sdir(this_directory)}'` next." end FileUtils.rm_rf(this_directory) # Finally remove the directory. end end end else e "Unknown input: #{this_directory.class}" end end
#¶ ↑
remove_double_slashes
(rds tag)¶ ↑
Replace // with / in a given string.
#¶ ↑
# File lib/rbt/base/prototype/rds.rb, line 16 def remove_double_slashes(i) if i.is_a? Array i.map {|entry| remove_double_slashes(entry) } else i.squeeze '/' end end
#¶ ↑
remove_file
(remove tag)¶ ↑
Use this method whenever you wish to remove a file.
The first input argument to this method shall be the file that we wish to remove. This means the “file path”, so the path to the file has to be provided, such as “/opt/foobar.md”. An Array can also be given, which will lead to batch-removal of the given files at hand.
The second input argument to this method, called ‘report_the_action`, determines whether we will be verbose or whether we will not be verbose. Verbose here means that we will notify the user what we are doing or about to do; not verbose means that we will be silent when we remove the target file.
#¶ ↑
# File lib/rbt/base/prototype/file_related_methods.rb, line 74 def remove_file( i, report_the_action = false ) if i.is_a? Array i.each {|entry| remove_file(entry, report_the_action) } else RBT.remove_file(i, report_the_action) end end
#¶ ↑
remove_file_extension
¶ ↑
This method will try to remove anything we declare to be an improper file extension. We do this by delegating towards class RemoveFileSuffix, an external dependency.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 522 def remove_file_extension( i, also_remove_the_basename = true ) case also_remove_the_basename when :do_not_strip_anything also_remove_the_basename = false end if also_remove_the_basename i = File.basename(i) end if i.end_with? '.src' i[-4,4] = '' elsif i.end_with? '-src' i[-4,4] = '' end i = remove_unnecessary_data_from_url(i.to_s.dup) remove_archive_from_the_end(i) end
#¶ ↑
remove_this_commandline_argument
¶ ↑
This method can be used to remove a specific argument from the commandline arguments.
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 51 def remove_this_commandline_argument( i, from = commandline_arguments? ) from.reject! {|line| line =~ /#{Regexp.quote(i)}/ } end
#¶ ↑
remove_trailing_ANSII_escape_code
¶ ↑
This method can be used if you need to get rid of trailing ANSII escape sequences from a given String.
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 294 def remove_trailing_ANSII_escape_code(i) if use_colours? i = ::Colours.remove_trailing_ANSII_escape_code(i) end i end
#¶ ↑
remove_unnecessary_data_from_url
¶ ↑
This method removes some meaningless information that can be found in some URLs.
#¶ ↑
# File lib/rbt/base/misc.rb, line 359 def remove_unnecessary_data_from_url(i) i = i.first if i.is_a? Array i = i.to_s.dup i = File.basename(i) i.gsub(/download\?file=/,''). sub(/\/download$/,''). sub(/\?download$/,''). gsub(/-fullsrc/,''). gsub(/-source/,''). gsub(/\?use_mirror=dfn/,''). gsub(/\.src/,''). gsub(/-src/,'') # .gsub(/_/,'-') # This here may be controversial, hence it # was disabled as of June 2010. # i = remove_file_extension(i) # ^^^ We can not do the above, because program_full_name # must include the archive. end
#¶ ↑
repackage (repackage tag)¶ ↑
This method will repackage an archive format such as .tar.gz into .tar.xz.
#¶ ↑
# File lib/rbt/base/misc.rb, line 693 def repackage( i, use_this_for_the_opnn_namespace = 'RBT::Repackage' ) begin require 'repackage' if File.exist? i opnn( namespace_to_use: use_this_for_the_opnn_namespace ) e "Trying to repackage `#{sfile(i)}` next:" Repackage.new(i) {{ run: :run_already, delete_code_of_conduct: delete_code_of_conduct? }} else # Not sure whether we should report to the user or not. end rescue LoadError e 'The gem called "repackage" is not available - please install it' e "in order to repackage the archive at hand here (`#{sfile(i)}`)." end end
#¶ ↑
report_to_developers
¶ ↑
Feedback information to the user so that he can report useful information to the project lead.
#¶ ↑
# File lib/rbt/base/misc.rb, line 226 def report_to_developers( this_email = RBT.configuration?.email ) opnwarn 'To report to the developer(s) of RBT, use this '\ 'email address:' opne opnn; efancy ' '+this_email opne opnwarn 'You can also use this URL:' opne opnn; efancy " #{RBT_HOMEPAGE_URL}" if RBT_HOMEPAGE_URL.include? 'rbt' opnn; efancy ' https://rubygems.org/profiles/58718/' end opne end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/reset.rb, line 25 def reset # ======================================================================= # # === @internal_hash # # This definition for the internal Hash *must* come first. # ======================================================================= # @internal_hash = {} populate_the_internal_hash_with_default_values end
#¶ ↑
return_appdir_prefix
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1095 def return_appdir_prefix(i) return RBT.return_appdir_prefix(i) end
#¶ ↑
return_commandline_arguments_with_leading_hyphens
¶ ↑
This will select all commandline-arguments with leading ‘–’ characters.
#¶ ↑
# File lib/rbt/base/prototype/commandline_arguments.rb, line 128 def return_commandline_arguments_with_leading_hyphens( i = commandline_arguments? ) i.select {|entry| entry and entry.start_with?('--') } end
#¶ ↑
return_n_random_characters
¶ ↑
This method will return n random characters, as Strings. It is used specifically to “create” a random temporary directory, into which archives can be extracted into.
#¶ ↑
# File lib/rbt/base/misc.rb, line 566 def return_n_random_characters( i = 10 ) array = ('a'..'z').to_a _ = ''.dup i.times { _ << array.sample } _ end
#¶ ↑
return_program_name
¶ ↑
This will always return the proper program name. If you need to modify that name, you must do so on your own.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 370 def return_program_name(i, optional_padding = ' ') _ = ''.dup if REPORT_SPECIFIC_PROGRAM_NAME _ << "#{File.basename(i)}:#{optional_padding}" end return _ end
#¶ ↑
return_utc_time_in_a_format_similar_to_slackware
¶ ↑
Slackware changelog uses a format such as this one here, in a UTC format:
Thu Sep 21 01:23:24 UTC 2017
#¶ ↑
# File lib/rbt/base/time.rb, line 156 def return_utc_time_in_a_format_similar_to_slackware return "#{return_weekday_based_on_utc.to_s} "\ "#{return_month_based_on_utc.to_s} "\ "#{return_day_of_the_month_based_on_utc} "\ "#{return_hours_minutes_seconds_based_on_utc}"\ " UTC "\ "#{return_year_based_on_utc}" end
#¶ ↑
run_ldconfig?¶ ↑
#¶ ↑
# File lib/rbt/base/misc.rb, line 441 def run_ldconfig? RBT.configuration?.run_ldconfig end
#¶ ↑
run_simulation
¶ ↑
Setter method for the ivar @run_simulation.
This way we can run in simulation mode. That way, we won’t do any modifications, we will only assume that certain things be done.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 597 def run_simulation=(i = false) @internal_hash[:run_simulation] = i end
#¶ ↑
run_simulation
?¶ ↑
This method will tell us whether we shall we run in simulation mode or whether we shall not. The default is false, as in, we will not run in simulation mode.
The simulation mode is required to tell the user what we would do, without actually doing any of these changes. It is a “dry run”, a test run.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 316 def run_simulation? @internal_hash[:run_simulation] end
#¶ ↑
sdir_return_pwd
¶ ↑
This method will simply colourize the returned String from the method return_pwd
().
#¶ ↑
# File lib/rbt/base/prototype/return_pwd.rb, line 27 def sdir_return_pwd sdir(return_pwd) end
#¶ ↑
set_be_verbose
¶ ↑
By default we will be verbose.
#¶ ↑
# File lib/rbt/base/prototype/be_verbose.rb, line 43 def set_be_verbose(i = true) @internal_hash[:be_verbose] = i end
#¶ ↑
set_namespace
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 1072 def set_namespace(i) @internal_hash[:namespace] = i end
#¶ ↑
set_source_directory
¶ ↑
Set the source dir to ANY new location. Defaults to Dir.pwd.
Example to test it this method:
ry mantis --source_dir=/Depot/j
#¶ ↑
# File lib/rbt/base/misc.rb, line 299 def set_source_directory( i = return_pwd, be_verbose = false ) i << '/' unless i.end_with? '/' RBT.set_source_directory(i) if be_verbose? e "Setting source directory to `#{sdir(i)}` next." end end
#¶ ↑
set_use_opn
¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/opn.rb, line 30 def set_use_opn(i = true) # Must remain true by default. @internal_hash[:use_opn] = i end
#¶ ↑
simp¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 123 def simp(i = '') return ::RBT.simp(i) if use_colours? return i end
#¶ ↑
store_into_this_directory?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 154 def store_into_this_directory? _ = RBT.store_into_this_directory? ensure_that_this_directory_exists(_) # Make sure that the directory exists. return _ end
#¶ ↑
symlink (symlink tag)¶ ↑
Wrapper to symlinking something.
The first argument should be the existing target.
The second argument shall be the name of the new location.
Since as of November 2019, the following syntax is supported as well:
symlink( from: @target_directory+'lib64', to: @target_directory+'lib' )
#¶ ↑
# File lib/rbt/base/symlink.rb, line 82 def symlink( existing, new_location = nil, be_verbose = true, use_colours = RBT.use_colours? # Here we need colours/colours.rb ) # ======================================================================= # # === Handle blocks next # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :be_quiet # ===================================================================== # when :be_quiet be_verbose = false end end # ======================================================================= # # === Handle Hashes next # ======================================================================= # if existing.is_a? Hash # ===================================================================== # # === :to # ===================================================================== # if existing.has_key?(:to) and new_location.nil? new_location = existing.delete(:to) end # ===================================================================== # # === :from # ===================================================================== # if existing.has_key?(:from) existing = existing.delete(:from) end end ::RBT.symlink( existing, new_location, be_verbose, use_colours ) end
#¶ ↑
symlink_all_files_from_this_directory_to_that_directory
¶ ↑
This method can be used to symlink two directories to one another, e. g. from directory A onto directory B.
#¶ ↑
# File lib/rbt/base/symlink.rb, line 20 def symlink_all_files_from_this_directory_to_that_directory( this_dir, that_dir, delete_target_file = false ) # ======================================================================= # # Select only files next: # ======================================================================= # _ = Dir[("#{this_dir}/*").squeeze('/')].select {|entry| is_file?(entry) } # ======================================================================= # # === Handle blocks next # # The block-variant can remove target-files. This is not the default, # so you have to specifically enable this if you want that # functionality. # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :also_include_directories # ===================================================================== # when :also_include_directories, :include_directories _ = Dir[("#{this_dir}/*").squeeze('/')].select {|entry| is_file?(entry) or is_directory?(entry) } when :delete_target_file_if_it_exists delete_target_file = true end end _.each {|entry| # ===================================================================== # # Note that the following clause is NOT the default. # ===================================================================== # if delete_target_file _ = that_dir+File.basename(entry) if File.exist?(_) and File.file?(_) remove_file(_) end end symlink(entry, that_dir) } end
#¶ ↑
sysbin_directory?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 262 def sysbin_directory? RBT.sysbin_directory? end
#¶ ↑
sysetc_directory?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 488 def sysetc_directory? RBT.sysetc_directory? end
#¶ ↑
sysinclude_directory?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 276 def sysinclude_directory? RBT.sysinclude_directory? end
#¶ ↑
syslib_directory?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 284 def syslib_directory? RBT.syslib_directory? end
#¶ ↑
today?¶ ↑
This method will return a String such as “21 September 2017”.
#¶ ↑
# File lib/rbt/base/time.rb, line 123 def today?( display_in_long_format = true ) if display_in_long_format # This is the default. Time.now.strftime('%d %B %Y') # => "28 December 2018" else Time.now.strftime('%d.%m.%Y') # => "28.12.2018" end end
#¶ ↑
touch (touch tag)¶ ↑
Use this unified method whenever you wish to create a new file, like the UNIX “touch” command.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 694 def touch( i, be_verbose = false ) case be_verbose when :be_verbose be_verbose = true end if be_verbose e "Next creating the file `#{sfile(i)}`." end FileUtils.touch(i) end
#¶ ↑
try_to_require_the_xorg_buffer
¶ ↑
#¶ ↑
# File lib/rbt/base/xorg.rb, line 22 def try_to_require_the_xorg_buffer begin require 'xorg_buffer' # or: require 'xorg_buffer/module' rescue LoadError if RUBY_PLATFORM.include?('linux') and is_on_roebe? puts 'The gem called `xorg_buffer` is unavailable. '\ 'Consider installing it.' end end end
#¶ ↑
use_colours?¶ ↑
Query whether we may use colours or not.
#¶ ↑
# File lib/rbt/base/prototype/colours.rb, line 102 def use_colours? @internal_hash[:use_colours] end
#¶ ↑
use_opn?¶ ↑
#¶ ↑
# File lib/rbt/base/prototype/opn.rb, line 69 def use_opn? @internal_hash[:use_opn] end
#¶ ↑
use_porg?¶ ↑
Whether we will use porg for installation or whether we will not.
Most users probably do not need/want this, so this is mostly for my home system, but also those users who may wish to use porg.
#¶ ↑
# File lib/rbt/base/misc.rb, line 216 def use_porg? RBT.configuration?.use_porg end
#¶ ↑
verbose_truth
¶ ↑
This will give us back “yes” or “no”, in String form.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 552 def verbose_truth(i, optional_arguments = nil) RBT.verbose_truth(i, optional_arguments) end
#¶ ↑
warn_and_exit
¶ ↑
This method will exit from the scripts.
You should be careful when using this, because in some situations we do not actually want to exit completely - for example when we chain-compile something.
# ¶ ↑
# File lib/rbt/base/misc.rb, line 461 def warn_and_exit(input, exit_mode = true) warn(input, exit_mode) end
#¶ ↑
word_wrap
¶ ↑
The first argument is the text that will be reformatted.
The second argument is at which position we will wrap it.
#¶ ↑
# File lib/rbt/base/prototype/word_wrap.rb, line 20 def word_wrap( this_text, n_characters_limit = :default # This should be equal to 78. ) ::RBT.wrap_at(this_text, n_characters_limit) end
#¶ ↑
yes_or_no
¶ ↑
Return ‘Yes.’ or ‘No.’ through this method here.
#¶ ↑
# File lib/rbt/base/prototype/misc.rb, line 345 def yes_or_no( i, optional_instructions = nil ) case i when true,'true' i = 'Yes.' when false,'false' i = 'No.' end case optional_instructions # ======================================================================= # # === :minimalistic # ======================================================================= # when :minimalistic i = i.downcase.delete('.') if i end return i end