class RBT::SuggestCookbookFor

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

[](i = '') click to toggle source
#

RBT::SuggestCookbookFor[]

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 621
def self.[](i = '')
  self.new(i)
end
new( commandline_arguments = nil, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 35
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  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
#

add (add tag)

This method will simply add (aka append) onto the @result variable.

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 149
def add(i, append_newline = true)
  if append_newline
    i = i.dup if i.frozen?
    i << "\n"
  end
  @result << i
end
binaries?() click to toggle source
#

binaries?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 77
def binaries?
  @binaries
end
blfs_entry?() click to toggle source
#

blfs_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 244
def blfs_entry?
  @dataset_from_the_expanded_cookbooks_directory['blfs']
end
commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 140
def commandline_arguments?
  @commandline_arguments
end
configure_base_dir?() click to toggle source
#

configure_base_dir?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 284
def configure_base_dir?
  @dataset_from_the_expanded_cookbooks_directory['configure_base_dir']
end
configure_options?() click to toggle source
#

configure_options?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 258
def configure_options?
  @dataset_from_the_expanded_cookbooks_directory and
  @dataset_from_the_expanded_cookbooks_directory['configure_options']
end
dataset_from_the_expanded_cookbooks_directory?() click to toggle source
#

dataset_from_the_expanded_cookbooks_directory?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 84
def dataset_from_the_expanded_cookbooks_directory?
  @dataset_from_the_expanded_cookbooks_directory
end
description?(pad_so_that_the_lines_are_all_equal = true) click to toggle source
#

description?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 266
def description?(pad_so_that_the_lines_are_all_equal = true)
  _ = @dataset_from_the_expanded_cookbooks_directory['description']
  _ = 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
expanded_cookbooks?()
expanded_dataset?()
has_blfs_entry?() click to toggle source
#

has_blfs_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 175
def has_blfs_entry?
  expanded_dataset? and
  expanded_dataset?.has_key?('blfs') and
 !expanded_dataset?['blfs'].empty? # <- We only care about non-empty Arrays here.
end
has_configure_base_directory_entry?() click to toggle source
#

has_configure_base_directory_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 191
def has_configure_base_directory_entry?
  expanded_dataset? and
  expanded_dataset?.has_key?('configure_base_dir')
end
has_homepage_entry?() click to toggle source
#

has_homepage_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 184
def has_homepage_entry?
  expanded_dataset?.has_key?('homepage')
end
has_required_deps?() click to toggle source
#

has_required_deps?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 167
def has_required_deps?
  expanded_dataset?.has_key?('required_deps_on') and
  !expanded_dataset?['required_deps_on'].empty?
end
has_sed_entry?() click to toggle source
#

has_sed_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 596
def has_sed_entry?
  expanded_dataset? and
  expanded_dataset?.has_key?('sed') and
  expanded_dataset?['sed'] and
 !expanded_dataset?['sed'].empty?
end
has_url1_entry?() click to toggle source
#

has_url1_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 199
def has_url1_entry?
  expanded_dataset?.has_key?('url1')
end
has_url2_entry?() click to toggle source
#

has_url2_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 206
def has_url2_entry?
  expanded_dataset?.has_key?('url2')
end
homepage_entry?() click to toggle source
#

homepage_entry?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 237
def homepage_entry?
  @dataset_from_the_expanded_cookbooks_directory['homepage']
end
infer_program_name_from(i) click to toggle source
#

infer_program_name_from

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 116
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 = YAML.load_file(
        this_file
      )
    end
  end
end
input?()
Alias for: program_name?
libraries?() click to toggle source
#

libraries?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 70
def libraries?
  @libraries
end
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 100
def program_name?
  @program_name
end
Also aliased as: input?
report_something?() click to toggle source
#

report_something?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 93
def report_something?
  @report_the_result
end
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/utility_scripts/suggest_cookbook_for.rb, line 568
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?(_)
      opnn; e 'We will additionally make use of the expanded '\
              'cookbook dataset'
      opnn; e "for `#{sfancy(i)}`."
    else
      # ===================================================================== #
      # We will report if we are on roebe.
      # ===================================================================== #
      if is_on_roebe?
        opnn; e "There is no expanded cookbook dataset for `"\
                "#{sfile(@program_name)}`."
        opnn; e '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
#

required_deps_on?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 251
def required_deps_on?
  @dataset_from_the_expanded_cookbooks_directory['required_deps_on']
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 56
def reset
  super()
  @namespace = NAMESPACE
  @dataset_from_the_expanded_cookbooks_directory = nil
  @program_name = nil
  @result = ''.dup
  @report_the_result = true
  @libraries = [] # We store found libraries in this Array here.
  @binaries  = [] # We store found binaries in this Array here.
end
result?() click to toggle source
#

result?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 160
def result?
  @result
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 613
def run
  try_to_obtain_information_from_the_corresponding_appdir_subdirectory_of_the_program
  try_to_report if @report_the_result
end
sanitize_binaries_entries() click to toggle source
#

sanitize_binaries_entries

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 514
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/utility_scripts/suggest_cookbook_for.rb, line 531
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)
  # ======================================================================= #
  # 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?() click to toggle source
