class RBT::Base
Public Class Methods
Public Instance Methods
#¶ ↑
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/base.rb, line 448 def cd_back_to_the_current_working_directory working_directory = return_pwd if block_given? yield end cd(working_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/base.rb, line 466 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
#¶ ↑
delete_code_of_conduct?¶ ↑
Query method over as to whether we will try to remove code-of-conduct files. This is usually only valid for my home system, or when a config-option has been set to true. Note that the default value is false, so that other users can decide on their own whether they want to retain code of conducts or not.
#¶ ↑
# File lib/rbt/base/base.rb, line 138 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/base.rb, line 254 def determine_appdir_prefix_from_this_input( i = nil, program_version = nil ) return RBT.determine_appdir_prefix_from_this_input( i, program_version ) 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/base.rb, line 325 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
#¶ ↑
is_a_64bit_system?¶ ↑
This method will return true if the underlying system is a 64-bit system.
#¶ ↑
# File lib/rbt/base/base.rb, line 115 def is_a_64bit_system? RUBY_PLATFORM.include? '_64' # Due to → "x86_64-linux". end
#¶ ↑
is_ccache_available?¶ ↑
This method queries as to whether ccache is available or whether it is not.
#¶ ↑
# File lib/rbt/base/base.rb, line 269 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_porg_available?¶ ↑
This method is required to determine whether porg is available or not.
#¶ ↑
# File lib/rbt/base/base.rb, line 388 def is_porg_available? result = `porg 2>&1`.include? 'porg: command not found' return !result 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/base.rb, line 359 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
#¶ ↑
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/base.rb, line 619 def new_cookbook_instance_for(name_of_the_program) action(:sanitize_cookbook, name_of_the_program) 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/base.rb, line 170 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
#¶ ↑
remove_symlink
¶ ↑
Simply remove a symlink. Use this method consistently when you wish to remove any symlink.
#¶ ↑
# File lib/rbt/base/base.rb, line 582 def remove_symlink( i, be_verbose = false ) case be_verbose # === :be_quiet when :be_quiet be_verbose = false # === :be_verbose when :be_verbose be_verbose = true end if i.is_a? Array i.each {|entry| remove_symlink(entry, be_verbose) } else if File.symlink?(i) if be_verbose e "#{rev}Now deleting the symlink `#{sfancy(i)}#{rev}`." end File.delete(i) end end end
#¶ ↑
repackage (repackage tag)¶ ↑
This method will repackage an archive format such as .tar.gz into .tar.xz.
#¶ ↑
# File lib/rbt/base/base.rb, line 70 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 "#{rev}Trying to repackage `#{sfile(i)}#{rev}` 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 "#{rev}The gem called \"repackage\" is not available - please install it" e "in order to repackage the archive at hand here (`#{sfile(i)}`)." end 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/base.rb, line 487 def return_n_random_characters( i = 10 ) array = ('a'..'z').to_a _ = ''.dup i.times { _ << array.sample } _ end
#¶ ↑
set_source_directory
¶ ↑
Set the source dir to ANY new location. Defaults to Dir.pwd.
Example to test this method:
ry mantis --source_dir=/Depot/j
#¶ ↑
# File lib/rbt/base/base.rb, line 403 def set_source_directory( i = return_pwd, be_verbose = false ) i << '/' unless i.end_with? '/' RBT.set_source_directory(i) if be_verbose? e "#{rev}Setting source directory to `#{sdir(i)}#{rev}` next." end 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/base.rb, line 531 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
#¶ ↑
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/base.rb, line 295 def warn_and_exit(input, exit_mode = true) warn(input, exit_mode) end