class RBT::SuggestCookbookFor
Public Class Methods
[](i = '')
click to toggle source
new( commandline_arguments = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 32 def initialize( commandline_arguments = nil, run_already = true ) reset set_commandline_arguments( commandline_arguments ) # ======================================================================= # # Next, we infer the program name at once. # ======================================================================= # infer_program_name_from( first_argument? ) if block_given? yielded = yield case yielded when :do_not_report @report_the_result = false end end run if run_already end
Public Instance Methods
add(i, append_newline = true)
click to toggle source
binaries?()
click to toggle source
blfs_entry?()
click to toggle source
configure_base_dir?()
click to toggle source
configure_options?()
click to toggle source
dataset_from_the_expanded_cookbooks_directory?()
click to toggle source
description?(pad_so_that_the_lines_are_all_equal = true)
click to toggle source
#¶ ↑
description?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 295 def description?(pad_so_that_the_lines_are_all_equal = true) _ = @dataset_from_the_expanded_cookbooks_directory[:description].to_s _ = word_wrap(_, 74).strip if pad_so_that_the_lines_are_all_equal splitted = _.split("\n").map {|entry| unless entry.start_with? ' ' entry.prepend(' ') end entry } _ = splitted.join("\n") end _.strip end
has_blfs_entry?( use_this_key = 'blfs' )
click to toggle source
#¶ ↑
has_blfs_entry?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 199 def has_blfs_entry?( use_this_key = 'blfs' ) use_this_key = use_this_key.to_sym if use_symbols? expanded_dataset? and expanded_dataset?.has_key?(use_this_key) and !expanded_dataset?[use_this_key].empty? # ← We only care about non-empty Arrays here. end
has_configure_base_directory_entry?()
click to toggle source
has_homepage_entry?( use_this_key = 'homepage' )
click to toggle source
has_required_deps?( use_this_key = 'required_deps_on' )
click to toggle source
has_sed_entry?( use_this_key = 'sed' )
click to toggle source
#¶ ↑
has_sed_entry?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 746 def has_sed_entry?( use_this_key = 'sed' ) use_this_key = use_this_key.to_sym if use_symbols? expanded_dataset? and expanded_dataset?.has_key?(use_this_key) and expanded_dataset?[use_this_key] and !expanded_dataset?[use_this_key].empty? end
has_url1_entry?( use_this_key = 'url1' )
click to toggle source
has_url2_entry?( use_this_key = 'url2' )
click to toggle source
homepage_entry?()
click to toggle source
infer_program_name_from(i)
click to toggle source
#¶ ↑
infer_program_name_from
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 143 def infer_program_name_from(i) # ======================================================================= # # Note that @program_name is not allowed to have a trailing '.yml' # component. # ======================================================================= # @program_name = i.to_s.downcase.delete('-'). sub(/\.yml$/,'') @name_of_the_cookbook_file = "#{@program_name}.yml" # ======================================================================= # # We have to check whether an expanded cookbook dataset exists. If # so then we can infer information from this file. # ======================================================================= # if expanded_cookbooks_directory_exists? this_file = directory_expanded_cookbooks?+@name_of_the_cookbook_file if File.exist? this_file @dataset_from_the_expanded_cookbooks_directory = load_yaml( this_file ) end end end
libraries?()
click to toggle source
program_name?()
click to toggle source
#¶ ↑
program_name?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 136 def program_name? @program_name end
Also aliased as: input?
program_version?()
click to toggle source
report_something?()
click to toggle source
report_whether_there_exists_an_expanded_cookbook_dataset_for(i)
click to toggle source
#¶ ↑
report_whether_there_exists_an_expanded_cookbook_dataset_for
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 616 def report_whether_there_exists_an_expanded_cookbook_dataset_for(i) i = i.dup i << '.yml' unless i.end_with? '.yml' _ = directory_expanded_cookbooks?+i if report_something? if File.exist?(_) opne 'We will additionally make use of the expanded '\ 'cookbook' opne "dataset for `#{sfancy(i)}`." else # ===================================================================== # # We will report if we are on roebe. # ===================================================================== # if is_on_roebe? opne "There is no expanded cookbook dataset for `"\ "#{sfile(@program_name)}`." opne 'A new one can be generated via:' e e " expand_cookbooks #{sfile(@program_name)}" e end end end end
required_deps_on?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 59 def reset super() infer_the_namespace # ======================================================================= # # === @dataset_from_the_expanded_cookbooks_directory # ======================================================================= # @dataset_from_the_expanded_cookbooks_directory = nil # ======================================================================= # # === @program_name # ======================================================================= # @program_name = nil # ======================================================================= # # === @result # ======================================================================= # @result = ''.dup # ======================================================================= # # === @report_the_result # ======================================================================= # @report_the_result = true # ======================================================================= # # === @libraries # # We store found libraries in this Array here. # ======================================================================= # @libraries = [] # ======================================================================= # # === @binaries # # We store found binaries in this Array here. # ======================================================================= # @binaries = [] # ======================================================================= # # === @use_symbols_or_strings_for_the_key # ======================================================================= # @use_symbols_or_strings_for_the_key = :symbols end
result?()
click to toggle source
return_licence( use_this_key = 'licence' )
click to toggle source
run()
click to toggle source
sanitize_binaries_entries()
click to toggle source
#¶ ↑
sanitize_binaries_entries
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 588 def sanitize_binaries_entries # ======================================================================= # # The following regex will get rid of the absolute path entries. # ======================================================================= # _ = appdir_location_of?(@program_name) quoted_regex_for_bin_entries = Regexp.quote("#{_}/bin/") quoted_regex_for_sbin_entries = Regexp.quote("#{_}/sbin/") @binaries.flatten! @binaries.map! {|binary_file| binary_file.sub(quoted_regex_for_bin_entries, ''). sub(quoted_regex_for_sbin_entries, '') } end
sanitize_libraries_entries()
click to toggle source
#¶ ↑
sanitize_libraries_entries
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 712 def sanitize_libraries_entries # ======================================================================= # # We must deduct all entries that contain the word 'pkgconfig' from # this Array, as the pkgconfig entry will have its own separate # entry here. # ======================================================================= # @libraries.reject! {|line| # ===================================================================== # # Directories will also be skipped. # ===================================================================== # line.include? 'pkgconfig' or File.directory?(line) or line.end_with?('.dll') } _ = appdir_location_of?(@program_name) # ======================================================================= # # Check for broken symlinks. # ======================================================================= # if File.symlink?(_) and !File.exist?(_) opne 'A broken symlink was found at `'+steelblue(_)+'`.' opne 'Please fix this manually before this class can continue.' exit end # ======================================================================= # # The following regex will get rid of the absolute path entries. # ======================================================================= # quoted_regex = Regexp.quote("#{_}/lib/") @libraries.map! {|library_file| library_file.sub(quoted_regex, '') } end
sed?( use_this_key = 'sed' )
click to toggle source
#¶ ↑
sed?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 759 def sed?( use_this_key = 'sed' ) use_this_key = use_this_key.to_sym if use_symbols? result = expanded_dataset?[use_this_key].flatten if result.is_a? Array result = result.join("\n") end result = result.to_s.tr("\n",' ').squeeze(' ') result end
short_desc?()
click to toggle source
show_help()
click to toggle source
try_to_obtain_information_from_the_corresponding_appdir_subdirectory_of_the_program()
click to toggle source
#¶ ↑
try_to_obtain_information_from_the_corresponding_appdir_subdirectory_of_the_program
¶ ↑
This is the method that will try to obtain as much information as necessary in order to display the result on the commandline.
#¶ ↑
# File lib/rbt/cookbooks/suggest_cookbook_for.rb, line 323 def try_to_obtain_information_from_the_corresponding_appdir_subdirectory_of_the_program if report_something? opne "Next trying to display the guessed content for `"\ "#{sfile(@name_of_the_cookbook_file)}`." end report_whether_there_exists_an_expanded_cookbook_dataset_for( @program_name ) _ = appdir_location_of?(@program_name) is_a_symlink = File.symlink?(_) # ======================================================================= # # ^^^ This variable may be a String such as "/Programs/Cluttergtk/Current". # This may not exist, though, if it is a symlink and has been deleted # or not (yet) created. So we will try to do an additional check if we # are on roebe - we will check if there is any directory that starts # with a number, such as '18.0.2'. # ======================================================================= # if is_on_roebe? and !File.exist?(_) dirname = "#{File.dirname(_)}/" subdirectories_in_that_directory = Dir[dirname+'*'].select {|entry| File.directory?(entry) } # ===================================================================== # # Must check whether we have found any subdirectories or not: # ===================================================================== # unless subdirectories_in_that_directory.empty? subdirectories_in_that_directory.select! {|entry| File.basename(entry).start_with?(/\d+/) } unless subdirectories_in_that_directory.empty? _ = subdirectories_in_that_directory.first # Grab the first entry. is_a_symlink = true # This is hackish but we need it to continue, below. end end end # ======================================================================= # # Obtain a "pointer" towards the main dataset. # ======================================================================= # main_dataset = main_dataset? if File.exist?(_) and is_a_symlink # ===================================================================== # # Headers are typically .h files, but also .hpp for C++. This # explains the next line of code. # On 05.12.2019 this was changed - .hpp are not so useful, so let's # not include them. # ===================================================================== # # headers = Dir["#{_}/include/**/**.{h,hpp}"].sort headers = Dir["#{_}/include/**/**.{h}"].sort @libraries = Dir["#{_}/lib/**/**"].sort sanitize_libraries_entries @binaries = Dir["#{_}/bin/**"].sort # ===================================================================== # # We will also append entries found under sbin/, if this directory # exists. # ===================================================================== # if File.directory? "#{_}/sbin/" @binaries << Dir["#{_}/sbin/**"].sort end sanitize_binaries_entries # ===================================================================== # # We first have to add the program name - this one comes ALWAYS on top. # ===================================================================== # add @program_name+':' # ===================================================================== # # Next we will consider adding a blfs entry, but this has to be # optional because not every program has a registered blfs entry. # ===================================================================== # if expanded_cookbooks_directory_exists? and has_blfs_entry? add ' blfs:' blfs_entry = blfs_entry? blfs_entry = blfs_entry.first if blfs_entry.is_a? Array add " - #{blfs_entry}" else # ===================================================================== # # else we will add a stub towards linuxfromscratch.org # ===================================================================== # add ' # blfs:' add ' # - https://www.linuxfromscratch.org/blfs/view/cvs/general/glib2.html' end # ===================================================================== # # Next, consider adding binaries entries, if these exist. # ===================================================================== # if @binaries.empty? add ' # binaries:' else add ' binaries:' quoted_regex = Regexp.quote(_+'/bin/') @binaries.each {|this_binary| add ' - '+this_binary.sub(quoted_regex, '') } end # ===================================================================== # # We have to check whether the expanded cookbooks-dataset also # contains an entry called configure_base_dir. If it does we # will make use of it. # ===================================================================== # if expanded_cookbooks_directory_exists? and has_configure_base_directory_entry? and main_dataset add ' configure_base_dir: '+configure_base_dir? end # ===================================================================== # # Next, add the configure options: # ===================================================================== # add ' configure_options: |' if expanded_cookbooks_directory_exists? and main_dataset # Must check that we have found something here. the_configure_options = configure_options?.dup.to_s # ===================================================================== # # We can modify/simplify the configure options a bit, if they # contain at the least one '--' set. # ===================================================================== # if the_configure_options.include? '--' the_configure_options.gsub!(/--/, "\n ") the_configure_options << "\n" end add " #{the_configure_options}" unless the_configure_options.empty? end # ===================================================================== # # Now we will add the short_description tag. # ===================================================================== # add " short_description: |\n" if expanded_cookbooks_directory_exists? and main_dataset add " #{short_desc?}\n" if short_desc? end add " description: |\n" if expanded_cookbooks_directory_exists? and main_dataset add " #{description?}\n" end add " extra_information: |\n" add ' licence: '+return_licence.to_s # ===================================================================== # # Next add the url1 entry: # ===================================================================== # if expanded_cookbooks_directory_exists? and main_dataset and has_url1_entry? add " url1: #{url1?}" else add ' url1: ' end if expanded_cookbooks_directory_exists? and main_dataset and has_url2_entry? add " url2: #{url2?}" else add ' url2: ' end if expanded_cookbooks_directory_exists? and main_dataset and has_homepage_entry? add " homepage: #{homepage_entry?}" else add ' homepage: ' end # ===================================================================== # # === .gir files # # Next, consider adding .gir files - if they exist. # ===================================================================== # gir_files = Dir["#{_}/share/gir-1.0/**.{gir}"].sort unless gir_files.empty? add ' gir_files:' gir_files.each {|gir_file| gir_file = gir_file.dup if gir_file.frozen? gir_file.strip! gir_file.sub!("#{_}/share/gir-1.0/", '') add " - #{gir_file}" } end # ===================================================================== # # === Headers # # Next, consider adding headers - if they exist. # ===================================================================== # unless headers.empty? add ' symlink_headers: t' add ' headers:' quoted_regex = Regexp.quote("#{_}/include/") headers.each {|header_file| add " - #{header_file.sub(quoted_regex, '')}" } end # ===================================================================== # # Next, consider adding the libraries-section: # ===================================================================== # unless @libraries.empty? add ' libraries:' @libraries.each {|library_file| add ' - '+library_file } end # ===================================================================== # # Add the pkg-config .pc files next, if they exist. # ===================================================================== # pkgconfig_files = Dir["#{_}/lib/pkgconfig/**"].sort.select {|file| file.end_with? '.pc' # ← Only use .pc files. } unless pkgconfig_files.empty? add ' symlink_pkgconfig_files: t' add ' pkgconfig_files:' quoted_regex = Regexp.quote(_+'/lib/pkgconfig/') pkgconfig_files.each {|pkgconfig_file| add ' - '+pkgconfig_file.sub(quoted_regex, '') } end # ===================================================================== # # Add the .m4 files next, if they exist. # ===================================================================== # m4_files = Dir["#{_}/share/aclocal/*.m4"].sort.select {|file| file.end_with? '.m4' # ← Only use .pc files. } unless m4_files.empty? add ' m4_files:' quoted_regex = Regexp.quote(_+'/share/aclocal/') m4_files.each {|m4_file| add ' - '+m4_file.sub(quoted_regex, '') } end # ===================================================================== # # Consider adding sed-instructions if they exist: # ===================================================================== # if has_sed_entry? # =================================================================== # # Ok, this program has a sed entry, so show it:' # =================================================================== # add ' sed:' add ' - '+sed? end # ===================================================================== # # Add the prefix variable next. # ===================================================================== # add ' prefix: t' add ' keep_extracted: no' add ' use_build_directory: '+ yes_or_no( use_build_directory?.to_s, :minimalistic ) add ' required_deps_on:' if expanded_cookbooks_directory_exists? and main_dataset and has_required_deps? required_deps_on?.each {|dep| add " - #{dep}" } else add ' - ' end # ===================================================================== # # Next add a last_update entry, in a format like "18 Dec 2018". # ===================================================================== # add " last_update: "\ "#{get_date}" else opnn; no_file_exists_at(_) end end
try_to_report()
click to toggle source
url1?()
click to toggle source
url2?()
click to toggle source
use_build_directory?( use_this_key = 'use_build_directory' )
click to toggle source