class Cookbooks::DownloadAllSourceArchives

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

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

[]

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 267
def self.[](i = '')
  self.new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 44
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(commandline_arguments)
  run if run_already
end

Public Instance Methods

cd_to_the_archive_directory() click to toggle source
#

#cd_to_the_archive_directory

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 201
def cd_to_the_archive_directory
  cd @archive_directory, :be_quiet
end
commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 95
def commandline_arguments?
  @commandline_arguments
end
Also aliased as: input?
consider_downloading_this_program(i) click to toggle source
#

#consider_downloading_this_program

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 164
def consider_downloading_this_program(i)
  unless Cookbooks.const_defined? :Cookbook
    require 'cookbooks/class/class.rb'
  end
  cd_to_the_archive_directory # Always enter the archive directory.
  # ======================================================================= #
  # Next, check whether the program exists.
  # ======================================================================= #
  _ = Cookbooks::Cookbook.new(i) { :bypass_menu_check }
  program_path = _.program_path?
  remote_url   = _.remote_url?
  unless File.exist? program_path
    this_directory = "#{@archive_directory}#{i}/"
    unless File.directory? this_directory
      opnn; e "Creating the directory `#{sdir(this_directory)}` next."
      mkdir this_directory
    end
    cd this_directory
    unless File.exist? program_path
      download(remote_url)
      opnn; e "Next downloading `#{simp(remote_url)}`."
    end
  end
end
dataset?() click to toggle source
#

dataset?

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 79
def dataset?
  @available_programs
end
download(i) click to toggle source
#

download

The download-functionality requires wget right now.

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 194
def download(i)
  esystem "wget #{i}"
end
input?()
menu(i = commandline_arguments?) click to toggle source
#

menu (menu tag)

#
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 208
def opnn
  super(NAMESPACE)
end
process_the_programs_one_after_the_other( i = @available_programs ) click to toggle source
#

#process_the_programs_one_after_the_other

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 247
def process_the_programs_one_after_the_other(
    i = @available_programs
  )
  i.each {|this_program|
    consider_downloading_this_program(this_program)
  }
end
register_this_tag(i) click to toggle source
#

#register_this_tag

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 127
def register_this_tag(i)
  @tag = i
end
report_the_archive_directory_in_use() click to toggle source
#

#report_the_archive_directory_in_use

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 134
def report_the_archive_directory_in_use
  if @tag
    opnn; e "All registered programs with the tag #{sfancy(@tag)}"\
            " will be downloaded into the directory:"
  else
    opnn; e 'All registered programs will be downloaded into the directory:'
  end
  e
  e sfile("  #{@archive_directory}")
  e
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method Cookbooks::Base#reset
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 56
def reset
  super()
  @tag = nil
  @archive_directory = source_directory?
  @available_programs = available_programs? # <- Must come before the menu() call.
end
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 258
def run
  menu
  report_the_archive_directory_in_use
  process_the_programs_one_after_the_other
end
select_only_these_tags(i) click to toggle source
#

#select_only_these_tags

To invoke this method, try:

download_all_source_archives --tags=plasma
#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 218
def select_only_these_tags(i)
  # ======================================================================= #
  # Ok, the user provided a tag, so we have to selectively filter for
  # programs that include only that tag. For now, we only use the
  # expanded cookbook dataset for this. Of course we must check whether
  # this directory exists or whether it does not.
  # ======================================================================= #
  if File.directory? DIRECTORY_EXPANDED_COOKBOOKS
    entries = Dir[DIRECTORY_EXPANDED_COOKBOOKS+'*.yml']
    results = entries.map {|entry|
      YAML.load_file(entry)
    }.select {|entry| entry['tags'].include? i }
    results.map! {|entry| entry['real_short_name'] }
    return results
  else
    opnn; e "No directory called #{sdir(DIRECTORY_EXPANDED_COOKBOOKS)} exists."
    opnn; e 'This class currently requires this directory to work.'
    opnn; e 'If you wish to auto-generate the directory and the files or that'
    opnn; e 'directory, then issue this command:'
    e
    e sfancy('  cookbooks --expand')
    e
    exit
  end
end
set_commandline_arguments(i = '') click to toggle source
#

#set_commandline_arguments

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 86
def set_commandline_arguments(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @commandline_arguments = i
end
set_use_these_cookbooks(i) click to toggle source
#

#set_use_these_cookbooks

The input to this method should be an Array.

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 68
def set_use_these_cookbooks(i)
  if i.is_a? Array
    i.flatten!
    i.sort!
  end
  @available_programs = i
end
show_help() click to toggle source
#

#show_help (help tag)

#
# File lib/cookbooks/utility_scripts/download_all_source_archives.rb, line 149
def show_help
  opnn; e 'This class allows you to download source archives.'
  opnn; e 'You can also selectively download only certain entries, in'
  opnn; e 'particular those who have registered tags.'
  e
  opnn; e 'For example, if you wish to download all KDE-plasma related entries'
  opnn; e 'then you can issue the following command:'
  e
  opnn; e sfancy('  download_all_source_archives --tags=plasma')
  e
end