class Cookbooks::Base
Constants
- KONSOLE
#¶ ↑
KONSOLE¶ ↑
#¶ ↑
Public Class Methods
Public Instance Methods
#¶ ↑
CookbookDirectory?¶ ↑
The name is not pretty, but we use it for now. Perhaps at a later time we will change it to “cookbook_directory?” or something like that, but presently (Jan 2018) this conflicts with an alias. We may have to get rid of the alias, and also change all the code that uses that alias.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 525 def CookbookDirectory? temp_directory?+'CookbookDirectory/' end
#¶ ↑
#available_programs¶ ↑
Feedback which programs are available, in sorted Array form.
#¶ ↑
# File lib/cookbooks/base/base.rb, line 42 def available_programs? Cookbooks.available_cookbooks? end
#¶ ↑
#change_directory¶ ↑
Use this to change directory.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 427 def change_directory(i, be_verbose = true) case be_verbose when :be_quiet be_verbose = false end if be_verbose e 'Changing into the directory `'+sdir(i.to_s)+'` now.' end FileUtils.cd(i) end
#¶ ↑
#chop_off_archive¶ ↑
Remove the trailing part of an archive. This isn't very sophisticated but it “just works” (TM).
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 238 def chop_off_archive(i) if i.include? '#' # Chop off at '#' characters. i = i[0..(i.index('#')-1)] end i.sub!(/\.source$/,'') if i.include? 'source' i.sub!(/-stable$/,'') if i.end_with? '-stable' i = i.sub(/&type=zip$/,''). sub(/\.lz$/,''). sub(/\.gz$/,''). sub(/\.xz$/,''). sub(/\.bz2$/,''). sub(/\.tar$/,''). sub(/\.zip$/,''). sub(/\.js$/,'') return i end
#¶ ↑
cliner¶ ↑
#¶ ↑
# File lib/cookbooks/base/cliner.rb, line 14 def cliner( i = '=', use_this_colour = nil ) result = ''.dup append = ''.dup if use_colours? if use_this_colour if i.is_a? Symbol use_this_colour = Colours::Konsole.send(i) end result << use_this_colour append << Colours.rev end end if i.is_a? Symbol i = '=' # Restore to the default here. end result << (i * 80) result << append unless append.empty? puts result if block_given? yield cliner('=', use_this_colour) end end
#¶ ↑
cookbook_files?¶ ↑
This method will return all available cookbook files in an Array.
Usage example:
cookbook_files?(:show_full_path)
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 220 def cookbook_files?(show_how = :show_only_name) result = Dir[individual_cookbooks_directory?+'*yml'].sort case show_how when :show_only_name # In this case, show only the name. result.map! {|entry| File.basename(entry).gsub( File.extname(entry), '' ) } when :show_full_path # In this case make no modifications. end return result end
#¶ ↑
#copy_file (copy file, cp tag, copy tag)¶ ↑
Use this method to copy a file.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 117 def copy_file(file, where_to) FileUtils.cp(file, where_to) end
#¶ ↑
#create_directory¶ ↑
Consistently use this when you want to create a directory for the Cookbooks-Project.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 77 def create_directory(i) unless File.directory? i opnn; e 'Creating directory `'+sdir(i)+'` now.' FileUtils.mkdir_p(i) end end
#¶ ↑
#determine_archive_type¶ ↑
We determine the archive type with this method, which really is a simplification.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 198 def determine_archive_type(i) _ = '' if i.include? '.tar.xz' _ = '.tar.xz' elsif i.include? '.tar.gz' _ = '.tar.gz' elsif i.include? '.tar.bz2' _ = '.tar.bz2' else # else use the extension name. _ = File.extname(i) end return _ end
#¶ ↑
#disable_colours¶ ↑
Use this method if you wish to disable colours. Invoke it only when you really do wish to disable the colours.
#¶ ↑
# File lib/cookbooks/base/colours.rb, line 38 def disable_colours ::Cookbooks.disable_colours end
#¶ ↑
display_md5sum?¶ ↑
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 357 def display_md5sum? ::Cookbooks.display_md5sum? end
#¶ ↑
expanded_cookbooks_directory_exists?¶ ↑
This method will try if the expanded-cookbooks directory exists, and false otherwise.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 512 def expanded_cookbooks_directory_exists? File.directory? temp_directory?+'CookbookDirectory/expanded_cookbooks/' end
#¶ ↑
#gem_version¶ ↑
This method is a wrapper over Gem::Version.new()
The reason as to why this resides in a method is so that we can do some input-sanitizing, and easier rescue, if this is necessary one day.
#¶ ↑
# File lib/cookbooks/base/base.rb, line 110 def gem_version(i) i = i.to_s.delete('vr') begin if i =~ /\d+/ # Must have at the least one number. return Gem::Version.new(i) end rescue ArgumentError => error opnn; e 'An error occurred in gem_version()' pp error end nil # Indicate "failure" aka unable to parse this version. end
#¶ ↑
is_this_program_included?¶ ↑
#¶ ↑
# File lib/cookbooks/base/base.rb, line 92 def is_this_program_included?(i) ::Cookbooks.program_is_included?(i) end
#¶ ↑
on_roebe?¶ ↑
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 276 def on_roebe? ::Cookbooks.on_roebe? end
#¶ ↑
programs_dir?¶ ↑
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 392 def programs_dir? ::Cookbooks.programs_directory?.dup end
#¶ ↑
#remove_double_slashes (rds tag)¶ ↑
Replace // with / in a given string.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 99 def remove_double_slashes(i) i.squeeze '/' end
#¶ ↑
#remove_file (remove tag)¶ ↑
Use this method whenever you wish to remove a file.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 134 def remove_file(i) if File.exist? i File.delete(i) if File.file? i end end
#¶ ↑
#remove_file_extension¶ ↑
This method will try to remove anything we declare to be an improper file extension. We do this by delegating towards class RemoveFileSuffix, an external dependency.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 336 def remove_file_extension(i, also_remove_the_basename = true) case also_remove_the_basename when :do_not_strip_anything also_remove_the_basename = false end if also_remove_the_basename i = File.basename(i) end if i.end_with? '.src' i[-4,4] = '' elsif i.end_with? '-src' i[-4,4] = '' end i = remove_unnecessary_data_from_url(i.to_s.dup) ::Cookbooks.remove_file_suffix(i) # Always return it. end
#¶ ↑
#remove_unnecessary_data_from_url¶ ↑
This method removes some meaningless information that can be found in some URLs.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 173 def remove_unnecessary_data_from_url(i) i = i.first if i.is_a? Array i = i.to_s.dup i = File.basename(i) i.gsub(/download\?file=/,''). gsub(/\/download$/,''). gsub(/\?download$/,''). gsub(/-fullsrc/,''). gsub(/-source/,''). gsub(/\?use_mirror=dfn/,''). gsub(/\.src/,''). gsub(/-src/,'') # .gsub(/_/,'-') # This here may be controversial, hence it # was disabled it as of Jun 2010. # i = remove_file_extension(i) # ^^^ We can not do the above, because program_full_name # must include the archive. end
#¶ ↑
reset¶ ↑
#¶ ↑
# File lib/cookbooks/base/reset.rb, line 8 def reset @be_verbose = true # ======================================================================= # # Report how many programs are registered. If true, then we will # report it. # ======================================================================= # @report_how_many_programs_are_registered = true @debug = false # Whether we will debug or not. @be_verbose = true end
#¶ ↑
#return_utc_time_in_a_format_similar_to_slackware¶ ↑
Slackware changelog uses a format such as this one here, in a UTC format:
Thu Sep 21 01:23:24 UTC 2017
#¶ ↑
# File lib/cookbooks/base/time.rb, line 104 def return_utc_time_in_a_format_similar_to_slackware return_weekday_based_on_utc.to_s+' '+ return_month_based_on_utc.to_s+' '+ return_day_of_the_month_based_on_utc+' '+ return_hours_minutes_seconds_based_on_utc+ ' UTC '+ return_year_based_on_utc end
#¶ ↑
#set_be_verbose¶ ↑
By default we will be verbose.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 285 def set_be_verbose(i = true) @be_verbose = i end
#¶ ↑
store_into_this_directory?¶ ↑
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 323 def store_into_this_directory? _ = ::Cookbooks.store_into_this_directory? ensure_that_this_directory_exists(_) # Make sure that the directory exists. return _ end
#¶ ↑
touch (touch tag)¶ ↑
Use this method to create a new file.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 146 def touch( i, be_verbose = false ) case be_verbose when :be_verbose be_verbose = true end if be_verbose e 'Next creating the file `'+sfile(i)+'`.' end FileUtils.touch(i) end
#¶ ↑
use_colours?¶ ↑
Just delegate towards the variable @use_colours.
#¶ ↑
# File lib/cookbooks/base/colours.rb, line 47 def use_colours? ::Cookbooks.use_colours? end
#¶ ↑
#verbose_truth¶ ↑
This will give us back “yes” or “no”, in String form.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 443 def verbose_truth(i) ::Cookbooks.verbose_truth(i) end
#¶ ↑
#word_wrap¶ ↑
The first argument is the text that will be reformatted.
The second argument is at which position we will wrap it.
#¶ ↑
# File lib/cookbooks/base/prototype.rb, line 461 def word_wrap(this_text, n_characters_limit = 78) unless this_text.encoding.to_s.include? main_encoding? this_text = ensure_main_encoding_for(this_text) end this_text.gsub(/(.{1,#{n_characters_limit}})(\s+|$)/, "\\1\n") end