class Cookbooks::CheckForBlfsUpdates

Constants

LIMIT_THE_AMOUNT_OF_PROGRAMS
#

LIMIT_THE_AMOUNT_OF_PROGRAMS

#
NAMESPACE
#

NAMESPACE

#
UPDATE_REGEX
#

UPDATE_REGEX

#
WORK_ON_N_PROGRAMS
#

WORK_ON_N_PROGRAMS

On how many programs we will work. This constant will only be honoured if the LIMIT_THE_AMOUNT_OF_PROGRAMS was set to true, though.

#

Public Class Methods

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

[]

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 264
def self.[](i = '')
  self.new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 49
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Public Instance Methods

blfs_url_for(i) click to toggle source
#

#blfs_url_for

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 120
def blfs_url_for(i)
  Cookbooks.return_blfs_page_of_this_program(i).to_s
end
colour_for_blfs_entries(i) click to toggle source
#

#colour_for_blfs_entries

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 142
def colour_for_blfs_entries(i)
  simp(i)
end
input?() click to toggle source
#

input?

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 106
def input?
  @input
end
menu(i) click to toggle source
#

menu (menu tag)

#
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 113
def opnn
  super(NAMESPACE)
end
remote_webpage?() click to toggle source
#

remote_webpage?

Query method over the remote BLFS webpage.

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 71
def remote_webpage?
  BLFS_CHANGELOG_WEBPAGE
end
Also aliased as: remote_website?
remote_website?()
Alias for: remote_webpage?
report_blfs_page_of_this_program(name_of_the_program) click to toggle source
#

#report_blfs_page_of_this_program

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 127
def report_blfs_page_of_this_program(name_of_the_program)
  _ = blfs_url_for(name_of_the_program)
  if _
    opnn; e 'The BLFS entry for '+sfancy(name_of_the_program)+
            ' can be found at `'+colour_for_blfs_entries(_)+'`.'
  else
    opnn; e 'The program '+sfancy(name_of_the_program)+
            ' does '+swarn('NOT')+' yet have a BLFS entry. '\
            'Please add one.'
  end
end
report_this_program(i) click to toggle source
#

#report_this_program

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 191
def report_this_program(i)
  ljust_value = 15
  # ======================================================================= #
  # Some entries may not have a version entry associated, such as
  # 'gconf".
  # ======================================================================= #
  if !does_the_cookbook_include_this_program?(i) and
     !i.include?('-')
    opnn; e 'A new program may have been added: '+sfancy(i)+N+
            (' ' * 32)+colour_for_blfs_entries(blfs_url_for(i))
  else
    unless i.include? '-'
      opnn; e 'The input `'+sfancy(i)+'` contains no - character. It '\
              'will thus'
      append_this = '-0.0.1'
      opnn; e 'be modified towards `'+sfancy(i+append_this)+'`.'
      i = i.dup
      i << append_this 
    end
    dataset_for_this_program = ProgramInformation.return_name_and_version(i, :downcase)
    name_of_the_program, remote_program_version = dataset_for_this_program
    remote_program_version.chop! if remote_program_version.end_with? '.'
    name_of_the_program.strip!
    name_of_the_program = correct_for_common_mistakes_in_program_names(
      name_of_the_program
    )
    if does_the_cookbook_include_this_program? name_of_the_program
      opnn; e 'The program '+sfancy(name_of_the_program.ljust(ljust_value))+
              ' is included.'
      local_version = return_local_version_of_this_program(name_of_the_program)
      if local_version.to_s == remote_program_version.to_s
        opnn; e "The local dataset is already up to date. Program "\
                "version is: #{sfancy(remote_program_version)}"
      else
        remote_program_version.delete!('v')
        # =================================================================== #
        # In this case, the remote version is not the same as the local
        # version. Report this.
        # =================================================================== #
        gem_version_of_the_remote_program = gem_version(remote_program_version)
        gem_version_of_the_local_program  = gem_version(local_version)
        if gem_version_of_the_remote_program and
           gem_version_of_the_local_program
          if gem_version_of_the_remote_program > gem_version_of_the_local_program
            opnn; e firebrick('The BLFS homepage contains a version that is '\
                    'more up to date.')
            opnn; e powderblue('Local version: ')+
                    sfancy(local_version.to_s)+powderblue(', BLFS version: ')+
                    sfancy(remote_program_version)+powderblue(')')
          else
            opnn; e powderblue('Local version: ')+
                    sfancy(local_version.to_s)+powderblue(', BLFS version: ')+
                    sfancy(remote_program_version)+powderblue(') Seems '\
                    'as if the local version is more up to date than the '\
                    'BLFS version.')
          end
        else
          opnn; e 'Something went wrong with these two version '\
                  'strings ('+sfancy(remote_program_version.to_s)+
                  ', '+sfancy(local_version)+').'
        end
      end
      report_blfs_page_of_this_program(name_of_the_program)
    else
      opnn; e 'The program '+sfancy(name_of_the_program.ljust(ljust_value))+
              ' is '+swarn('NOT')+' included.'
    end
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method Cookbooks::CheckForRemoteWebpages#reset
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 61
def reset
  super()
  @work_on_n_programs = WORK_ON_N_PROGRAMS
end
return_blfs_page_of_this_program(i)
Alias for: blfs_url_for
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 149
def run
  report_the_remote_webpage
  obtain_dataset_from_the_remote_webpage
  array = [] # Our main dataset.
  # ======================================================================= #
  # Check for "Add xyz" first.
  # ======================================================================= #
  use_this_regex = /- Adde?d? ([A-Za-z]{1,14}[0-9]{0,1})/ # See: http://rubular.com/r/gl1vSycqVf
  array << @dataset.scan(use_this_regex).flatten.reject {|entry|
    (entry == '-') or (entry == ' ')
  }
  array.flatten!
  # ======================================================================= #
  # The next regex checks for "Update to" entries. However had, the
  # BLFS homepage also has other formats such as
  # "[renodr] - Add libidn2. Fixes #9045.
  # ======================================================================= #
  use_this_regex = UPDATE_REGEX
  matches = @dataset.scan(use_this_regex).map {|entry| entry.join }.flatten
  array << matches
  array.flatten!
  array.compact!
  array.map! {|line| line.strip.downcase } # Keep it downcased as well.
  if LIMIT_THE_AMOUNT_OF_PROGRAMS
    # ===================================================================== #
    # Right now we hardcode-limit this to 15 entries.
    # ===================================================================== #
    n_programs_in_total = @work_on_n_programs
    array = array[0..(n_programs_in_total-1)]
  end
  array.each_with_index {|entry, index| index += 1
    # ===================================================================== #
    # First show the colourized index.
    # ===================================================================== #
    e ; e '('+plum(index.to_s)+') '; e
    report_this_program(entry.strip)
  }
end
set_input(i = '') click to toggle source
#

#set_input

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 78
def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
  menu(@input)
end
set_work_on_n_programs(i) click to toggle source
#

#set_work_on_n_programs

#
# File lib/cookbooks/check_for_updates/check_for_blfs_updates.rb, line 88
def set_work_on_n_programs(i)
  i = i.to_s.delete('-')
  @work_on_n_programs = i.to_i
end