class RBT::Linux::Slackware::FilelistParser

Public Class Methods

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

RBT::Linux::Slackware::FilelistParser[]

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 220
def self.[](i = nil)
  new(i)
end
new( this_url = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 34
def initialize(
    this_url     = ARGV,
    run_already  = true
  )
  reset
  set_use_this_url(this_url)
  run if run_already
end

Public Instance Methods

main_url?()
Alias for: use_this_url?
obtain_the_remote_dataset() click to toggle source
#

obtain_the_remote_dataset

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 84
def obtain_the_remote_dataset
  # ======================================================================= #
  # We will first try open-uri, and if that fails with an openssl error
  # then we will try the second version.
  # ======================================================================= #
  begin
    dataset = URI.open(main_url?).read
  rescue OpenSSL::SSL::SSLError
    e 'Trying to '+crimson('avoid')+' '+royalblue('OpenSSL')+
      ' as we have just recieved '\
      'a '+crimson('OpenSSL::SSL::SSLError')+'.'
    require 'open-uri'
    require 'openssl'
    require 'json'
    request_uri = URI.parse(main_url?)
    result = open(
      request_uri, { ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }
    )
    dataset = result.readlines.join
  end
  @dataset = dataset
end
register_this_program(i) click to toggle source
#

register_this_program (add tag)

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 187
def register_this_program(i)
  if i
    @array_registered_programs << i unless i.to_s.empty?
  end
end
remote_url?()
Alias for: use_this_url?
report_information_about( i = @dataset ) click to toggle source
#

report_information_about

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 110
def report_information_about(
    i = @dataset
  )
  if i.is_a? Array
    e 'A total of '+royalblue(i.size.to_s)+' programs are '\
      'available on the remote'
    e 'url '+orange(remote_url?)+'.'
    e
    e 'Next, these programs will be shown in two entries per row:'
    e
    i.sort.each {|original_line|
      line = remove_archive_at_the_end(original_line)
      if line.include?('-1alien')
        line.sub!(/-1alien/, '')
      end
      if line.include?('-2alien')
        line.sub!(/-2alien/, '')
      end
      if line.include?('-3alien')
        line.sub!(/-3alien/, '')
      end
      if line.include?('-4alien')
        line.sub!(/-4alien/, '')
      end
      if line.include?('-5alien')
        line.sub!(/-5alien/, '')
      end
      if line.include?('-6alien')
        line.sub!(/-6alien/, '')
      end
      if line.include?('-x86_64')
        line.sub!(/-x86_64/, '')
      end
      if line.include?('-noarch-2alien')
        line.sub!(/-noarch-2alien/, '')
      end
      if line.include?('-noarch')
        line.sub!(/-noarch/, '')
      end
      assumed_program_name    = ProgramInformation.return_program_name(line)
      assumed_program_version = ProgramInformation.return_program_version(line)
      unless assumed_program_name.nil? or assumed_program_version.nil?
        assumedn_program_name.downcase!
        e '  '+royalblue(line.ljust(55))+
          steelblue(
            " [#{assumed_program_name}, #{assumed_program_version}]"
          )
        register_this_program(assumed_program_name)
      end
    }
    report_whether_these_programs_are_all_registered_in_the_rbt_project
  end
end
report_whether_these_programs_are_all_registered_in_the_rbt_project( i = @array_registered_programs ) click to toggle source
#

report_whether_these_programs_are_all_registered_in_the_rbt_project

This method will report whether all the discovered programs are registered in the RBT project.

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 170
def report_whether_these_programs_are_all_registered_in_the_rbt_project(
    i = @array_registered_programs
  )
  if @also_determine_whether_the_programs_are_registered_in_the_rbt_project
    i.each {|entry|
      if is_this_program_registered?(entry)
        # In this case all is fine.
      else
        e 'The program '+royalblue(entry)+' is '+crimson('not')+' registered.'
      end
    }
  end
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/linux/slackware/filelist_parser.rb, line 46
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @dataset
  # ======================================================================= #
  @dataset = nil
  # ======================================================================= #
  # === @array_registered_programs
  # ======================================================================= #
  @array_registered_programs = []
  # ======================================================================= #
  # === @also_determine_whether_the_programs_are_registered_in_the_rbt_project
  # ======================================================================= #
  @also_determine_whether_the_programs_are_registered_in_the_rbt_project = true
end
run() click to toggle source
#

run

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 196
def run
  obtain_the_remote_dataset
  if @dataset
    # ===================================================================== #
    # In this case we assume that we have found a result. We will select
    # all entries that have .txt as part of their name.
    #
    # Example:
    #
    #   ./kde/plasma/kgamma5-5.16.0-x86_64-1alien.txz
    #
    # ===================================================================== #
    @dataset = @dataset.split("\n").select {|line| line.strip.end_with? '.txz' }.map {|line|
      File.basename(line)
    }
    report_information_about(@dataset)
  else
    opne 'No dataset has been found.'
  end
end
set_use_this_url(i) click to toggle source
#

set_use_this_url

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 66
def set_use_this_url(i)
  if i.is_a? Array
    i = i.first
  end
  @use_this_url = i
end
use_this_url?() click to toggle source
#

use_this_url?

#
# File lib/rbt/linux/slackware/filelist_parser.rb, line 76
def use_this_url?
  @use_this_url
end
Also aliased as: main_url?, remote_url?