class RBT::Cookbooks::ScanForIncompleteLastUpdateEntries
Constants
- AUTOMATICALLY_FIX_INCOMPLETE_ENTRIES
#¶ ↑
AUTOMATICALLY_FIX_INCOMPLETE_ENTRIES
¶ ↑If this constant is set to true then entries which are incomplete will be automatically fixed. This works only for simple cases.
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
Public Instance Methods
all_programs?()
click to toggle source
autofix_this_file(i)
click to toggle source
#¶ ↑
autofix_this_file
(autofix tag)¶ ↑
This method will first do a backup of the old file, before trying to fix the existing file.
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 226 def autofix_this_file(i) i = i.dup if File.exist? i backup_this_file(i) dataset = File.readlines(i) dataset.map! {|line| if line.include? ' last_update: ' line = prepend_first_day_in_the_month_to_this_line(line) end line } @n_autocorrections += 1 opnn; e 'Autocorrecting the file at `'+sfile(i)+'`.' write_what_into(dataset.join, i) # ===================================================================== # # And then also autofix this on my home-system. # ===================================================================== # if is_on_roebe? i = RUBY_SRC_DIR_RBT_YAML+'individual_cookbooks/'+File.basename(i) opnn; e 'Autocorrecting the file at `'+sfile(i)+'`.' write_what_into(dataset.join, i) end else opnn; no_such_file_exists(i) end end
automatically_fix_incomplete_entries?()
click to toggle source
#¶ ↑
automatically_fix_incomplete_entries?¶ ↑
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 117 def automatically_fix_incomplete_entries? @automatically_fix_incomplete_entries end
Also aliased as: fix_incomplete_entries?
backup_this_file(from_here)
click to toggle source
#¶ ↑
backup_this_file
¶ ↑
This will store into the directory '/Depot/Temp/BackupForCookbooks/'.
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 212 def backup_this_file(from_here) _ = temp_dir?+'BackupForCookbooks/' mkdir(_) unless Dir.exist? _ to_there = _+File.basename(from_here) opnn; e 'We will backup the file '+sfile(from_here)+' to `'+sfile(to_there)+'`.' copy_file(from_here, to_there) end
consider_reporting_how_many_autocorrections_have_been_done()
click to toggle source
#¶ ↑
consider_reporting_how_many_autocorrections_have_been_done
¶ ↑
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 263 def consider_reporting_how_many_autocorrections_have_been_done if @n_autocorrections > 0 opnn; e sfancy(@n_autocorrections.to_s)+' autocorrections have been performed.' end end
do_scan()
click to toggle source
#¶ ↑
do_scan
¶ ↑
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 166 def do_scan fix_incomplete_entries = fix_incomplete_entries? # ======================================================================= # # Iterate over all registered programs at hand. # ======================================================================= # all_programs?.each {|program| program = program.downcase _ = return_location_to_this_programs_yaml_file(program) if File.exist? _ # Ok, the file exists. begin dataset = YAML.load_file(_) rescue ArgumentError => error e 'An ArgumentError happened for the program `'+ sfancy(program.to_s)+'`.' pp error end hash = dataset[program.to_s] if hash if hash.has_key? 'last_update' last_update = hash['last_update'] splitted = last_update.split(' ') if splitted.size == 3 # Then all is fine. elsif splitted.size == 2 register_this_incomplete_entry(program, last_update) if fix_incomplete_entries autofix_this_file(_) end end else e "The hash has no key called #{simp('last_update')}." end else end else opnn; e 'The file at `'+sfile(_)+'` does not exist. Exiting now.' exit end } end
prepend_first_day_in_the_month_to_this_line(line)
click to toggle source
register_this_incomplete_entry( name_of_the_program, last_update_tag )
click to toggle source
report_how_many_programs_have_an_incomplete_last_update_entry()
click to toggle source
#¶ ↑
report_how_many_programs_have_an_incomplete_last_update_entry
¶ ↑
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 93 def report_how_many_programs_have_an_incomplete_last_update_entry opnn; e "We have a total of #{sfancy(results?.size.to_s)}"\ " programs with an incomplete #{swarn('last_update: entry')}." if results?.size == 0 opnn; e 'Excellent! No cookbook file has an incomplete' opnn; e "`#{simp('last_update')}` entry." e e 'The directory that we did check for this was:' e e ' '+sdir(RBT.individual_cookbooks_directory?) e end end
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 55 def reset super() @namespace = NAMESPACE @array_with_the_results = [] @automatically_fix_incomplete_entries = AUTOMATICALLY_FIX_INCOMPLETE_ENTRIES @n_autocorrections = 0 # How many autocorrections were done. end
results?()
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 272 def run check_against_menu do_scan # Do the scan part now. report_how_many_programs_have_an_incomplete_last_update_entry # We finally report how many "faulty" programs we have discovered. try_to_show_problematic_programs consider_reporting_how_many_autocorrections_have_been_done end
set_input(i = '')
click to toggle source
show_help()
click to toggle source
try_to_show_problematic_programs()
click to toggle source
#¶ ↑
try_to_show_problematic_programs
¶ ↑
#¶ ↑
# File lib/rbt/validation/scan_for_incomplete_last_update_entries.rb, line 153 def try_to_show_problematic_programs _ = results? unless _.empty? _.each {|this_program, last_update_entry| e 'Incomplete last_entry: '+slateblue(this_program)+ hotpink(" (#{last_update_entry})") } end end