class RBT::Action::RemoveOutdatedArchives
Public Class Methods
[](i = ARGV)
click to toggle source
new( i = ARGV, run_already = true, &block )
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/actions/individual_actions/remove_outdated_archives/remove_outdated_archives.rb, line 48 def initialize( i = ARGV, run_already = true, &block ) reset set_commandline_arguments(i) case run_already # ======================================================================= # # === :do_not_run_yet # ======================================================================= # when :do_not_run_yet run_already = false end 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/actions/individual_actions/remove_outdated_archives/remove_outdated_archives.rb, line 246 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
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/actions/individual_actions/remove_outdated_archives/remove_outdated_archives.rb, line 255 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)+ rev+' files were removed.' opne "#{rev}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/actions/individual_actions/remove_outdated_archives/remove_outdated_archives.rb, line 329 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 "#{rev}The entry `#{sfile(i)}#{rev}` 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::Action#reset
# File lib/rbt/actions/individual_actions/remove_outdated_archives/remove_outdated_archives.rb, line 68 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
work_on_which_programs?()
click to toggle source
work_through_the_programs( i = work_on_which_programs? )
click to toggle source
#¶ ↑
work_through_the_programs
¶ ↑
This is the method that will iterate over all available program.
#¶ ↑
# File lib/rbt/actions/individual_actions/remove_outdated_archives/remove_outdated_archives.rb, line 281 def work_through_the_programs( i = work_on_which_programs? ) if i.empty? opne "#{rev}No program was given to remove its outdated archive(s)." else i.each {|this_program| this_directory = "#{src_dir?}#{this_program}/" opne "#{rev}Working on the directory #{sdir(this_directory)} #{rev}next:" # =================================================================== # # Obtain all entries of that directory next, in a sorted manner. This # may yield wrong results though, such as: # # kcontacts-5.114.0.tar.xz # kcontacts-5.93.0.tar.xz # # Applying .max there yields the wrong result. # =================================================================== # use_this_regex = /\d{1,8}\.?\d{0,12}\.?\d{0,12}/ # See: https://rubular.com/r/ypXFhDrhYI4NEN files_in_that_directory = Dir[ this_directory+'*'+@look_only_for_these_archive_types ].sort_by {|entry| entry = remove_archive_at_the_end(entry) extracted_number = entry.scan(use_this_regex).flatten if extracted_number.respond_to?(:first) extracted_number = extracted_number.first end Gem::Version.new(extracted_number) # Make use of Gem::Version to get the "real" version. }.reverse # =================================================================== # # Next, determine the highest entry that will be kept. # =================================================================== # highest_entry = files_in_that_directory[0] # .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