class RBT::RemoveOutdatedArchives

Public Class Methods

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

RBT::RemoveOutdatedArchives[]

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 332
def self.[](i = ARGV)
  new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 47
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

add(i) click to toggle source
#

add (add tag)

This method will simply append (aka add) to the main Array of this class.

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 239
def add(i)
  @array_work_on_these_programs << i
  @array_work_on_these_programs.flatten!
  @array_work_on_these_programs.compact!
end
format_type?() click to toggle source
#

format_type?

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 92
def format_type?
  @look_only_for_these_archive_types
end
menu( i = commandline_arguments? ) click to toggle source
#

menu (menu tag)

#
notify_the_user_as_to_how_many_files_were_removed() click to toggle source
#

notify_the_user_as_to_how_many_files_were_removed

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 248
def notify_the_user_as_to_how_many_files_were_removed
  if @n_files_were_removed > 0
    opne 'A total of '+sfancy(@n_files_were_removed.to_s)+' files were removed.'
    opne 'The total filesize of these archives was: '+
            sfancy(
              @total_file_size.to_s
            )+
            tomato('B')+' '+
            sfancy(
              (@total_file_size.to_f / (1000.0 * 1000.0)).round(1)
            )+
            tomato('MB')
  end
end
purge_these_entries(i) click to toggle source
#

purge_these_entries (purge tag)

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 307
def purge_these_entries(i)
  if i.is_a? Array
    i.flatten.each {|entry| purge_these_entries(entry) }
  else
    if File.file?(i) and i.end_with?(format_type?)
      opne "The entry `#{sfile(i)}` will be removed next."
      @n_files_were_removed += 1
      @total_file_size += File.size(i)
      remove_file(i)
    end
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 61
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @look_only_for_these_archive_types
  #
  # The next variable determines which archive types we are looking
  # for.
  # ======================================================================= #
  @look_only_for_these_archive_types = '.tar.xz'
  # ======================================================================= #
  # === @array_work_on_these_programs
  #
  # This Array keeps track on the programs that will be handled by this
  # class. It will be empty on startup, so as to require the user to
  # tell this class which programs it ought to handle.
  # ======================================================================= #
  @array_work_on_these_programs = []
  # ======================================================================= #
  # === @n_files_were_removed
  # ======================================================================= #
  @n_files_were_removed = 0
  # ======================================================================= #
  # === @total_file_size
  # ======================================================================= #
  @total_file_size = 0
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 323
def run
  menu
  work_through_the_programs
  notify_the_user_as_to_how_many_files_were_removed
end
work_on_which_programs?() click to toggle source
#

work_on_which_programs?

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 266
def work_on_which_programs?
  @array_work_on_these_programs
end
work_through_the_programs( i = work_on_which_programs? ) click to toggle source
#

work_through_the_programs

#
# File lib/rbt/utility_scripts/remove_outdated_archives.rb, line 273
def work_through_the_programs(
    i = work_on_which_programs?
  )
  if i.empty?
    opne 'No program was given to remove its outdated archive(s).'
  else
    i.each {|this_program|
      this_directory = "#{src_dir?}#{this_program}/"
      opne "Working on the directory #{sdir(this_directory)} next:"
      # =================================================================== #
      # Obtain all entries of that directory:
      # =================================================================== #
      files_in_that_directory = Dir[
        this_directory+'*'+@look_only_for_these_archive_types
      ].sort
      # =================================================================== #
      # Next, determine the highest entry that will be kept.
      # =================================================================== #
      highest_entry = files_in_that_directory.max
      # =================================================================== #
      # The next variable denotes which entries will be purged (aka
      # removed).
      # =================================================================== #
      array_of_entries_that_are_to_be_purged = files_in_that_directory.reject {|entry|
        entry.include? highest_entry
      }
      purge_these_entries(array_of_entries_that_are_to_be_purged)
    }
  end
end