class RBT::Cookbooks::IncrementProgramVersion

Constants

DEFAULT_PROGRAM
#

DEFAULT_PROGRAM

#
TRY_TO_REPACKAGE_INTO_TAR_XZ_FORMAT
#

TRY_TO_REPACKAGE_INTO_TAR_XZ_FORMAT

If the following constant is true then incremented programs will be repackaged into .tar.xz, unless they are already in this format.

This constant is thus mostly a convenience setting, if you wish to keep archives in .tar.xz, which I do.

#

Public Class Methods

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

RBT::Cookbooks::IncrementProgramVersion[]

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 406
def self.[](i = '')
  new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 34
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Public Instance Methods

assign_url_to_dataset_url(use_this_dataset) click to toggle source
#

assign_url_to_dataset_url

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 292
def assign_url_to_dataset_url(use_this_dataset)
  @url = use_this_dataset.url1?
end
check_for_incremented_remote_versions( i = url? ) click to toggle source
#

check_for_incremented_remote_versions

This is the method that will check for the remote versions.

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 101
def check_for_incremented_remote_versions(
    i = url?
  )
  if i.nil? or i.empty?
    e 'No '+steelblue('url1')+' entry could be found. '+
      lightblue('Is the .yml file correct?')
    return
  end
  original_version = ProgramInformation.return_version(i)
  e "The input-version was `#{sfancy(original_version)}`."
  original_split   = original_version.split('.')
  splitted         = original_split
  # ======================================================================= #
  # === Minor Version Check
  #
  # First check for minor-version part. We must be careful here because
  # some programs use a version scheme such as "009", such as usbutils.
  # ======================================================================= #
  splitted_last_part = splitted.last
  if splitted_last_part
    if splitted_last_part.start_with? '0'
      new_number = splitted_last_part.to_i + 1
      last_part  = new_number.to_s.rjust(splitted_last_part.to_s.size,'0')
    else
      last_part  = splitted_last_part.to_i + 1 # Increment the last part here.
    end
  else
    e 'A '+steelblue('nil value')+
      ' occurred so something must have went wrong.'
    pp splitted
  end
  splitted[-1]    = last_part.to_s
  minor_increment = splitted.join('.')
  url_for_minor_version = i.gsub(/#{original_version}/, minor_increment)
  try_this_URL(url_for_minor_version)
  # ======================================================================= #
  # === Next query whether the remote file exists
  #
  # Up until November 2020, we always relied on "wget" for this, but
  # since as of the 09.11.2020, we will also allow the use of curl
  # instead of wget. The reason for this was that "wget --spider" does
  # not always seem to work reliably well. In fact, that was the
  # reason why support for "curl" was added.
  #
  # Wget will query whether the remote file exists or whether it does
  # not.
  # ======================================================================= #
  case @use_this_program_to_query_whether_the_remote_URL_exists
  # ======================================================================= #
  # === :wget
  # ======================================================================= #
  when :wget
    if Object.const_defined? :Wget
      does_it_exist = Wget.check_if_remote_file_exists(url_for_minor_version)
      if does_it_exist # Minor increment exist, download it.
        register_and_install_this_program(url_for_minor_version)
      else
        e 'There was '+seagreen('no minor release')+' for `'+
          sfancy(url_for_minor_version)+'`.'
      end
    else
      report_that_wget_is_missing_then_exit
    end
  # ======================================================================= #
  # === :curl
  # ======================================================================= #
  when :curl
    cmd = "curl -Is #{url_for_minor_version}"
    result = `#{cmd}`
    does_it_exist = false
    if result.include? "302 Found\r\n"
      does_it_exist = true
    end
    if does_it_exist # Minor increment exist, download it.
      register_and_install_this_program(url_for_minor_version)
    else
      e 'There was '+seagreen('no minor release')+' for `'+
        sfancy(url_for_minor_version)+'`.'
    end
  end
  # ======================================================================= #
  # Check for another minor-version again.
  # ======================================================================= #
  last_part       = splitted.last.to_i + 1 # Increment the last part here again.
  splitted[-1]    = last_part.to_s
  minor_increment = splitted.join('.')
  url_for_minor_version = i.gsub(/#{original_version}/, minor_increment)
  try_this_URL(url_for_minor_version)
  # ======================================================================= #
  # === Query via Wget whether a remote file exists
  # ======================================================================= #
  if Object.const_defined? :Wget
    does_it_exist = Wget.check_if_remote_file_exists(url_for_minor_version)
    if does_it_exist # Minor increment exist, download it.
      register_and_install_this_program(url_for_minor_version)
    else
      e "There was #{seagreen('no minor release')} for `"\
        "#{sfancy(url_for_minor_version)}`."
    end
  else
    report_that_wget_is_missing_then_exit
  end
  # ======================================================================= #
  # === Check the subversion next, which is simply a '.1' added.
  # ======================================================================= #
  splitted = (original_version+'.1').split('.')
  url_for_subversion = splitted.join('.')
  url_for_subversion = i.gsub(/#{original_version}/, url_for_subversion)
  try_this_URL(url_for_subversion)
  subversion_version_exists = Wget.check_if_remote_file_exists(url_for_subversion)
  if subversion_version_exists
    register_and_install_this_program(url_for_subversion)
  else
    e 'There was '+seagreen('no subversion release')+
      ' release for '+sfancy(url_for_subversion)+'.'
  end
  # ======================================================================= #
  # === Middle Version Check
  #
  # Next check for the middle version part.
  # ======================================================================= #
  splitted     = original_version.split('.')
  splitted[1]  = (splitted[1].to_i + 1).to_s
  splitted[-1] = '0' # Last bit is 0.
  middle_increment = splitted.join('.')
  url_for_middle_version = i.gsub(/#{original_version}/, middle_increment)
  _ = "/#{original_split[0]}.#{original_split[1]}/"
  if url_for_middle_version.include? _ # Then apply a .gsub()
    url_for_middle_version.gsub!(/#{_}/,"/#{splitted[0]}.#{splitted[1]}/")
  end
  try_this_URL(url_for_middle_version)
  middle_version_exists = Wget.check_if_remote_file_exists(url_for_middle_version)
  if middle_version_exists
    register_and_install_this_program(url_for_middle_version)
  else
    e 'There was '+seagreen('no middle release')+
      ' release for '+sfancy(url_for_middle_version)+'.'
  end
  # ======================================================================= #
  # === Major Version Check
  #
  # Next check for the middle version part.
  # ======================================================================= #
  splitted = original_version.split('.')
  splitted[0]  = splitted[0].to_i + 1
  splitted[1]  = '0' # Middle bit is now 0 as well.
  splitted[-1] = '0' # Last bit is 0.
  major_increment = splitted.join('.')
  url_for_major_version = i.gsub(/#{original_version}/, major_increment)
  _ = "/#{original_split[0]}.#{original_split[1]}/"
  if url_for_major_version.include? _ # Then apply a .gsub()
    url_for_major_version.gsub!(/#{_}/,"/#{splitted[0]}.#{splitted[1]}/")
  end
  try_this_URL(url_for_major_version)
  major_version_exists = Wget.check_if_remote_file_exists(url_for_major_version)
  if major_version_exists
    register_and_install_this_program(url_for_major_version)
  else
    e "There was #{seagreen('no major release')} for "\
      "#{sfancy(url_for_major_version)}."
  end
end
check_for_missing_homepage_entry() click to toggle source
#

check_for_missing_homepage_entry

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 299
def check_for_missing_homepage_entry
  homepage = @dataset.homepage?.to_s
  if homepage.empty?
    if is_on_roebe?
      # =================================================================== #
      # Only roebe-systems get the following extra notifications.
      # =================================================================== #
      e "The program `#{sfancy(short_name?)}` has no "\
        "#{orange('homepage: entry')}. Consider adding one."
    end
  end
end
dataset?() click to toggle source
#

dataset?

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 322
def dataset?
  @dataset
end
determine_dataset( i = input? ) click to toggle source
#

determine_dataset

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 371
def determine_dataset(
    i = input?
  )
  @dataset = RBT::Cookbooks::SanitizeCookbook.new(i) { :fast }
  check_for_missing_homepage_entry
end
determine_whether_the_program_exists_or_not() click to toggle source
#

determine_whether_the_program_exists_or_not

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 348
def determine_whether_the_program_exists_or_not
  _ = program_name?
  # ======================================================================= #
  # === try_to_update_this_program binutils
  # ======================================================================= #
  if RBT.does_include? _
    e 'The program '+sfancy(_)+' is included. '+
      steelblue('This class can thus proceed. ')+
      gold(
        cheering_ascii_person
      )
    determine_dataset(_)
    assign_url_to_dataset_url(dataset?)
    check_for_incremented_remote_versions # Here we check for different remote versions.
  else
    e "The program #{sfancy(_)} is #{swarn('NOT')} included. "\
      "Can not proceed."
  end
end
exit_program() click to toggle source
#

exit_program

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 274
def exit_program
  exit
end
input?() click to toggle source
#

input?

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 92
def input?
  @input
end
Also aliased as: program_name?
program_name?()
Alias for: input?
register_and_install_this_program( i, shall_we_exit = true ) click to toggle source
#

register_and_install_this_program

This method will delegate into class RBT::UpdateEntry for updating the specific program at hand.

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 332
def register_and_install_this_program(
    i, shall_we_exit = true
  )
  e 'We found a match towards the URL `'+simp(i)+'`.'
  # ======================================================================= #
  # Delegate towards class Cookbooks::UpdateEntry in this case.
  # ======================================================================= #
  RBT::UpdateEntry.new(i) {{
    repackage_into_tar_xz_format: @try_to_repackage_into_tar_xz_format
  }}
  exit_program if shall_we_exit
end
report_that_wget_is_missing_then_exit() click to toggle source
#

report_that_wget_is_missing_then_exit

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 281
def report_that_wget_is_missing_then_exit
  e 'Wget is unavailable. Please install it via:'
  e
  e '  gem install wget'
  e
  exit
end
report_the_main_namespace() click to toggle source
#

report_the_main_namespace

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 381
def report_the_main_namespace
  opnn { :no_trailing }
  e
  e
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 46
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === try_to_repackage_into_tar_xz_format
  # ======================================================================= #
  @try_to_repackage_into_tar_xz_format = TRY_TO_REPACKAGE_INTO_TAR_XZ_FORMAT
  # ======================================================================= #
  # === @use_this_program_to_query_whether_the_remote_URL_exists
  #
  # The following variable can be either :wget or :curl. Since as of
  # November 2020, the default is :curl.
  # ======================================================================= #
  @use_this_program_to_query_whether_the_remote_URL_exists = :curl
  try_to_require_wget
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 398
def run
  report_the_main_namespace
  determine_whether_the_program_exists_or_not
end
set_input( i = DEFAULT_PROGRAM ) click to toggle source
#

set_input

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 66
def set_input(
    i = DEFAULT_PROGRAM
  )
  i = i.first if i.is_a? Array
  if i.nil? # If the user did not provide any input-argument here.
    if return_pwd.include? archive_dir?
      i = Dir['*'].first # Just pick the first entry in this case.
      if i
        if i.include? '-'
          i = ProgramInformation.return_name(i)
        end 
      else
        e 'There does not appear to be any file in that directory.'
        i = nil
      end
    else
      i = DEFAULT_PROGRAM
    end
  end
  i = i.to_s.dup.delete('-_').downcase
  @input = i
end
short_name?() click to toggle source
#

short_name?

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 315
def short_name?
  @dataset.short_name?
end
try_this_URL(this_URL) click to toggle source
#

try_this_URL

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 390
def try_this_URL(this_URL)
  e "Now trying the following URL: "\
    "#{sfancy(this_URL)}"
end
url?() click to toggle source
#

url?

#
# File lib/rbt/utility_scripts/increment_program_version/increment_program_version.rb, line 267
def url?
  @url
end