#

sed?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 606
def sed?
  expanded_dataset?['sed'].to_s.tr("\n",' ').squeeze(' ')
end
set_commandline_arguments(i = '') click to toggle source
#

set_input

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 107
def set_commandline_arguments(i = '')
  i = [i].flatten.compact
  @commandline_arguments = i
  infer_program_name_from(i.first)
end
short_desc?() click to toggle source
#

short_desc?

This method will only work if the expanded-cookbook dataset exits.

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 229
def short_desc?
  @dataset_from_the_expanded_cookbooks_directory and
  @dataset_from_the_expanded_cookbooks_directory['short_description']
end
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/utility_scripts/suggest_cookbook_for.rb, line 294
def try_to_obtain_information_from_the_corresponding_appdir_subdirectory_of_the_program
  if report_something?
    opnn; e '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.
    # ===================================================================== #
    headers         = Dir["#{_}/include/**/**.{h,hpp}"].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
    pkgconfig_files = Dir["#{_}/lib/pkgconfig/**"].sort
    # ===================================================================== #
    # 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.to_s
    else
      # ===================================================================== #
      # else we will add a stub
      # ===================================================================== #
      add ' # blfs:'
      add ' # - http://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
      # ===================================================================== #
      # 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
    end
    # ===================================================================== #
    # Now we will add the short_description tag.
    # ===================================================================== #
    add ' short_description: |'
    if expanded_cookbooks_directory_exists? and
       main_dataset
      add '  '+short_desc? if short_desc?
    end
    add ' description: |'
    if expanded_cookbooks_directory_exists? and
       main_dataset
      add '  '+description?
    end
    add ' extra_information: |'
    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
    # ===================================================================== #
    # 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
    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
    # ===================================================================== #
    # 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: f'
    add ' use_build_directory: f'
    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
    add ' licence: '
    # ===================================================================== #
    # Next add a last_update entry, in a format like "18 Dec 2018".
    # ===================================================================== #
    add " last_update: "\
        "#{get_date}"
  else
    opnn; e "No file exists at `#{sfile(_)}`."
  end
end
try_to_report() click to toggle source
#

try_to_report (report tag)

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 557
def try_to_report
  if @result.empty?
    # Do nothing in this case.
  else
    e @result
  end
end
url1?() click to toggle source
#

url1?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 220
def url1?
  @dataset_from_the_expanded_cookbooks_directory['url1']
end
url2?() click to toggle source
#

url2?

#
# File lib/rbt/utility_scripts/suggest_cookbook_for.rb, line 213
def url2?
  @dataset_from_the_expanded_cookbooks_directory['url2']
end