class Cookbooks::Cookbook
Constants
- ARRAY_ARRAY_ENTRIES
#¶ ↑
Cookbooks::ARRAY_ARRAY_ENTRIES (array tag)¶ ↑
These entries should be kept as an Array.
#¶ ↑
- ARRAY_EMPTY_VALUES
#¶ ↑
Cookbooks::ARRAY_EMPTY_VALUES¶ ↑
All values that will initialize default to an empty string, have to be registered here.
#¶ ↑
- ARRAY_FALSE_VALUES
#¶ ↑
Cookbooks::ARRAY_FALSE_VALUES (false tag)¶ ↑
This constant collects all values that must be explicitely set to false on startup.
#¶ ↑
- ARRAY_MAIN_PROGRAM_ENTRIES
#¶ ↑
Cookbooks::ARRAY_MAIN_PROGRAM_ENTRIES¶ ↑
We need the following 8 entries defined here, so that we do not forget them lateron.
These are the only entries we care about and describe the most important components of a program.
#¶ ↑
- ARRAY_NIL_ENTRIES
#¶ ↑
Cookbooks::ARRAY_NIL_ENTRIES (nil tag)¶ ↑
All entries that are nil by default.
#¶ ↑
- ARRAY_TRUE_VALUES
#¶ ↑
ARRAY_TRUE_VALUES (true tag)¶ ↑
Only a few variables are true for now, by default - prefix, run_ldconfig and has_to_be_compiled.
#¶ ↑
- DEFAULT_PROGRAM_VERSION
#¶ ↑
DEFAULT_PROGRAM_VERSION¶ ↑
#¶ ↑
- HOW_TO_INVOKE_THE_PROGRAM
#¶ ↑
HOW_TO_INVOKE_THE_PROGRAM¶ ↑
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE¶ ↑
#¶ ↑
- REPLACE_PLUS_WITH_LONG_NAME
#¶ ↑
REPLACE_PLUS_WITH_LONG_NAME¶ ↑
If this constant is true then we will replace '+' with 'plus' if they are part of a program name.
#¶ ↑
Public Class Methods
#¶ ↑
::feedback_all_available_formats¶ ↑
To invoke this method from the commandline, try:
cookbooks --feedback_all_available_formats
#¶ ↑
# File lib/cookbooks/class/feedback/feedback_all_available_formats.rb, line 22 def self.feedback_all_available_formats dataset = return_file_specification_of_registered_cookbook_entries dataset.each_pair {|key, value| if Object.const_defined? :Colours separator = slateblue(': ') else separator = simp(': ') end ::Cookbooks.e( key.ljust(30)+separator+value.rjust(10) ) } end
#¶ ↑
::feedback_format_specification_of¶ ↑
This is the method that will tell us whether an entry in the cookbooks settings is an Array or a String or a Hash or a Boolean value.
Usage example:
Cookbooks::Cookbook.feedback_format_specification_of :headers
From the commandline:
scookie --format-specification-of=extract_to cookbooks --format-specification-of=extract_to
#¶ ↑
# File lib/cookbooks/class/feedback/feedback_format_specification_of.rb, line 41 def self.feedback_format_specification_of( i = 'extract_to' ) i = i.to_s unless i.is_a? String # We need a String here. # ======================================================================= # # First, load the YAML file that has our dataset. # ======================================================================= # dataset = return_file_specification_of_registered_cookbook_entries # We need this method. if dataset.has_key? i format_type = dataset[i] opnn; e "The format type for the key `#{Colours.simp(i)}` is:" opnn; e " #{Colours.sfancy(format_type)}" else opnn; e 'No format called `'+Colours.simp(i)+'` is known.' end end
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/cookbooks/class/initialize.rb, line 14 def initialize( commandline_arguments = nil, run_already = true ) reset # ======================================================================= # # Next handle blocks. This must happen before the invocation of the # method set_commandline_arguments() because we can thus also # bypass calling menu(). # ======================================================================= # if block_given? yielded = yield # ===================================================================== # # For now, we will only check for Symbols in the given block. # ===================================================================== # if yielded.is_a? Symbol case yielded when :be_quiet_and_bypass_menu @use_menu_interface = false be_quiet when :skip_menu_interface, :bypass_menu, :bypass_menu_check @use_menu_interface = false else opnn; e "Unknown symbol called #{sfancy(yielded.to_s)} passed." end # ===================================================================== # # === Handle hashes next # ===================================================================== # elsif yielded.is_a? Hash if yielded.has_key? :use_menu_interface set_use_menu_interface( yielded.delete(:use_menu_interface) ) end if yielded.has_key? :make_use_of_aliases_kept_in_the_file_cookbook_aliases _ = yielded.delete(:make_use_of_aliases_kept_in_the_file_cookbook_aliases) set_make_use_of_aliases_kept_in_the_file_cookbook_aliases(_) end end end set_commandline_arguments( commandline_arguments ) run if run_already end
#¶ ↑
::return_dataset¶ ↑
This will return the whole dataset. You can then use this dataset in other programs.
Returns: a Hash
Usage examples:
htop_dataset = SanitizeCookbookDataset.return_array(:htop) ruby_dataset = SanitizeCookbookDataset.return_array(:ruby)
#¶ ↑
# File lib/cookbooks/class/class_methods/class_methods.rb, line 30 def self.return_dataset(of_this_program = :htop) dataset = ::Cookbooks::Cookbook.new(of_this_program).yaml_dataset? return dataset end
Public Instance Methods
#¶ ↑
#archive_type?¶ ↑
Simply query the archive type here. The #archive_type is something such as “.tar.gz” or “.tar.bz2”.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 791 def archive_type? obtain(:archive_type) end
#¶ ↑
#array_invalid_keys?¶ ↑
All invalid cookbook-entries will be kept in this Array.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 387 def array_invalid_keys? @internal_hash[:array_invalid_keys] end
#¶ ↑
#assemble_default_program_name¶ ↑
This method will assemble the #program_name (6) variable, which is derived directly from:
short_name? and '-' and program_version?
For example it could look like this:
"gnome-mahjongg-5.08"
#¶ ↑
# File lib/cookbooks/class/set.rb, line 735 def assemble_default_program_name set_program_name(return_program_name) end
#¶ ↑
#assemble_program_full_name¶ ↑
This method will build-up a valid “program_full_name” setting.
In order to achieve this, it will make use of the method called #return_default_program_full_name, which itself is a combination of #program_name?+archive_type?.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 442 def assemble_program_full_name( i = return_default_program_full_name ) set_program_full_name(i) end
#¶ ↑
#assemble_program_path¶ ↑
This method will always ultimate attempt to set the program path, if possible.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 835 def assemble_program_path( i = return_default_program_path ) assemble_default_program_name # Assign to something such as: "gnome-mahjongg-0.1.3" set_program_path(i) end
#¶ ↑
#base_dir?¶ ↑
This is entry (5), a simple query method. It will give us back the base directory of our program in question, such as '/Users/x/SRC/htop/'.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 203 def base_dir? obtain(:base_dir) end
#¶ ↑
#batch_validate_the_cookbooks¶ ↑
#¶ ↑
# File lib/cookbooks/class/class.rb, line 420 def batch_validate_the_cookbooks unless Cookbooks.const_defined? :BatchValidateTheCookbookRecipes require 'cookbooks/validation/batch_validate_the_cookbook_recipes.rb' end BatchValidateTheCookbookRecipes.new end
#¶ ↑
#build_static?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 354 def build_static? obtain(:build_static) end
#¶ ↑
#calculate_archive_size¶ ↑
This method can be used to determine the size of the target archive in question. The corresponding entry will be set in the main Hash, called 'archive_size'.
In order for this to work, we need the content of #program_path defined before, however. Whenever we set #program_path, we can re-calculate the filesize anew.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 139 def calculate_archive_size if found_result? if File.exist? program_path?.to_s size = File.size?(program_path?.to_s) set_archive_size(size) end end end
#¶ ↑
#chop_off_revision_number¶ ↑
This method will check if a program version ends with a String such as “-r8”. If so then this part will be chopped off.
Usually this trailing part denotes an internal revision rather than an external program version.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 465 def chop_off_revision_number _ = program_version? use_this_regex = /(-r\d{1,2})$/ if _ =~ use_this_regex _.sub!(use_this_regex,'') set_program_version(_) end end
#¶ ↑
#cleanup_unusued_variables¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 302 def cleanup_unusued_variables # ======================================================================= # # Must safeguard to query whether the key still exists. When it does, # we will simply delete them. # ======================================================================= # if ihash?.has_key? :array_invalid_keys ihash?.delete :array_invalid_keys end end
#¶ ↑
commandline_arguments?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 378 def commandline_arguments? @internal_hash[:commandline_arguments] end
#¶ ↑
#configure_command?¶ ↑
The specific configure command that we will use.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 52 def configure_command? obtain(:configure_command) end
#¶ ↑
#decompose_program_name¶ ↑
This method will set #short_name and #program_version, by making use of the content stored in #program_name? by default.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 501 def decompose_program_name(i = program_name?) _ = ::ProgramInformation.return_short_name_and_program_version(i) set_short_name(_.short_name?, :propagate_towards_real_short_name) set_program_version(_.program_version?) end
#¶ ↑
description? (description tag)¶ ↑
The description value of a program will be returned via this method.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 854 def description?(wrap_result = wrap_result?) result = obtain(:description) case wrap_result when :retain_newlines wrap_result = false end if wrap_result if use_word_wrap? result = word_wrap(result) end if result # Do not work on nil-values here. end return result end
#¶ ↑
#do_extract¶ ↑
You can use this method, if you have class Extracter available, to force class Extracter to extract this program.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 209 def do_extract(i = program_path?) begin require 'extracter' unless Object.const_defined? :Extracter rescue LoadError; end if Object.const_defined? :Extracter # ===================================================================== # # Ok, extracter is available so we can continue. # ===================================================================== # Extracter.new(i?).extracted_path? # Specify the path. else opnn; e 'class Extracter is not available. Consider installing it via:' e opnn; e orange(' gem install extracter') e end end
#¶ ↑
#do_permanently_use_psych¶ ↑
Use this method if you wish to permanently use psych, rather than syck.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 433 def do_permanently_use_psych opnn; e 'We will use the psych module for yaml-datasets from now on.' opnn; e 'This will be stored in the file '+sfile(FILE_USE_PSYCH_OR_SYCK) write_what_into(YAML.dump(:psych), FILE_USE_PSYCH_OR_SYCK) if is_on_roebe? write_what_into(YAML.dump(:psych), ROEBE_PATH_TO_COOKBOOKS+'yaml/configuration/'+ File.basename(FILE_USE_PSYCH_OR_SYCK) ) end end
#¶ ↑
#do_permanently_use_syck¶ ↑
Use this method if you wish to permanently use syck, rather than psych.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 451 def do_permanently_use_syck opnn; e 'We will use the syck module for yaml-datasets from now on.' opnn; e 'This will be stored in the file '+sfile(FILE_USE_PSYCH_OR_SYCK) write_what_into(YAML.dump(:syck), FILE_USE_PSYCH_OR_SYCK) if is_on_roebe? write_what_into(YAML.dump(:syck), ROEBE_PATH_TO_COOKBOOKS+'yaml/configuration/'+ File.basename(FILE_USE_PSYCH_OR_SYCK) ) end end
#¶ ↑
#do_show_full_description¶ ↑
This method will allow us to show the full description of a given program.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 250 def do_show_full_description # ======================================================================= # # The following method-call will toggle the proper behaviour. # ======================================================================= # ::Cookbooks::Cookbook.do_not_honour_threshold_value end
#¶ ↑
#do_use_this_program_version¶ ↑
Use this method specifically to set (and use) another program version.
The difference towards #set_program_version is that we will also re-assemble the default program path.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 563 def do_use_this_program_version(i = '1.52.1') set_program_version(i) reassemble_program_path end
#¶ ↑
does_include?¶ ↑
#¶ ↑
# File lib/cookbooks/class/class.rb, line 542 def does_include?( i, honour_aliases = make_use_of_aliases_kept_in_the_file_cookbook_aliases? ) ::Cookbooks.does_include? i, honour_aliases # Delegate towards the class method. end
#¶ ↑
#ensure_proper_true_false_array_and_empty_values (ensure tag)¶ ↑
This method will ensure that the main hash will have certain default values set.
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 34 def ensure_proper_true_false_array_and_empty_values ensure_that_the_boolean_values_are_there # <- Will set true and false values. ensure_that_the_empty_values_are_there ensure_that_the_array_values_are_there end
#¶ ↑
#ensure_that_the_array_values_are_there¶ ↑
This method will ensure that all specified Array entries are part of the internal yaml dataset.
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 54 def ensure_that_the_array_values_are_there ARRAY_ARRAY_ENTRIES.each {|this_entry_must_become_an_array| set(this_entry_must_become_an_array, []) unless has_key? this_entry_must_become_an_array } end
#¶ ↑
#ensure_that_the_empty_values_are_there¶ ↑
We must ensure that the empty values are also properly set to “” on startup, in a mandatory fashion.
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 66 def ensure_that_the_empty_values_are_there ARRAY_EMPTY_VALUES.each {|empty_value| set(empty_value, '') unless has_key? empty_value } end
#¶ ↑
#ensure_that_the_false_values_are_there (false tag)¶ ↑
Here we will set all false values into our main dataset.
We do this only if we do not yet have such a value in our dataset though.
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 95 def ensure_that_the_false_values_are_there # ======================================================================= # # Set the false values to false next. # ======================================================================= # ARRAY_FALSE_VALUES.each {|this_false_value| if has_key? this_false_value sanitize_boolean_value(this_false_value) else set(this_false_value, false) end } end
#¶ ↑
#ensure_that_the_nil_values_are_there (nil tag)¶ ↑
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 20 def ensure_that_the_nil_values_are_there( nil_values = ARRAY_NIL_ENTRIES ) nil_values.each {|this_entry_must_be_nil| set(this_entry_must_be_nil, nil) unless has_key? this_entry_must_be_nil } end
#¶ ↑
#ensure_that_the_true_values_are_there¶ ↑
Now come the true values, array_true_values. Right now only prefix must default to true - but only if it is empty.
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 78 def ensure_that_the_true_values_are_there ARRAY_TRUE_VALUES.each {|true_value| if has_key? true_value sanitize_boolean_value(true_value) else set(true_value, true) end } end
#¶ ↑
#ensure_that_this_hash_has_only_valid_keys¶ ↑
The input to this method must be a Hash.
This method will ensure that the given Hash has only valid keys.
In the past, we could use it to convert it into Symbols but this is no longer in use. We now make no further modifications to the original dataset in use.
If all keys are valid then we won't have to notify the user about it at all.
#¶ ↑
# File lib/cookbooks/class/ensure.rb, line 122 def ensure_that_this_hash_has_only_valid_keys( i = yaml_dataset? ) if i.nil? cliner opnn; e sfancy('nil')+' was passed into the method '+ orange('ensure_that_this_hash_has_only_valid_keys()') opnn; e 'This can not be right. Program name was: '+ sfancy(program_name?.to_s)+'.' pp caller() pp self cliner else i.each_pair {|key, value| unless registered_cookbook_entries?.include?(key) seek_this_yaml_file = "#{seek_this_program?}.yml" opnn; e "#{swarn('Warning')} - the cookbook-file for `"\ "#{sfancy(seek_this_yaml_file)}"\ "` contains a key that was" opnn; e "#{swarn('NOT')} registered. The name of that (invalid / "\ "ignored) key is: `#{sfancy(key.to_s)}`." opnn; e 'This is defined in the file '+Colours.sfile( 'registered_cookbook_entries.yml') register_invalid_key(key) # ================================================================= # # Next, also try to find a name that is similar. # ================================================================= # if registered_cookbook_entries?.any? {|entry| entry.include? key.to_s } select_this_entry = registered_cookbook_entries?.select {|entry| entry.include? key.to_s }.first opnn; e "Did you mean this entry instead? "\ "#{sfancy(select_this_entry)}" end end } end end
#¶ ↑
#extra_information?¶ ↑
We must not get rid of information from the original dataset.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 809 def extra_information? result = obtain(:extra_information) if result.encoding.to_s.include? 'UTF-8' result.force_encoding(ENCODING_ISO) end if result if use_word_wrap? result = word_wrap(result) end if result # Do not work on nil-values here. end return result end
#¶ ↑
#guess_entries_based_on_the_first_url¶ ↑
This method is used to call some entries on the dataset.
If the #program_name is already set, though, then we will NOT guess it at all. But we will split it up, and set the cascading variants on it.
#¶ ↑
# File lib/cookbooks/class/guess.rb, line 74 def guess_entries_based_on_the_first_url _ = url1?.dup if _.include? '-release.tar' _ = chop_off_archive(_) _.sub!(/-release/,'') end basename = File.basename(_) if basename.include? '%2B' # This means '+'. basename.gsub!(/%2B/,'+') end # ======================================================================= # # Some yaml-entries may have program_name set. We have to check for this # here. # ======================================================================= # unless program_name?.to_s.empty? basename = program_name? end # ======================================================================= # # At this point, sanitize program_name. # ======================================================================= # basename = return_sanitized_program_name(basename) basename = remove_archive_from_the_end(basename) basename.chop! if basename.end_with? '.' # ======================================================================= # # Obtain information from ProgramInformation. # ======================================================================= # program_information = ProgramInformation.new(basename) if program_information.program_version? set_program_version(program_information.program_version?) end if program_information.real_short_name? set_real_short_name(program_information.real_short_name?) end if program_information.short_name? set_short_name(program_information.short_name?) end if File.basename(url?).include? '_' unless File.basename(url?).include? '-' # ===================================================================== # # Specifically change this for programs such as 'artemis_v16.0.11.jar'. # ===================================================================== # set_use_this_connective_token '_' end end assemble_program_name # This is short_name?+'-'+program_version? usually. set_archive_type(_) set_base_dir( source_dir?+ real_short_name?.downcase.delete('.')+ # <- Is not allowed to have any '.' tokens. '/' ) if !program_name?.empty? program_information = ProgramInformation.new(program_name) set_short_name(program_information.name?) set_program_version(program_information.version?) end assemble_program_path # use_default_connective_token_again <- This should be re-enabled one day. end
#¶ ↑
#guess_program_version¶ ↑
We can use this method to guess the program version. This requires that the entry for #program_name exists.
We will delegate towards the method #set_program_version() then.
#¶ ↑
# File lib/cookbooks/class/guess.rb, line 60 def guess_program_version(i = program_name?) _ = ::ProgramInformation.return_version(i) set_program_version(_) end
#¶ ↑
#has_to_be_compiled?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 943 def has_to_be_compiled? obtain(:has_to_be_compiled) end
#¶ ↑
headers?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 59 def headers? obtain(:headers) end
#¶ ↑
homepage?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 925 def homepage? obtain(:homepage) end
#¶ ↑
#initialize_the_internal_hash¶ ↑
#¶ ↑
# File lib/cookbooks/class/reset.rb, line 20 def initialize_the_internal_hash # ======================================================================= # # Everything is stored here into this main Hash. # ======================================================================= # @internal_hash = {} @internal_hash[:yaml_dataset] = nil # Is nil initially. @internal_hash[:search_for_this_program] = nil @internal_hash[:is_the_program_included] = false @internal_hash[:replace_plus_with_long_name] = REPLACE_PLUS_WITH_LONG_NAME @internal_hash[:array_invalid_keys] = [] # Invalid entries will be stored here. Must ALWAYS be an Array. @internal_hash[:shall_we_display_the_md5sum] = ::Cookbooks.display_md5sum? # ======================================================================= # # By default, we will word-wrap too long text lines. # ======================================================================= # @internal_hash[:wrap_result] = true @internal_hash[:report_how_many_programs_are_registered] = false @internal_hash[:use_this_connective_token] = '-' # ======================================================================= # # Next, determine whether to use cookbook-internal aliases or whether # we shall not. # ======================================================================= # @internal_hash[:make_use_of_aliases_kept_in_the_file_cookbook_aliases] = true end
#¶ ↑
#initialize_yaml_dataset¶ ↑
#¶ ↑
# File lib/cookbooks/class/dataset.rb, line 12 def initialize_yaml_dataset set_archive_size 0 # Initialize the program size to 0. It will may be changed lateron. # ======================================================================= # # Add nil, array, empty values and booleans. # ======================================================================= # ensure_that_the_nil_values_are_there ensure_that_the_array_values_are_there ensure_that_the_empty_values_are_there # ======================================================================= # # === Ensure that the boolean values (true and false) will be there # ======================================================================= # ensure_that_the_boolean_values_are_there # ======================================================================= # # Last but not least, add the missing entries. # ======================================================================= # fill_in_missing_entries end
#¶ ↑
is_a_boolean_configuration_value?¶ ↑
Query method to determine whether the input is a boolean configuration value. For example, the String “use_glib_schema”, would be a boolean configuration value and thus this method would return true.
#¶ ↑
# File lib/cookbooks/class/constants.rb, line 155 def is_a_boolean_configuration_value?(i) ( ARRAY_FALSE_VALUES + ARRAY_TRUE_VALUES ).flatten.include? i end
#¶ ↑
is_a_game?¶ ↑
This method will simply return true if the program in question is a game, and false if it is not a game. That way we can quickly find out whether the input is a game or whether it is not.
ProgramInformation.return_name @program_name ProgramInformation.return_name 'supertux-0.1.1'
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 585 def is_a_game? return true if tags?.to_s.include? 'game' return false # Else return false here. end
#¶ ↑
#keep_extracted?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 210 def keep_extracted? obtain(:keep_extracted) end
#¶ ↑
#last_update?¶ ↑
The #last_update tag keeps track over as to when that particular program was last updated.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 639 def last_update? obtain(:last_update) end
#¶ ↑
licence?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 833 def licence? obtain(:licence) end
#¶ ↑
#load_yaml_dataset_from_this_file¶ ↑
This is the main method, the powerhorse of the class - it will load up the dataset for a given program, from the .yml file at hand.
In order for this to work, the .yml file must of course exist locally.
You can also pass the name of the program, such as “htop”, rather than specify the full path. The method will automatically expand in such a case.
#¶ ↑
# File lib/cookbooks/class/dataset.rb, line 73 def load_yaml_dataset_from_this_file( i = search_for_this_program? ) original_search_term = i.dup clear_yaml_dataset # ======================================================================= # # Initialize the yaml dataset first. # ======================================================================= # initialize_yaml_dataset # ======================================================================= # # Next, check whether there is any '/' character in the given input. # If not, then we will expand to the real, full path. # ======================================================================= # unless i.empty? # Ignore empty Strings. unless i.include?('/') if make_use_of_cookbook_aliases? if Cookbooks.is_an_alias?(i) and !Cookbooks.program_is_included?(i, :do_not_check_for_aliases) original_name = i.dup # ================================================================= # # Ok, it is an alias. This must also re-rewrite the program # that we are searching for. # ================================================================= # i = Cookbooks.find_alias_for(original_name) opnn; e "The alias name #{sfancy(i)} will be "\ "used for #{simp(original_name)}." set_search_for_this_program(i) end i = return_default_location_of_this_cookbook(i) end end end if debug? opnn; e 'Now loading the dataset from the file `'+sfile(i)+'`.' end unless i.end_with? '.yml' i = return_default_location_of_this_cookbook(i) end # ======================================================================= # # The file must exist, because otherwise we can not load up the yaml # dataset. We will also have to ensure that it is a file. # ======================================================================= # if File.exist?(i) and File.file?(i) the_program_is_included dataset = YAML.load_file(i) update_yaml_dataset(dataset) set_short_name nil # Must be specifically set to nil. if yaml_dataset_exists? sync_yaml_dataset_down_one_level sanitize_yaml_dataset end else this_program_was_not_found(original_search_term) end end
#¶ ↑
main_eight?¶ ↑
This method will return the main 8 entries that are the most important ones for any given program at hand.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 649 def main_eight?( use_padded_output = true ) _ = ''.dup one = 'real_short_name: '.dup two = 'short_name: '.dup three = 'program_version: '.dup four = 'archive_type: '.dup five = 'base_dir: '.dup six = 'program_name: '.dup seven = 'program_full_name: '.dup eight = 'program_path: '.dup # ======================================================================= # # Next make sure to pad the output, if the user requested this. # ======================================================================= # if use_padded_output n_ljust = 19 one = one.ljust(n_ljust) two = two.ljust(n_ljust) three = three.ljust(n_ljust) four = four.ljust(n_ljust) five = five.ljust(n_ljust) six = six.ljust(n_ljust) seven = seven.ljust(n_ljust) eight = eight.ljust(n_ljust) end _ << one+real_short_name?.dup+N _ << two+short_name?.dup+N _ << three+program_version?.dup+N _ << four+archive_type?.dup+N _ << five+base_dir?.dup+N _ << six+program_name?.dup+N _ << seven+program_full_name?.dup+N _ << eight+program_path?.dup+N return _ end
#¶ ↑
#make_options?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 950 def make_options? obtain(:make_options) end
#¶ ↑
make_use_of_aliases_kept_in_the_file_cookbook_aliases?¶ ↑
This method can be used to query whether we will make use of aliases kept in the cookbook_aliases.yml file or whether we will not.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 576 def make_use_of_aliases_kept_in_the_file_cookbook_aliases? @internal_hash[:make_use_of_aliases_kept_in_the_file_cookbook_aliases] end
#¶ ↑
md5sum?¶ ↑
Conditionally use md5sum.
This method must accomodate three different possibilities.
(1) We have generated a .yml file in a special directory. We
will preferentially use that one, if it exists. This requires of the user to have generated these values already. If the user did so then we will use these values rather than calculate them anew again. The advantage of this way is that it will significantly speed up the process.
(2) IF we do not have such a file as described in (1), then we will
first try to use the ruby Md5sum class, specifically its Md5sum[] class method. Note that the ruby Md5sum class is fairly slow for large programs, which is why option (1) is the default since as of April 2016.
(3) The other two options (1) and (2) not being available, we will
try to use the unix coreutils "md5sum" instead, which is a binary, and should be pretty fast.
Note that as of May 2016, we also make available a way to NOT calculate the md5sum at all. Not everyone will need the md5sum information after all.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 426 def md5sum?(use_this_path = path?) # ======================================================================= # # === Try to use yaml files first # # The expanded directory on my system will be here: # # /Depot/Temp/CookbookDirectory/expanded_cookbooks/ # # ======================================================================= # if File.directory?(::Cookbooks.base_dir_to_store_expanded_cookbooks?) and File.exist?(use_this_path.to_s) and use_this_path.end_with?('.yml') begin dataset = YAML.load_file(use_this_path) return dataset['md5sum'].to_s rescue ArgumentError => error opnn; e 'An error happened for the path `'+ sfile(use_this_path)+'`. We will exit as a consequence.' pp error exit end # ======================================================================= # # === Use the pure ruby way next # ======================================================================= # elsif Object.const_defined? :Md5sum Md5sum[use_this_path].md5sum? # Calculate it anew via Md5sum[]. # ======================================================================= # # === Try to use md5sum binary directly next # ======================================================================= # elsif (result = `md5sum bogus 2>&1`) and !result.include?('command not found') if File.directory? use_this_path # A workaround for now. return '0' else # =================================================================== # # Delegate to the system tool here, part of coreutils. # =================================================================== # result = `md5sum #{use_this_path}`.split(' ').first result.strip! if result return result end else '0' # Return 0 then. But that should not ever happen. end end
#¶ ↑
obtain (obtain tag, o tag)¶ ↑
Use this getter-method to obtain elements of the main yaml dataset directly, stored within the @internal_hash.
The main reason why we will use this method here is because the keys can be either Symbols or Strings. If we ever wish to change to another format, we can do so thanks to the flexibility of this setup.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 518 def obtain(i) i = i.to_s unless i.is_a? String # ======================================================================= # # We can feedback input that was not found - but this can become noisy, # so I have disabled this as of Sep 2015. # ======================================================================= # # begin # return _[i] # rescue NoMethodError; end # ======================================================================= # if @internal_hash[:yaml_dataset] @internal_hash[:yaml_dataset][i] # [] is better than .fetch() here. end end
#¶ ↑
#optional_start_message¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 140 def optional_start_message? obtain(:optional_start_message) end
#¶ ↑
#pkgconfig_files?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 186 def pkgconfig_files? obtain(:pkgconfig_files) end
#¶ ↑
#pre_make_commands?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 394 def pre_make_commands? obtain(:pre_make_commands) end
#¶ ↑
#program_full_name?¶ ↑
This entry will have everything except the leading PATH.
For instance:
"gpm-1.20.1.tar.xz"
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 152 def program_full_name? obtain(:program_full_name) end
#¶ ↑
#program_name?¶ ↑
Feedback the #program_name through this method. The #program_name in this context, would mean a String such as gnome-mahjonng-5.08'.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 713 def program_name? obtain(:program_name) end
#¶ ↑
#program_path?¶ ↑
This method will return the 'program_path' value, through the reader method obtain().
The #program_path variable has the FULL path to the archive in question, for instance:
/Users/x/SRC/gnomemahjonng/gnome-mahjonng-5.08.tar.xz /Users/x/SRC/gpm/gpm-1.20.1.tar.bz2
Do note that the #program_path value is the most important entry, as we can retrieve ALL other information from the information stored in this variable alone.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 550 def program_path? obtain(:program_path) end
#¶ ↑
#program_version?¶ ↑
This method must always return a String.
We use it to query the program version of the specific program at hand.
For instance, if the program name is “python-2.4” then this method will return the version string part, i.e. “2.4”.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 335 def program_version? obtain(:program_version) end
#¶ ↑
#properly_pad_and_colourize_this_help_option¶ ↑
#¶ ↑
# File lib/cookbooks/class/help.rb, line 171 def properly_pad_and_colourize_this_help_option( key_to_invoke_the_method, text_that_is_to_be_displayed ) left_padding = ' ' # A bit of left-padding here. n_left_pad_value = 38 n_left_pad_value -= key_to_invoke_the_method.size left_padding+HOW_TO_INVOKE_THE_PROGRAM+ skyblue(' '+key_to_invoke_the_method)+ (' ' * n_left_pad_value)+' # '+ text_that_is_to_be_displayed end
#¶ ↑
#quiet_down¶ ↑
This method will cause the cookbook to be silent and not report how many programs are registered.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 198 def quiet_down set_be_silent # This is defined in the parent class. @internal_hash[:report_how_many_programs_are_registered] = false end
#¶ ↑
#raw_description?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 872 def raw_description? obtain(:raw_description) end
#¶ ↑
real_short_name¶ ↑
Reader method for real_short_name. This can only work after we invoked merge_basic_dataset().
real_short_name? may never include '-' characters.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 171 def real_short_name? obtain(:real_short_name) end
#¶ ↑
report¶ ↑
This is just a general-purpose method that will output some values.
It will output useful information about a program.
For a full report system, use the specialized class DisplayCookbookDataset.
#¶ ↑
# File lib/cookbooks/class/report.rb, line 89 def report( program_name = short_name? ) return if program_name.to_s.empty? @array_show_these_entries.clear @array_show_these_entries << :description # ======================================================================= # # Add a bunch of symbols to the main array here. # ======================================================================= # @array_show_these_entries << %i( program_path program_full_name program_name real_short_name short_name program_compile_name program_version archive_type base_dir remote_url extract_to prefix configure_options md5sum file_size keep_extracted ) @array_show_these_entries.flatten! # ======================================================================= # # === short_description # ======================================================================= # unless short_description?.empty? @array_show_these_entries << :short_description end if short_description? # ======================================================================= # # Unless the pkgconfig_files Array is empty, we will display the # .pc files of the given program. # ======================================================================= # if pkgconfig_files? unless pkgconfig_files?.empty? @array_show_these_entries << :pkgconfig_files end end unless extra_information?.empty? @array_show_these_entries << :extra_information end unless configure_command?.empty? unless configure_command? == 'configure' @array_show_these_entries << :configure_command end end # ======================================================================= # # === Show the main homepage if it exists # ======================================================================= # if homepage? @array_show_these_entries << :homepage end # ======================================================================= # # === Add the headers, if they exist # ======================================================================= # unless headers?.empty? @array_show_these_entries << :headers end if build_static? == true @array_show_these_entries << :build_static end unless use_this_make_command?.to_s == 'make' @array_show_these_entries << :use_this_make_command end if (sed? == true) and !sed?.to_s.empty? @array_show_these_entries << :sed end @array_show_these_entries << :do_not_download if do_not_download? @array_show_these_entries << :required_deps_on unless deps?.empty? @array_show_these_entries << :apply_patch if apply_patch? @array_show_these_entries << :libraries unless libraries?.empty? @array_show_these_entries << :make_options unless make_options?.empty? @array_show_these_entries << :enable_shared if enable_shared? @array_show_these_entries << :binaries unless binaries?.empty? @array_show_these_entries << :preinstall unless preinstall?.empty? @array_show_these_entries << :postinstall unless postinstall?.empty? @array_show_these_entries << :tags unless tags?.empty? @array_show_these_entries << :svn_url if svn_url? and !svn_url?.empty? @array_show_these_entries << :pre_make_commands unless pre_make_commands?.empty? @array_show_these_entries << :use_build_directory if use_build_directory? @array_show_these_entries << :licence # <- Mandatory entry. # ======================================================================= # # === Use autogen will always be shown. # ======================================================================= # @array_show_these_entries << :use_autogen @array_show_these_entries << :configure_base_dir if configure_base_dir? and !configure_base_dir?.to_s.empty? @array_show_these_entries << :blfs unless blfs?.empty? @array_show_these_entries << :last_update @array_show_these_entries << :has_to_be_compiled @array_show_these_entries << :do_not_symlink if do_not_symlink? @array_show_these_entries << :md5sum if show_md5sum? @array_show_these_entries << :use_this_make_install_command if use_this_make_install_command? @array_show_these_entries << :skip_configure if skip_configure? # ======================================================================= # # Next, display it with a coloured "border". # ======================================================================= # use_this_colour_or_no_colour = :lightblue unless use_colours? use_this_colour_or_no_colour = :do_not_use_colours end cliner(use_this_colour_or_no_colour) { e 'Feedbacking all about the program `'+simp(program_name)+'`.' e show_this_array(@array_show_these_entries) # ===================================================================== # # Show important URLs next. # ===================================================================== # if urls?.first e; e ' Important URLs:' _ = urls?.map {|entry| entry.to_s.chomp }.reject {|x| x.empty?} if _ e; _.each_with_index {|line, index| e "#{grey(' (')}#{seagreen(index+1).to_s}#{grey(') ')}#{grey(line)}" }; e end end } e end
#¶ ↑
#report_binary_or_library_program_name¶ ↑
Only call this method when we have found an alias.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 301 def report_binary_or_library_program_name( i, new_program_name, binary_or_library = 'binary' ) case binary_or_library when :binary binary_or_library = 'binary' when :library binary_or_library = 'library' end opnn; e '`'+simp(i)+'` was found as name of a '+simp(binary_or_library)+' file.' opnn; e 'We will now assume that you want to get this whole package '\ 'instead and will' opnn; e 'thus set the name to this program now, which belongs to '\ 'the package `'+sfancy(new_program_name)+'`.'+N end
#¶ ↑
#report_size_of_these_programs¶ ↑
This method will report the size of the issued programs.
#¶ ↑
# File lib/cookbooks/class/report.rb, line 39 def report_size_of_these_programs(i, size_of_the_programs = 0) if i.is_a? String and i.include?('=') i = i.to_s.dup if i.frozen? i.gsub!(/--size=/,'') i = i.split(',') if i.include? ',' end i = [i] unless i.is_a? Array i.each {|entry| dataset = self.new(entry) unless use_colours? dataset.disable_colours end size = dataset.size?.to_i opnn; e 'Now working on '+sfancy(entry.rjust(8))+ ' (Size: '+size.to_s.rjust(8)+' bytes)' size_of_the_programs += size } e opnn; e 'The size of the programs '+sfancy(i.join(','))+' is:' e if Object.const_defined? :HumanReadable size_of_the_programs = HumanReadable[size_of_the_programs] end result = " #{simp(size_of_the_programs.to_s)}".dup result << ' bytes' unless size_of_the_programs.to_s.strip.end_with? 'B' opnn; e result e end
#¶ ↑
#report_the_kde_status¶ ↑
This method will report the “status” of the KDE project, as far as the cookbooks project is concerned.
What is meant here is that this method will simply report the main constants that handle the remote URL to kde projects.
To invoke this method, do this on the commandline:
cookbooks --report-the-kde-status
#¶ ↑
# File lib/cookbooks/class/report.rb, line 487 def report_the_kde_status kde_frameworks_version = File.basename( REMOTE_URL_FOR_KDE_FRAMEWORKS ) kde_applications_version = File.basename( REMOTE_URL_FOR_KDE_APPLICATIONS.sub(/src\/$/,'') ) kde_plasma_version = File.basename( REMOTE_URL_FOR_KDE_PLASMA ).sub(/\.php$/,'').sub(/^plasma-/,'') e e 'KDE Frameworks version: '+cyan(kde_frameworks_version) e 'KDE Applications version: '+cyan(kde_applications_version) e 'KDE Plasma version: '+cyan(kde_plasma_version) e end
#¶ ↑
#report_total_size_of_locally_available_files¶ ↑
This method will simply calculate the total file size of all locally available programs.
#¶ ↑
# File lib/cookbooks/class/report.rb, line 449 def report_total_size_of_locally_available_files total_file_size = 0 _ = available_programs? _.each {|name_of_the_program| size = ::Cookbooks::Cookbook.new(name_of_the_program) { :bypass_menu }.file_size? opnn; e 'Now adding the file size of the '\ 'program `'+sfancy(name_of_the_program)+'` ('+ orange(size.to_s)+' bytes).' total_file_size += size } opnn; e "Total file size of #{sfancy(_.size.to_s)} programs: "\ "#{slateblue(total_file_size.to_s+' bytes')}" end
#¶ ↑
required_deps_on?¶ ↑
This method will list the required dependencies of a given program and returns them, at least those that are defined in the 'required_deps_on:' entry of the respective yaml file.
Please keep in mind that our dependencies must be kept in Array form.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 498 def required_deps_on? obtain(:required_deps_on) end
#¶ ↑
#return_appdir_path¶ ↑
This method will return an App-Dir like path.
It may be used from within #sanitize_prefix() - that is, when you wish to sanitize the prefix passed.
This method requires that #short_name? and #program_version? were already defined prior to invocation.
The appdir components would be like this:
/Programs/Ruby/2.4.1 programs_dir?+real_short_name?.capitalize+'/'+program_version?
#¶ ↑
# File lib/cookbooks/class/class.rb, line 373 def return_appdir_path( programs_dir_to_use = programs_dir?, short_name_to_use = real_short_name?.capitalize, program_version_to_use = program_version? ) _ = programs_dir_to_use.dup if are_we_on_gobolinux? _ << program_compile_name?.dup else _ << short_name_to_use.dup end _ << "/#{program_version_to_use.dup}/" return _ end
#¶ ↑
#return_default_location_of_this_cookbook¶ ↑
This will use the default location based on the search_term.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 269 def return_default_location_of_this_cookbook( i = search_term? ) individual_cookbooks_directory?+i+'.yml' end
#¶ ↑
#return_default_program_full_name¶ ↑
#program_full_name is something like 'gnome-mahjonng-5.08.tar.xz'.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 763 def return_default_program_full_name program_name?+archive_type? end
#¶ ↑
#return_first_underscore_as_hyphen_and_other_undscores_as_dots¶ ↑
This method exists specifically for input such as 'boost_1_61_0'.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 452 def return_first_underscore_as_hyphen_and_other_undscores_as_dots(i = url?) i = return_first_underscore_as_hyphen_from_this_url(i).dup i.tr!('_','.') return i end
#¶ ↑
#return_first_underscore_as_hyphen_from_this_url¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 441 def return_first_underscore_as_hyphen_from_this_url(i = url?) new_url = File.basename(i).dup # Obtain the URL here. new_url.sub!(/_/,'-') # This replaces only the first '_' found. return new_url end
#¶ ↑
#return_program_name¶ ↑
Note that the connective token in use is usually '-', but there are programs such as 'artemis_v16.0.11.jar' that have no '-' at all whatsoever. To also honour this, we have to use this connective token - it will be re-defined towards '_' specifically for programs that have no '-' token.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 711 def return_program_name( use_this_connective_token = use_this_connective_token? ) short_name?+use_this_connective_token+program_version? end
#¶ ↑
#return_program_path¶ ↑
This method will return the full program path, consisting of the #base_dir and #program_full_name component.
Example:
'/Users/x/SRC/gnomemahjonng/' + 'gnome-mahjonng-5.08.tar.xz'
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 571 def return_program_path base_dir?+program_full_name? end
#¶ ↑
#return_sanitized_program_name¶ ↑
This will also get rid of archives.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 648 def return_sanitized_program_name(i = program_name?.dup) url = url?.dup case i # case tag # ======================================================================= # # === FIRST_UNDERSCORE_AS_HYPHEN # # This will convert input such as 'boost_1_61_0' into 'boost-1_61_0'. # ======================================================================= # when 'FIRST_UNDERSCORE_AS_HYPHEN', 'FIRST_UNDERSCORE_IS_HYPHEN' i = return_first_underscore_as_hyphen_from_this_url(url) # ======================================================================= # # === FIRST_UNDERSCORE_AS_HYPHEN_AND_OTHER_UNDERSCORES_AS_DOTS # # This is due to boost again - apparnetly the boost developers make # use of a very strange packaging schemata. # # So this entry point will convert input such as 'boost_1_61_0' into # 'boost-1.61.0'. # ======================================================================= # when 'FIRST_UNDERSCORE_AS_HYPHEN_AND_OTHER_UNDERSCORES_AS_DOTS' i = return_first_underscore_as_hyphen_and_other_undscores_as_dots(url) # ======================================================================= # # === FIRST_DOT_AS_HYPHEN # # The following case is for input such as "sendmail.5.2.18" # which should become "sendmail-5.2.18". # # We only manipulate the last part though, so if we have input that # contains a '/', we assume that this is a path and split it up. # This is the reason why we will use File.basename() # ======================================================================= # when 'FIRST_DOT_AS_HYPHEN' i = return_first_dot_as_hyphen_from_this_url(url) # ======================================================================= # # === URL_REPLACE_UNDERSCORE # # This entry point handles the case when the input has '_' characters # in the String. If this is the case then all '_' will be replaced # via '-' characters. # ======================================================================= # when 'URL_REPLACE_UNDERSCORE', 'URL_CONVERT_UNDERSCORE', 'USE_URL_SANITIZED', 'REPLACE_UNDERSCORES', 'USE_URL_MIDDLE_HYPHENS' i = return_url_replace_underscore(url) # ======================================================================= # # === USE_URL_DOWNCASE # # Use the URL as program name but downcase it. # ======================================================================= # when 'USE_URL_DOWNCASE','USE_DOWNCASED' i = url.downcase # ======================================================================= # # === USE_URL # # Simply use the URL as-is, for the program name. # ======================================================================= # when 'USE_URL' i = url # ======================================================================= # # === PROGRAM_VERSION # ======================================================================= # when /PROGRAM_VERSION/ program_version = program_version? if program_version.empty? program_version = remove_archive_from_the_end( File.basename(url?.dup).delete('a-z') ) end i.sub!(/PROGRAM_VERSION/, program_version) i.squeeze!('.') end # ======================================================================= # # Get rid of any .tar.xz or similar archive end here. # ======================================================================= # i = remove_archive_from_the_end(i) return i end
#¶ ↑
#return_url_replace_underscore¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 418 def return_url_replace_underscore(i = url?) _ = File.basename(i).dup if _.include? '_' _.tr!('_','-') # Replace all '_' with '-'. elsif _.include? '.' # Else replace just the first '.'. _.sub!('.','-') end _ = remove_file_extension(_) return _ end
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/cookbooks/class/run.rb, line 14 def run # ======================================================================= # # Must check whether the .yml file exists. # ======================================================================= # update_with_this_program(search_for_this_program?) end
#¶ ↑
#sanitize_apply_patch¶ ↑
Here we sanitize the value for apply_patch.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 317 def sanitize_apply_patch _ = apply_patch? if _ if _.include? '#' _ = _[0 .. (_.index('#') - 1)] set_apply_patch _ end if _.include? 'if PROGRAM_VERSION' # Ok, we specified a specific version. version_to_compare = _.split(' ').last if version_to_compare == program_version? # Ok, patch can be applied. else # Else do not apply this patch. set_apply_patch '' end end end end
#¶ ↑
#sanitize_base_dir¶ ↑
This method will currently only downcase the last part, so that “Eterm/” becomes “eterm/” instead.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 382 def sanitize_base_dir _ = base_dir? if _.include? '/' splitted = _.split('/') last_part = splitted.last unless last_part == last_part.downcase splitted[-1] = last_part.downcase _ = splitted.join('/') set_base_dir(_) end end end
#¶ ↑
#sanitize_binaries (binaries tag)¶ ↑
This method will sanitize the binaries entry, @_. We must keep the binaries in Array format.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 215 def sanitize_binaries _ = binaries? # Obtain a pointer. _ = [] if _.nil? if _.is_a?(String) and !_.empty? _ = _.split(',') elsif _.is_a? String _ = [_] end if _.is_a? Array if _.first.include? ',' # Assume that we must split then. _.map! {|entry| entry.split(',') } end if _.first end _ = _.flatten.compact.map(&:strip) set_binaries(_) end
#¶ ↑
#sanitize_blfs_entry¶ ↑
This method will clean up the BLFS entry, should it exist.
It must be guaranteed to be an Array.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 169 def sanitize_blfs_entry if has_key? :blfs _ = blfs? unless _.is_a? Array if _.nil? _ = [] elsif _.empty? _ = [] # Empty Array then. else _ = [_] end set_blfs _ end else set_blfs [] end end
#¶ ↑
#sanitize_configure_base_dir¶ ↑
We must ensure that this variable has a trailing / character.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 129 def sanitize_configure_base_dir if configure_base_dir? unless configure_base_dir?.empty? set_configure_base_dir rds(configure_base_dir?+'/') end end end
#¶ ↑
#sanitize_configure_command¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 398 def sanitize_configure_command _ = configure_command? if _ if _.empty? set_configure_command 'configure' # set default, reset every time. else _ = ConvertGlobalEnv[_] if _.include? '$' set_configure_command(_) end else if _.include? '$' _ = ConvertGlobalEnv[_] end set_configure_command(_) # set rescue. end end
#¶ ↑
#sanitize_configure_options (configure tag)¶ ↑
Work on the configure options, i.e. @dataset.
Note that this depends on #program_version? having been set properly.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 477 def sanitize_configure_options _ = configure_options?.to_s.strip # Don't want empty thingies here. # ======================================================================= # # Get rid of multi-blanks next. # ======================================================================= # if _ _.squeeze!('/') _.gsub!(/#{N}/,' ') end # ======================================================================= # # Treat 'VERSION' as a macro, for expansion. # ======================================================================= # if _.include? 'PROGRAM_VERSION' _.gsub!(/PROGRAM_VERSION/, program_version?.to_s) if _ elsif _.include? 'VERSION' _.gsub!(/VERSION/, program_version?.to_s) if _ end # ======================================================================= # # Treat 'CURRENT' as a macro, for expansion. # ======================================================================= # if _.include? 'CURRENT' _.gsub!(/CURRENT/, program_version?.to_s) if _ end # ======================================================================= # # === NAME_OF_THE_DISTRIBUTION # ======================================================================= # if _.include? 'NAME_OF_THE_DISTRIBUTION' name = YAML.load_file( project_yaml_directory?+'configuration/name_of_the_distribution.yml' ) _.gsub!(/NAME_OF_THE_DISTRIBUTION/, name) end unless _.empty? # ======================================================================= # # Finally, run through the configure options. If they start with # enable or disable, with or without, we prepend -- if this is not # yet the case. Since Sep 2011, we will always prepend --, unless # the first character already is a '-' (this is done to # ======================================================================= # _ = _.split(' ').map {|configure_option| # If configure_option =~ /^disable|enable|with|without/ # =================================================================== # # Only add when not yet first char is NOT a '-'. # =================================================================== # unless configure_option.start_with? '-' or configure_option.start_with? '$' configure_option = '--'+configure_option end # end configure_option }.join(' ') end _ = _.tr(N, ' ') # Replace all newlines again. set_configure_options(_) # Last but not least, reassign. end
#¶ ↑
#sanitize_description (description tag, desc tag)¶ ↑
Get rid of trailing newlines in our description, and apply some other operations.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 1073 def sanitize_description _ = description?.to_s.chomp _.chop! if _.end_with? '"' # Get rid of leading and trailing ". _[0,1] = '' if _.start_with? '"' # ======================================================================= # # Some macros have to be expanded before we invoke substitute_macros(). # SELF_NAME is such an example. # ======================================================================= # if _.include? 'SELF_NAME' _.gsub!(/SELF_NAME/, short_name?) end _ = substitute_macros(_) begin # Replace newlines with ' ' characters. _ = _.gsub(/#{N}/,' ').squeeze(' ') rescue Exception => error cliner { opnn; e 'An error happened for the description:' pp @_ pp error } end # ======================================================================= # # Next, if this is empty, but short_description? is not, then # simply copy-paste the content of short_description? onto # the main program description. # ======================================================================= # if _.to_s.empty? and !short_description?.to_s.strip.empty? _ = short_description?.dup end set_description _ end
#¶ ↑
#sanitize_env_variables¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 337 def sanitize_env_variables _ = env_variables? if _ and _.is_a? Array # Must also check for nil. # ===================================================================== # # If it is an Array, then it must be wrong, so correct this here # silently. We need a Hash, as specified in the specification. # ===================================================================== # hash = {} _.each {|inner_hash| if inner_hash.is_a? Hash key = inner_hash.keys.first value = inner_hash.values.first hash[key] = value end } set_env_variables(hash) end end
#¶ ↑
#sanitize_headers (headers tag)¶ ↑
This method was added as of May 2014.
The headers entry must be kept as an Array.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 1009 def sanitize_headers _ = headers? if _.is_a? Array if _.first.include? ',' _ = _.first.split(',') end if _.first end if _.is_a? String _ = _.to_s.strip _ = _.split(',') if _.include? ',' _ = nil if _.empty? end _ = [_] unless _.is_a? Array _ = _.flatten.compact # ======================================================================= # # The individual entries may have a newline or an empty String at # the beginning. The next line of code ensures that we will get # rid of these. # ======================================================================= # _.map! {|entry| entry.delete(N).strip } # ======================================================================= # # Must keep it sorted, since as of July 2017. # ======================================================================= # _.sort! set_headers(_) end
#¶ ↑
#sanitize_last_update_entry¶ ↑
The only sanitize-operation we do here is if it is an valid date such as “32 Aug 2017”.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 598 def sanitize_last_update_entry _ = last_update? if _.include? ' ' splitted = _.split(' ') day = splitted.first if day.to_i > 31 opnn; e swarn('The last_update entry for ')+sfancy(program_name?)+ swarn(' is wrong (too high).') opnn; e swarn('Please correct this entry.') # =================================================================== # # We could exit here but this is mostly an annoyance rather than # a bug, so we continue. # =================================================================== # end elsif _.count('.') == 2 # Input such as '24.09.2017' splitted = _.split('.') splitted[1] = return_month_based_on_this_number(splitted[1])[0,3] # This is the month but only the first 3 characters. _ = splitted.join(' ') set_last_update(_) end end
#¶ ↑
#sanitize_libraries¶ ↑
This sanitizes the libraries entry, @_.
We must keep this entry in Array format.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 239 def sanitize_libraries _ = libraries? unless _.is_a? Array _ = [_].compact end # ======================================================================= # # Next, we will assume something such as: # ["libdevkit-power-gobject.{so,a},libupower-glib.{so,a}"] # ======================================================================= # unless _.empty? # safeguard against nil entries. if _.first.include?('}') and _.first.include?('{') splitted = _.first.split(/\},/) splitted.map! {|entry| entry =~ REGEX_TO_SANITIZE_LIBRARIES [$1+'.'+$2, $1+'.'+$3] } splitted.flatten! _ = splitted end end if _.is_a? Array if _.first.include? ',' _ = _.first.split(',') _.map!(&:strip) # It should not include empty whitespace. # =================================================================== # # Some libraries may have components such as foo{so.a} # We need to split these up into foo.so and foo.a. # =================================================================== # end if _.first end new_value = [] # default. new_value = [_].flatten unless _.empty? new_value.compact! if new_value.is_a? Array set_libraries(new_value) end
#¶ ↑
#sanitize_license¶ ↑
Empty license should default to “unknown” license. This method will ensure that this is the case.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 803 def sanitize_license _ = licence? begin if _.nil? or _.empty? set_licence('unknown') else if _.is_a?(String) and _.include?(',') # <- In this case, turn it into an Array. set_licence(_.split(',').map(&:strip)) end end rescue Exception => error opnn; e 'An error happened.' pp data? pp error pp error.class opnn; e 'Exiting now - this error (in sanitize_license()) '\ 'should be fixed though.' exit end end
#¶ ↑
#sanitize_make_options¶ ↑
This method will sanitize the make options used for a given program.
Special macros can be used as part of the make options.
For instance:
MY_PROGRAMS/Procps/PROGRAM_VERSION
Will be expanded to whatever value MY_PROGRAMS was set to; usually it is, or should be, pointing towards “/Programs/”.
Do also note that this means that the value for MY_PROGRAMS must exist, otherwise this can not possibly work. Of course you can omit using macros and just hardcode values there.
Another example for macro-conversion would be the String 'RINSTALL1', which will become expanded into the following three actions:
ruby install.rb config ruby install.rb setup ruby install.rb install
The latter expansions are part of the file:
predefined_installation_instructions.yml
So if you want to add new macros, you can do so by modifying that yaml file.
The #make_options need to be An array in the end.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 1153 def sanitize_make_options _ = make_options? _ = 'make' if _.nil? || _.empty? # <- Use "make" this as default value if empty. _ = [_] unless _.is_a? Array # ========================================================================= # # Past this point here we have an Array. # ========================================================================= # unless _.empty? _.map! {|line| line = line.dup if line.frozen? line.strip! # =================================================================== # # Next, replace all ',' with ';' characters. # =================================================================== # line.tr!(',',';') if line.include? ',' if Object.const_defined? :ConvertGlobalEnv line = ConvertGlobalEnv[line] if line.include? '$' end # =================================================================== # # === Replace the predefined installation instruction next # =================================================================== # if PREDEFINED_INSTALLATION_INSTRUCTIONS.include? line line = PREDEFINED_INSTALLATION_INSTRUCTIONS[line] end if line.include? 'VERSION' # ================================================================= # # Need to set @program_version first, hence we update some stuff. # ================================================================= # set_program_name(program_name?) # This equals, for example, to "gnome-mahjonng-5.08" if line.include? 'PROGRAM_VERSION' line.gsub!(/PROGRAM_VERSION/, program_version?) if program_version? elsif line.include? 'VERSION' line.gsub!(/VERSION/, program_version?) if program_version? end end line = line.split(';') if line.include? ';' # This may turn it into an Array. line } end _.flatten! set_make_options(_) end
#¶ ↑
#sanitize_postinstall¶ ↑
This will sanitize the postinstall stuff, by assigning to the respective entry in the main Hash.
Note that we have to invoke this method only after real_short_name and #program_version was set, because one entry requires this.
As of 20.09.2014, postinstall must be an Array.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 51 def sanitize_postinstall _ = postinstall? if _.nil? # Safeguard to ensure Array. set_postinstall [] _ = postinstall? end _.compact! if _.is_a? Array # Get rid of nil values. unless _.empty? if _.is_a? Array _.map! {|entry| substitute_macros(entry) } end _.gsub!(/#{N}/,',') if _.include?(N) # Replace newlines with ',' char. # ======================================================================= # # Replace universal targets with real targets. # ======================================================================= # case prefix? when false # Yup. Only one option for false.. point_to_libraries = SYSLIB_DIR point_to_binaries = SYSBIN_DIR point_to_includes = SYSINCLUDE_DIR point_to_program_dir = rds( # Remove double slashes. programs_dir?+ real_short_name?.to_s.capitalize+'/'+ program_version?.to_s+'/bin' ) when true # =================================================================== # # FHS installation method comes here. It will defaults to /usr/bin. # It also includes true of course. # =================================================================== # point_to_libraries = '/usr/lib' point_to_binaries = '/usr/bin' point_to_includes = '/usr/include' point_to_program_dir = point_to_binaries else point_to_libraries = "{prefix?}lib" point_to_binaries = "{prefix?}bin" # For example, /Programs/Glib/2.40.0/bin/ point_to_includes = "{prefix?}include" point_to_program_dir = point_to_binaries end if _.is_a? String _ = [_] end # ======================================================================= # # Sanitize the @postinstall variable next. # ======================================================================= # if _.is_a? Array _.map! {|entry| if entry.include? 'UNIVERSAL_BINARY_DIR' entry.gsub!(/UNIVERSAL_BINARY_DIR/, point_to_binaries) end entry.gsub!(/UNIVERSAL_BINARIES_DIR/, point_to_binaries) entry.gsub!(/UBD/, point_to_binaries) entry.gsub!(/UNIVERSAL_LIBRARIES_DIR/, point_to_libraries) entry.gsub!(/ULD/, point_to_libraries) entry.gsub!(/UNIVERSAL_INCLUDE_DIR/, point_to_includes) entry.gsub!(/PROGRAM_DIR/, point_to_program_dir) entry.gsub!(/PROGRAMS_DIR/, point_to_program_dir) entry.gsub!(/,cp/, ',copy_file') entry.strip! # Strip it. entry = rds(entry) # Replace // with // here. entry } set_postinstall _ # Reassign. end end unless postinstall?.is_a? Array _ = rds(postinstall?) _ = _.split(',') if _.include? ',' set_postinstall [_].flatten end end
#¶ ↑
#sanitize_pre_make_commands¶ ↑
We must keep the #pre_make_commands in Array format. The method here will make sure of this.
We can only invoke this after having set #program_version before, because some macro-substitutions require the program version to be properly set before the make-commands can be sanitized.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 147 def sanitize_pre_make_commands _ = pre_make_commands? _.compact! if _.is_a? Array # Get rid of nil values. array = [] if _ unless _.empty? _ = substitute_macros(_) array << _ end end array.flatten! array.compact! set_pre_make_commands(array) # Turn it into an Array here. end
#¶ ↑
#sanitize_prefix (sanitize prefix tag)¶ ↑
The value for the prefix of the program at hand will be sanitized here, in this method.
Since as of May 2013, we will never use a shortcut anymore, we will always store the full, absolute path to our entry.
“false” as value, is an indication of using the path to an AppDir. For example, this would be something such as /Programs/Htop/2.0.0 - that would be a proper appdir.
The –prefix is always a directory, so as of Jan 2014 we will append a / to this unless the last character is already a /.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 549 def sanitize_prefix _ = prefix?.dup # ======================================================================= # # General way to overrule the prefix setting in this case. # ======================================================================= # _ = false if COMPILE_EVERYTHING_INTO_STANDALONE_DIRECTORY if _.is_a?(FalseClass) or _.is_a?(TrueClass) _ = _.to_s end _ = _.to_s.dup if _.is_a? String case _ when 't','true','yes','y','traditional' _ = '/usr/' when 'f','false','no','AppDir','return_appdir_path','appdir_path' _ = return_appdir_prefix.dup # <- This is the AppDir variant. end if _.is_a? String _ = _.dup if _.frozen? # Unfreeze it. # =================================================================== # # As of January 2014, we will pass the String through the macro-check, # which has to be done because our string may include PROGRAM_NAME as # a prefix. # =================================================================== # _ = substitute_macros(_).dup # =================================================================== # # Append '/' unless we already have a trailing '/'. # =================================================================== # _ << '/' unless _.end_with? '/' _.gsub!(/ULOCAL/,'/usr/local') if _.include? 'ULOCAL' # ULOCAL gets expanded to /usr/local _.gsub!(/ULOC/, '/usr/local') if _.include? 'ULOC' # same counts for ULOC # =================================================================== # # We used to delete '-' here in the past, but as of Sep 2017 this # is no longer the case. Some programs may have a '-' as part of # the program version, and it may be better to include this rather # than remove it. # =================================================================== # # _.delete!('-') if _.include? '-' end set_prefix(_) end end
#¶ ↑
#sanitize_preinstall¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 190 def sanitize_preinstall _ = preinstall? if _.is_a?(String) and (_.count(N) > 1) _ = _.split(N) end if _.nil? # Safeguard to ensure Array. set_preinstall [] else _ = [_] if _.is_a? String if _.is_a? Array _.compact! _.map!(&:strip) _.reject! {|entry| entry.empty? } # Weed out empty entries. _.flatten! end set_preinstall _ end end
#¶ ↑
#sanitize_program_compile_name¶ ↑
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 359 def sanitize_program_compile_name _ = program_compile_name? if are_we_on_gobolinux? and !use_this_program_name_on_gobolinux?.to_s.empty? _ = use_this_program_name_on_gobolinux? end set_program_compile_name(_.to_s) # Will always be at the least an empty String. end
#¶ ↑
#sanitize_program_name¶ ↑
This method can be used to sanitize the #program_name entry.
The #program_name entry is something such as 'gnome-mahjonng-5.08'.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 627 def sanitize_program_name _ = program_name?.dup # Obtain a reference-copy first. i = return_sanitized_program_name(_) set_program_name(i) # And set the new variant. end
#¶ ↑
#sanitize_required_deps¶ ↑
The entry required_deps_on will be sanitized here - it must be an Array at all times.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 747 def sanitize_required_deps _ = required_deps_on? if _.is_a?(String) # Input such as 'perl cmake'. Has to become an Array. if _.include? ' ' unless _.include?('>') or _.include?('<') # But not when we have comparison-operators. _ = _.split(' ') end end end array = [] _ = [_] unless _.is_a? Array # Must be an Array. _.compact! _.map! {|entry| if entry.include? ',' entry = entry.split(',').map(&:strip) end entry } unless _.empty? _ = [] if _.nil? # Safeguard to keep this as an Array. array << _ array = array.flatten.compact # ======================================================================= # # At this point the entry is a sanitized Array. But the cookbook # file may still have made a mistake, such as when an entry # was accidentally listed twice. (I had this problem in Feb # 2017, which was why I added the following code.) # So we need to check whether the entries are all unique - and # if they are not, we will notify the user that something may # be wrong with the yaml file in question. # ======================================================================= # if array.uniq.size != array.size path = Cookbooks.individual_cookbooks_dir?+program?+'.yml' non_unique_entries = array.uniq.map { |e| [array.count(e), e] }.select { | c, _ | c > 1 }.sort.reverse.first.last unless non_unique_entries.is_a? Array non_unique_entries = [non_unique_entries] # We need an Array. end opnn; e swarn('There may be one (or several) duplicate dependencies '\ ' listed in the yaml file.') opnn; e swarn(' Path: ')+sfile(path) opnn; e swarn('Here are the duplicate entries:') non_unique_entries.each {|duplicate_entry| e ' '+simp(duplicate_entry) } e swarn('If you wish to check for that on your own, have a look at the') e swarn('yaml file at `')+sfile(path)+swarn('`.') e swarn('Check the "required_deps_on:" entry of the .yml file.') end set_required_deps_on(array) end
#¶ ↑
#sanitize_use_this_make_command¶ ↑
This will default to whatever is stored in the configuration file.
Should be 'make' usually, but could be “cmake” or another make-like command.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 1204 def sanitize_use_this_make_command if use_this_make_command?.to_s.empty? set_use_this_make_command(MAKE_COMMAND_TO_USE) # MAKE_COMMAND_TO_USE is defined in constants.rb end end
#¶ ↑
#sanitize_yaml_dataset (sanitize tag, sani tag)¶ ↑
Sanitize the whole yaml dataset. Note that some entries have to come in a specific order.
This method must ensure that the mandatory entries will exist in the main yaml dataset.
Additionally, we will run various sanitize-commands, through subsequent method calls.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 905 def sanitize_yaml_dataset set_default_raw_description sanitize_libraries sanitize_binaries if url1? and (short_name?.nil? or short_name?.empty?) guess_entries_based_on_the_first_url end sanitize_blfs_entry sanitize_required_deps sanitize_license sanitize_preinstall sanitize_use_this_make_command sanitize_pre_make_commands sanitize_configure_options sanitize_configure_command sanitize_configure_base_dir sanitize_url sanitize_apply_patch sanitize_short_description sanitize_headers sanitize_make_options sanitize_description sanitize_extra_information sanitize_tags sanitize_env_variables sanitize_last_update_entry sanitize_has_to_be_compiled try_to_sanitize_sed_entry sanitize_base_dir sanitize_program_compile_name sanitize_program_name sanitize_program_path sanitize_skip_configure # ======================================================================= # # The prefix setting can only be sanitized after the program_version # has been sanitized, since the actual prefix may depend on the # program version in use, such as for AppDirs. # ======================================================================= # sanitize_prefix # Must come BEFORE sanitize_postinstall. # ======================================================================= # # === sanitize_postinstall # # sanitize_postinstall should only be called after the prefix was # already defined, since a few internal-parts of the method # sanitize_postinstall may need to know the real prefix in use. # ======================================================================= # sanitize_postinstall unless File.exist? program_path? # ===================================================================== # # Try to see whether we can modify archive_type, in order to find # a proper match. # ===================================================================== # target = base_dir?+'*' possible_matches = Dir[target] unless possible_matches.empty? # =================================================================== # # This means we may have found another archive. # =================================================================== # first_entry = possible_matches.first # Obtain an entry to it. set_archive_type(File.basename(first_entry)) # =================================================================== # # Check whether the program name is like 'apt_1.2.1' # =================================================================== # if program_name.include?('_') and !program_name.include?('-') unless File.basename(first_entry).include?('_') name, version = ProgramInformation.return_name_and_version_of(File.basename(first_entry)) set_short_name(name) set_program_version(version) use_default_connective_token_again assemble_program_name end end sync_archive_type_entries # This method will also update the program path. end end if archive_type?.empty? and !program_name?.empty? try_to_guess_the_archive_type end # ======================================================================= # # Do some syncing next - first, make sure that the program_full_name # setting is not empty. # ======================================================================= # if program_full_name?.empty? sync_archive_type_entries end # ======================================================================= # # Last but not least, find out the file size of the program in question. # ======================================================================= # calculate_archive_size calculate_md5sum if shall_we_display_the_md5sum? # ======================================================================= # # Last but not least, delete the array that holds the invalid keys, # since this information will no longer be relevant. # ======================================================================= # cleanup_unusued_variables end
#¶ ↑
#set_archive_type (archive tag, 4 tag)¶ ↑
This method will set the 'archive_type' of a given program at hand.
This is entry number (4), such as '.tar.xz' in a program like 'gnome-mahjonng-5.08.tar.xz'.
Typically, archives will be kept in the .tar.xz format, or rather the content of the constant DEFAULT_ARCHIVE_TYPE. We need this part when we wish to assemble the #program_full_name setting lateron, at entry number (7).
#¶ ↑
# File lib/cookbooks/class/set.rb, line 607 def set_archive_type(i = DEFAULT_ARCHIVE_TYPE) case i when nil, :default, 'default' i = DEFAULT_ARCHIVE_TYPE # Safeguard. end i = i.to_s.dup.downcase # Keep it downcased as well, and in String format. # ======================================================================= # # === Get rid of '/' # ======================================================================= # if i.include? '/' i = File.basename(i) end # ======================================================================= # # Do some sanitizing next. # ======================================================================= # i.sub!(/\.source$/,'') if i.include? '.source' # ======================================================================= # # If the input includes a '-' token, then something can not be right. # ======================================================================= # if i.include? '-' i = i[(i.rindex('-')+1)..-1] # ======================================================================= # # Same for input containing '_'. # ======================================================================= # elsif i.include? '_' i = i[(i.rindex('_')+1)..-1] end if i == 'guess' i = File.basename(url?) end i = return_archive_type(i) # This method must have registered all archive-types. set(:archive_type, i) end
#¶ ↑
#set_autoconf¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 201 def set_autoconf(i) set(:use_autoconf, i) end
#¶ ↑
#set_base_dir (base_dir tag, base dir tag, 5 tag)¶ ↑
This setter will set the base_directory setting, which is entry number (5).
An example for a proper base_directory setting would be a String such as this one here:
"/Users/x/SRC/file/"
If the input is :guess_base_dir then this means that we will try to guess the base directory.
Also note that real_short_name? should be set before calling this method, in some situations.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 1053 def set_base_dir( i = source_dir?+ real_short_name?.downcase.delete('.')+ # Note that the base_dir part is not allowed to have any '.' characters. '/' ) case i when :guess_base_dir, :guess i = guess_base_dir end # ======================================================================= # # We don't want any '-' in the base_dir name. # ======================================================================= # i.delete!('-') if i.include? '-' # ======================================================================= # # === Delete _ from the name of the directory # # Added the following code as of January 2014. While programs can have # names such as 'e_dbus', the directory name itself is not allowed # to contain any '_' token. It looks visually odd otherwise. # ======================================================================= # i.delete!('_') if i.include? '_' # ======================================================================= # # === Handle + tokens # # Some directory names may include a '+' character, such as is the # case with gtk+. There are several ways how to deal with this, but # if we have a certain configuration option set, then we will # replace '+' with long name, which is 'plus'. I personally no # longer use this - my directory names will also include a '+' # character as a consequence. # ======================================================================= # if i.include? '+' i.gsub!(/\+/, 'plus') if replace_plus_with_long_name? end i = rds(i) # Remove double slashes # ======================================================================= # # Assume that a path starting with ./ is never correct. # ======================================================================= # if i.start_with? './' i[0,2] = source_dir? end # ======================================================================= # # === Append / # # It is the correct way to ensure that the last char is a /. The # reason is: directories contain a '/' as part of their name. # ======================================================================= # i << '/' unless i.end_with? '/' set(:base_dir, i) end
#¶ ↑
#set_commandline_arguments¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 854 def set_commandline_arguments(i = '') # ======================================================================= # # Keep track of the commandline arguments in the main Hash of this class. # ======================================================================= # @internal_hash[:commandline_arguments] = i if i.is_a? Array i = i.join(' ').strip end i = i.to_s.dup i.delete!('-') if i.include? '-' # ======================================================================= # # And then, we will seek for this program. # ======================================================================= # set_search_for_this_program(i) end
#¶ ↑
#set_complex_program_version¶ ↑
The purpose of this method is to allow you to overrule the respective settings, at run-time.
That way, you can change e. g. “glib-2.24” to “glib-2.25”.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 285 def set_complex_program_version( i, be_verbose = true ) case be_verbose when :be_quiet, :be_silent be_verbose = false end # ======================================================================= # # Add a '=' to make it easier to know what we want to modify. # ======================================================================= # i.prepend '=' unless i.include? '=' # ======================================================================= # # Next, we fetch a specific version. We assume this to be the last part # of the command given, which must include a '=' character. # ======================================================================= # new_version = i.split('=').last # ======================================================================= # # Chop off archive-extension since we don't need these. # ======================================================================= # new_version = remove_file_extension(new_version) if be_verbose opnn; e 'Setting a new version: '+simp(new_version) end set_program_version(new_version, :propagate_the_change) # The second argument will propagate the change, by cascading downwards. update_prefix :bypass_check end
#¶ ↑
#set_configure_command¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 238 def set_configure_command(i) set(:configure_command, i) end
#¶ ↑
#set_configure_options¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 542 def set_configure_options(i) # ======================================================================= # # Since as of September 2017, the input is no longer allowed to have # any newlines. This is explicitely mentioned here in the event that # we may have to rever this decision one day. # ======================================================================= # if i.include? N i.delete!(N) i.squeeze!(' ') # And also get rid of ' ' variants. end set(:configure_options, i) end
#¶ ↑
#set_env_variables?¶ ↑
Query the environment variables that this cookbook may set.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 628 def set_env_variables? obtain(:set_env_variables) end
#¶ ↑
#set_extract_to¶ ↑
Consistently use this method when you wish to use the extract_to variable.
This variable must ALWAYS keep the location of where to extract a package to lateron.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 384 def set_extract_to(i = TEMP_DIR) i = TEMP_DIR if i.nil? # default. i = i.dup # We don't want to keep a tainted reference. # ======================================================================= # # Ensure that we have a proper default value if the input was ''. # ======================================================================= # i = extract_to? if i.to_s.empty? # ======================================================================= # # Try to get an ENV variable here, if ENV is part of @extract_to. # ======================================================================= # if i.include? 'ENV' match = i.gsub(/ENV\['/,'').gsub(/'\]/,'') # contains the ENV variable i = ENV[match].dup end # ======================================================================= # # append / if the last character is not '/' # ======================================================================= # i << '/' unless i.end_with? '/' set(:extract_to, i) end
#¶ ↑
#set_in_yaml_dataset (set tag, setter tag)¶ ↑
This is the main setter for the yaml dataset.
Note that you can also use it to set several subsequent entries.
We will also batch-update if you send in a String that contains ','.
An example for this would be the following:
set '4,5,6,7,8'
#¶ ↑
# File lib/cookbooks/class/set.rb, line 33 def set_in_yaml_dataset( key, new_value = nil ) if key.is_a? Array # Recursive invocation in this case. key.flatten.each {|inner_key| set(inner_key, new_value) } elsif key.is_a?(String) and key.include?(',') key.split(',').each {|inner_entry| set(inner_entry, new_value) # Recursive calling then. } elsif key.is_a?(String) and key.include?('-') # Ok, we have a range here such as 2-5, meaning to update 2,3,4,5. splitted = key.split('-') min, max = splitted[0].to_i, splitted[1].to_i min.upto(max) {|entry| set(entry) } else # ===================================================================== # # All keys in the yaml_dataset have to be kept as Strings, for now. # This may change one day but for now, it will remain how it is. # ===================================================================== # key = key.to_s unless key.is_a? String # ===================================================================== # # After this point, all keys will be Strings. We must be careful when # we apply rds() - valid URLs may contain '//'. # ===================================================================== # if new_value and new_value.is_a? String # Only sanitize Strings. if new_value.include?('//') and !new_value.include?('http://') new_value = rds(new_value) end end # ===================================================================== # # Next set some aliases for keys issued. # ===================================================================== # case key when '1' key = 'real_short_name' when '2' key = 'short_name' when '3','version',/program_?version/ key = 'program_version' when '4' key = 'archive_type' when '5','dir' key = 'base_dir' when '6' key = 'program_name' when '7' key = 'program_full_name' when '8','program_full_path' key = 'program_path' end # ===================================================================== # # Store in the internal Hash. The internal Hash must always exist, # for this to work. # ===================================================================== # @internal_hash[:yaml_dataset][key] = new_value end end
#¶ ↑
#set_keep_extracted¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 252 def set_keep_extracted(i) set(:keep_extracted, i) end
#¶ ↑
#set_licence¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 770 def set_licence(i) set(:licence, i) end
#¶ ↑
#set_make_use_of_aliases_kept_in_the_file_cookbook_aliases¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 988 def set_make_use_of_aliases_kept_in_the_file_cookbook_aliases(i) case i when :nope, :user_disabled_this_setting_via_the_commandline i = false end @internal_hash[:make_use_of_aliases_kept_in_the_file_cookbook_aliases] = i end
#¶ ↑
#set_pkgconfig_files¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 182 def set_pkgconfig_files(i) unless i.is_a? Array i = [i] end set(:pkgconfig_files, i) end
#¶ ↑
#set_prefix¶ ↑
Use this method to set towards a specific prefix, such as '/usr/'.
This is then the option that will be passed into scripts such as 'configure' or cmake-based systems.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 515 def set_prefix(i = '/usr/') case i when :appdir i = return_appdir_path end set(:prefix, i) end
#¶ ↑
#set_program_full_name¶ ↑
We combine #program_name? and #archive_type? here.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 427 def set_program_full_name( i = return_program_full_name ) set(:program_full_name, i) end
#¶ ↑
#set_program_name (entry number 6)¶ ↑
The program name of a program might be something such as this:
gnome-mahjonng-5.08 file-5.05
So in other words, this is entry number (6) and it will combine the two entries (2) and (3):
short_name?+'-'+program_version?
A '-' is usually required as separator for a proper “program_name” entry, about at the least in 99.5% of the programs out there in the wild. They usually include a '-' as part of the program name. Note that there are some weird exceptions such as “boost_1_59_0”.
Consistently use this and ONLY this method when modifying the 'program_name' entry in the main dataset.
One more question should be answered - why do we use real_short_name? rather than #short_name?
We need to use real_short_name? because some other settings may require input without any '-' as part of their name.
Some other programs require to have a '_' as part of the program name.
This can lead to problems such as for those programs that have a _ as part of their name. A good example is the name “e_dbus”, which includes includes a '_' token as part of its name.
In Jan 2014, I realized that eliminating '_' is too much of a hassle, so I disabled it again. I will retain the explanation above though, in the event that future programmers - or future me - may encounter similar problems.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 681 def set_program_name(i = return_program_name) # ======================================================================= # # A program name never has a '/'. # ======================================================================= # if i.include? '/' i = File.basename(i) end i = remove_file_extension(i) if i.include? '.' # <- Added this as of Nov 2013. case i when 'URL_REPLACE_UNDERSCORE' i = url?.to_s.dup when '', nil, :assemble, :guess # Then we assemble it for these two conditions. assemble_program_name # In these cases, we will try to guess the name. end i = i.to_s.dup # if i.include?('_') and !i.include?('-') # i.tr!('_','-') # end # ^^^ this line would break artemis. set(:program_name, i) end
#¶ ↑
#set_program_path (8 tag)¶ ↑
The #program_path is composed of these two elements:
- base_dir? - program_full_name?
It would look like this:
'/Users/x/SRC/gnomemahjongg/gnome-mahjonng-5.08.tar.xz'
In other words, it will add (5) + (7).
It is the most important entry, containing everything - which is the major goal for the class here.
The full #program_path will look such as:
'/Users/x/SRC/file/file-5.08.tar.xz' '/Users/x/SRC/gnomemahjongg/gnome-mahjonng-5.08.tar.xz'
The two main components are thus:
(5) base_dir, such as: "/Users/x/SRC/file/" (7) program_full_name, such as: "file-5.08.tar.xz"
#¶ ↑
# File lib/cookbooks/class/set.rb, line 825 def set_program_path(i) set(:program_path, i) end
#¶ ↑
#set_program_version (version tag)¶ ↑
This method will set the program_version.
Use this method whenever you wish to modify the version of the program, which is entry number (3), like:
"5.08"
# ¶ ↑
# File lib/cookbooks/class/set.rb, line 752 def set_program_version(i) i = i.to_s.dup # Work on a copy. i.sub!(/-source$/,'') if i.include? '-source' i.sub!(/\.src/,'') if i.include? '.src' i.sub!(/-Source/,'') if i.include? '-Source' i = chop_off_archive(i) i = remove_file_suffix(i) # Added this as of Jan 2014. if i.include? '#' # This is an illegal character as of Apr 2014. i = i[0, i.index('#')] end set(:program_version, i) end
#¶ ↑
#set_programs_dir¶ ↑
This can set to another directory than '/Programs'.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 224 def set_programs_dir(i = '/Programs/') @internal_hash[:programs_dir] = i end
#¶ ↑
#set_real_short_name¶ ↑
This method should be used to set the value for the 'real_short_name'.
The real short name entry entry may not include any '-' characters.
Since Jan 2014 we also get rid of '_' characters - this is experimental though and may be subject to change.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 266 def set_real_short_name( i = short_name? # 1 tag ) if i i = i.to_s.dup # Work on a copy to avoid side-effects. i.delete!('-') if i.include? '-' i.delete!('_') if i.include? '_' end set(:real_short_name, i) end
#¶ ↑
#set_required_deps_on¶ ↑
Set the required dependencies for a program through this method.
Note that this method will not do any sanitizing - you have to sanitize the input on your own prior to calling this method.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 1004 def set_required_deps_on(i) set(:required_deps_on, i) end
#¶ ↑
#set_search_for_this_program¶ ↑
Set the main program to work with. In other words, we will seek this program in the cookbooks “database”.
This should always be at least a String.
Keep in mind that the input to this method may also be in the form of a String such as “php.yml”. In that case, we have to get rid of the trailing '.yml' part.
Additionally, do note that the input could be a binary name or a library name. In these two cases, we may overrule the input provided but this can be configured via some settings.
Since as of Sep 2012, aliases can overrule this setting. This however may lead to problems, such as “make” suddenly becoming “makeinfo” rather than being kept as make.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 890 def set_search_for_this_program( i = DEFAULT_ENTRY ) i = i.keys.first if i.is_a? Hash i.flatten! if i.is_a? Array # Keep it flattened. i = DEFAULT_ENTRY if i.nil? i = i.first if i.is_a? Array i = i.to_s.dup # Work on a reference copy. # ======================================================================= # # Pass the input into the menu() here, but only if we will use the # menu interface. # ======================================================================= # menu(i) if @use_menu_interface i.delete!('-_') # Neither '-' nor '_' are allowed as input. if i.include? '.' i.sub!(/#{File.extname(i)}/,'') end # ======================================================================= # # We will also chop off trailing '/' characters. A trailing '/' is # assumed to have been a typo. Nobody will call a file or input # program something such as 'libgweather/'. # ======================================================================= # i.chop! if i.end_with? '/' # ======================================================================= # # === Next check for entries that lack a leading 'lib' entry # ======================================================================= # unless does_include?(i, :do_not_check_for_aliases) if does_include?('lib'+i, :do_not_check_for_aliases) opnn; e 'The given input '+sfancy(i)+' is not included '\ 'but '+sfancy('lib'+i)+'. is.' opnn; e 'Thus using this as the new input next.' i.prepend('lib') end end all_binaries = all_binaries? all_libraries = all_libraries? # ======================================================================= # # === Handle possible binary names next # # Here we will check for binary names of programs, but only if the input # has not yet been found as regular name of a registered program at # hand. As this is not always needed anyway, we will use various checks # to make sure that we really want to find a binary name. # # In order to test this, try: # cookbooks2 xmlif # ry xmlif # ======================================================================= # if !does_include?(i) and check_for_binary_names? and all_binaries.has_key?(i) and (i != all_binaries[i]) new_name = all_binaries[i] report_binary_or_library_program_name(i, new_name, :binary) i = new_name # ======================================================================= # # === Check for library names # # Similar reasoning applies to this entry point, as to the one above # for binary names. # ======================================================================= # elsif !does_include?(i) and check_for_library_names? and all_libraries.has_key?(i) and (i != all_libraries[i]) new_name = all_libraries[i] report_binary_or_library_program_name(i, new_name, :library) i = new_name end # ======================================================================= # # === Check for Abbreviations if the key was not found # ======================================================================= # unless does_include?(i, :do_not_check_for_aliases) unless i.empty? # =================================================================== # # Ok, we did not find anything, so check for abbreviations. # =================================================================== # available_programs = available_programs? require 'abbrev' unless Object.const_defined? :Abbrev abbrevs = Abbrev.abbrev(available_programs) if abbrevs.has_key? i # ================================================================= # # Ok, this means that our key is included. # ================================================================= # i = abbrevs.fetch(i) end end end # ======================================================================= # # Next, set it but not if it is empty. # ======================================================================= # unless i.empty? @internal_hash[:search_for_this_program] = i end end
#¶ ↑
#set_short_description¶ ↑
The short_description entry should not end with a newline.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 417 def set_short_description(i = nil) i.chomp! if i # We do not want trailing newlines. set(:short_description, i) end
#¶ ↑
#set_short_name¶ ↑
This method will set the #short_name entry in the main yaml_dataset.
The 'short_name' variable is allowed to include the '-' character, and if the '-' character is part of the program name in question, such as for a program like “gnome-commander”, then it must be retained in the method #set_short_name() here.
Numbers will be retained as well because they may be part of the #short_name, such as for the program called “dzen2”.
For the variant without '-' please see to the method #set_real_short_name() instead.
Valid input to this method could be something like:
"xfce4-dev-tools"
#¶ ↑
# File lib/cookbooks/class/set.rb, line 332 def set_short_name( i, # 2 tag also_set_other_names = true ) i = i.to_s.dup case also_set_other_names when :cascade_downwards, :cascade, :propagate_towards_real_short_name also_set_other_names = true when :do_not_cascade also_set_other_names = false end # ======================================================================= # # === Get rid of '/' # ======================================================================= # if i.include? '/' i = File.basename(i) end # ======================================================================= # # If the input includes .tar, check it further. # ======================================================================= # if i.include?('.tar') i = ::ProgramInformation.return_short_name(i) end set(:short_name, i) # ======================================================================= # # We can propagate only into (1) from this method, which is the # 'real_short_name' again. # ======================================================================= # if also_set_other_names set_real_short_name(i) # By default, sync when setting short_name. set_program_compile_name(i) # Also sync it here. end end
#¶ ↑
#set_symlink_headers¶ ↑
If we want to symlink the headers, this is the setter-method that should be called.
#¶ ↑
# File lib/cookbooks/class/set.rb, line 175 def set_symlink_headers(i = true) set(:symlink_headers, i) end
#¶ ↑
#set_symlink_pkgconfig_files¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 109 def set_symlink_pkgconfig_files(i = true) set(:symlink_pkgconfig_files, i) end
#¶ ↑
#set_use_build_directory¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 158 def set_use_build_directory(i) set(:use_build_directory, i) end
#¶ ↑
#set_use_glib_schema¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 192 def set_use_glib_schema(i = nil) if i set(:use_glib_schema, i) end end
#¶ ↑
#set_use_this_build_directory¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 130 def set_use_this_build_directory(i) set(:use_this_build_directory, i) end
#¶ ↑
#set_use_this_connective_token¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 720 def set_use_this_connective_token(i = '-') @internal_hash[:use_this_connective_token] = i end
#¶ ↑
#set_use_this_make_command¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 1018 def set_use_this_make_command(i) set(:use_this_make_command, i) end
#¶ ↑
#set_use_this_make_install_command¶ ↑
#¶ ↑
# File lib/cookbooks/class/set.rb, line 1025 def set_use_this_make_install_command(i) set(:use_this_make_install_command, i) end
#¶ ↑
shall_we_display_the_md5sum?¶ ↑
Query whether we shall display the md5sum or whether we shall not.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 188 def shall_we_display_the_md5sum? ihash?[:shall_we_display_the_md5sum] end
#¶ ↑
short_description?¶ ↑
This method will obtain the short description of a given program.
Not every program will have a short description, but it is recommended that all programs SHOULD have a short description.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 845 def short_description? obtain(:short_description) end
#¶ ↑
#short_name?¶ ↑
This method queries the short name of the program we are trying to find.
For example, this method will return the program name without the version, such as:
"ruby" (which is part of the program_name "ruby-2.2.0")
This method must always return a String, even if it is an empty String.
Characters such as '-' are allowed to be part of the #short_name variable.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 92 def short_name? obtain(:short_name) end
#¶ ↑
#show_all_available_program¶ ↑
To invoke this method, do:
cookbook --available_programs?
#¶ ↑
# File lib/cookbooks/class/feedback/feedback.rb, line 29 def show_all_available_program _ = available_programs? _.each_with_index {|name_of_the_program, index| index += 1 e (index.to_s+')').rjust(5)+' '+sfancy(name_of_the_program) } end
#¶ ↑
#show_available_aliases¶ ↑
To invoke this method, do:
cookbooks --aliases?
#¶ ↑
# File lib/cookbooks/class/class.rb, line 528 def show_available_aliases _ = Cookbooks.cookbook_aliases? opnn; e "The available #{sfancy(_.size.to_s)} aliases are:" index = 0 _.each_pair {|key, value| index += 1 colourized_index = slateblue((index.to_s+')').rjust(5)) e colourized_index+' '+sfancy(key.ljust(18))+ mediumseagreen(' -> ')+simp(value) } end
#¶ ↑
#show_help (help tag)¶ ↑
To invoke this particular method, try:
cookbook --help
To invoke individual entries, do:
cookbook nprograms? cookbook --overview cookbook --version
#¶ ↑
# File lib/cookbooks/class/help.rb, line 27 def show_help left_padding = ' ' # A bit of left-padding here. n_space_characters = 50 how_to_invoke_the_program = HOW_TO_INVOKE_THE_PROGRAM opnn; e 'This class can feedback information about any '\ 'specific program.' e # ======================================================================= # # === Common usage examples # ======================================================================= # e 'Common usage examples:' e e left_padding+how_to_invoke_the_program+' ruby' e left_padding+how_to_invoke_the_program+' htop' e left_padding+how_to_invoke_the_program+' m4' e # ======================================================================= # # === Advanced Options # ======================================================================= # e 'Advanced options:' e e properly_pad_and_colourize_this_help_option('nprograms?', 'show how many programs are registered in the cookbooks-collection' ) e properly_pad_and_colourize_this_help_option('--aliases?', 'show all available aliases to the registered cookbooks-programs' ) e properly_pad_and_colourize_this_help_option('--available_programs?', 'show all available programs' ) e properly_pad_and_colourize_this_help_option('--batch-download-all-source-archives', 'batch-download all source archives (optionally select for specific tags)' ) e properly_pad_and_colourize_this_help_option('--overview', 'give us an overview over all programs in the utility_scripts directory,' ) e (' ' * n_space_characters)+'# of the cookbooks project' e properly_pad_and_colourize_this_help_option('--format=[name]', 'feedback the format type of this entry,' ) e (' ' * n_space_characters)+'# such as via '+simp('cookbook --format=postinstall') e properly_pad_and_colourize_this_help_option('--expand', 'to expand the short yaml dataset into' ) e properly_pad_and_colourize_this_help_option('--expand=PROGRAM_NAME', 'to expand an individual program, such as python or ruby' ) # ======================================================================= # # === --n-registered-binaries? # ======================================================================= # e properly_pad_and_colourize_this_help_option('--n-registered-binaries?', 'to report how many registered binaries are available' ) # ======================================================================= # # === --show-all-about=PROGRAM_NAME # ======================================================================= # e properly_pad_and_colourize_this_help_option('--show-all-about=PROGRAM_NAME', 'to show all about the given program at hand' ) e properly_pad_and_colourize_this_help_option('--permanently-disable-colours', 'to permanently disable all colour output by the Cookbooks project' ) e properly_pad_and_colourize_this_help_option('--update-kde-plasma', 'batch-update (that is, download) all KDE5 components of KDE Plasma' ) e (' ' * n_space_characters)+'# a long dataset; --initialize is an alias to this action' e properly_pad_and_colourize_this_help_option('--create-programs-version-html-file', 'create and upload a .html file containing all '\ 'program_name-program_versions' ) e (' ' * n_space_characters)+'# entries. This is primarily meant for my home system.' # ======================================================================= # # === --allowed_tags? # ======================================================================= # e properly_pad_and_colourize_this_help_option('--allowed_tags?', 'show a list of all allowed tags in the '+simp('tags: subsection')+ ' of a cookbook-yaml file' ) # ======================================================================= # # === --generate_version_file # ======================================================================= # e properly_pad_and_colourize_this_help_option('--generate_version_file', 'to generate a programs-version yaml file' ) # ======================================================================= # # === --use-psych # ======================================================================= # e properly_pad_and_colourize_this_help_option('--use-psych', 'to use psych for the yaml files' ) # ======================================================================= # # === --use-syck # ======================================================================= # e properly_pad_and_colourize_this_help_option('--use-syck', 'to use syck for the yaml files' ) # ======================================================================= # # === --create-html-page-for-these-programs= # ======================================================================= # e properly_pad_and_colourize_this_help_option('--create-html-page-for-these-programs=', 'to generate a .html page for the given programs; separate '\ 'the input via' ) e (' ' * n_space_characters)+'# "'+sfancy(',')+'" such as in '+ simp('=ruby,python,php') # ======================================================================= # # === --n_binaries? # ======================================================================= # e properly_pad_and_colourize_this_help_option('--n_binaries?', 'tell us how many binaries/executables are tracked '\ 'in all cookbook-yaml files' ) e properly_pad_and_colourize_this_help_option('--publish', 'publish the list of all program versions of the cookbooks project' ) e properly_pad_and_colourize_this_help_option('--total-size?', 'show the total size of all locally available archives' ) e properly_pad_and_colourize_this_help_option('--tutorial', 'do show the short tutorial how the Cookbooks project may be used' ) e properly_pad_and_colourize_this_help_option('--update-tags', 'do update the tags defined in the various cookbooks' ) e properly_pad_and_colourize_this_help_option('--validate-entries', 'validate all Cookbook entries' ) e properly_pad_and_colourize_this_help_option('--version', 'feedback the current version of the Cookbooks gem' ) e properly_pad_and_colourize_this_help_option('--set_source_dir=/tmp', 'permanently set a new source dir (aka where all '\ 'archives are kept locally)' ) e properly_pad_and_colourize_this_help_option('--set_temp_dir=/tmp', 'permanently change the yaml file to set a '\ 'new temp directory' ) e end
#¶ ↑
#show_path_to_the_source_directory_yaml_file¶ ↑
This method will simply show the path to the source_dir.yml file.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 173 def show_path_to_the_source_directory_yaml_file begin require 'rbt/project/project_yaml_directory.rb' _ = RBT::PROJECT_YAML_DIRECTORY+'source_dir.yml' e sfile(_) rescue LoadError e 'The gem rbt is unavailable.' end end
#¶ ↑
#show_this_array¶ ↑
#¶ ↑
# File lib/cookbooks/class/report.rb, line 221 def show_this_array(array) # ======================================================================= # # Determine the threshold value to use for this display. # ======================================================================= # threshold_value = 70 left_pad = ' ' ljust_value = 28 array.each {|entry| case entry # ===================================================================== # # === has_to_be_compiled # ===================================================================== # when :has_to_be_compiled e (left_pad+entry.to_s+': ').ljust(ljust_value)+ steelblue( yes_or_no(send_this_method_and_sanitize_arrays(entry.to_s+'?')).to_s ) # ===================================================================== # # === skip_configure # ===================================================================== # when :skip_configure e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumorchid(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === archive_size # ===================================================================== # when :archive_size, :file_size, :program_size # colourize program_size. e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumorchid(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === homepage # ===================================================================== # when :homepage e (left_pad+entry.to_s+': ').ljust(ljust_value)+ cadetblue(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === short_description # ===================================================================== # when :short_description e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumturquoise(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === program_name # ===================================================================== # when :program_name e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumslateblue(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === program_compile_name # ===================================================================== # when :program_compile_name e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumslateblue(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === description # # Handle the description entry here. # ===================================================================== # when :description result = description?.chomp.rstrip if (result.size > threshold_value) result = result.tr("\n",' ')[0..threshold_value]+' [...]' end e (left_pad+entry.to_s+': ').ljust(ljust_value)+ limegreen(result)+rev # ===================================================================== # # === extra_information # ===================================================================== # when :extra_information # =================================================================== # # === Handle extra_information # # Next, limit the size for extra_description. We do not want to show # too much here. # =================================================================== # result = send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s if self.class.honour_threshold_value? if (result.size > threshold_value) result = result[0, result.index("\n")].delete('"')+' [...]' end end result.chomp! e (left_pad+entry.to_s+': ').ljust(ljust_value)+ darkslateblue(result) # ===================================================================== # # === use_autogen # ===================================================================== # when :use_autogen e (left_pad+entry.to_s+': ').ljust(ljust_value)+ cadetblue(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === extract_to # ===================================================================== # when :extract_to e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumpurple(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s)+rev # ===================================================================== # # === program_path # ===================================================================== # when :program_path e (left_pad+entry.to_s+': ').ljust(ljust_value)+ orange(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === configure_options # ===================================================================== # when :configure_options unless configure_options?.empty? e (left_pad+entry.to_s+': ').ljust(ljust_value)+ mediumseagreen(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s)+rev end # ===================================================================== # # === do_not_symlink # ===================================================================== # when :do_not_symlink e (left_pad+entry.to_s+': ').ljust(ljust_value)+ lightslategray(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === keep_extracted # ===================================================================== # when :keep_extracted e (left_pad+entry.to_s+': ').ljust(ljust_value)+ seagreen(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === last_update # ===================================================================== # when :last_update e (left_pad+entry.to_s+': ').ljust(ljust_value)+ cornflowerblue(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === prefix # ===================================================================== # when :prefix e (left_pad+entry.to_s+': ').ljust(ljust_value)+ darkseagreen(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === program_version # ===================================================================== # when :program_version e (left_pad+entry.to_s+': ').ljust(ljust_value)+ springgreen(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === url1 # ===================================================================== # when :url1,:url2,:url3,:url4,:url5 e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sandybrown(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === pkgconfig_files # ===================================================================== # when :pkgconfig_files e (left_pad+entry.to_s+': ').ljust(ljust_value)+ deepskyblue(send_this_method_and_sanitize_arrays(entry.to_s+'?').to_s) # ===================================================================== # # === headers # ===================================================================== # when :headers e (left_pad+entry.to_s+': ').ljust(ljust_value)+ darkseagreen(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === md5sum # ===================================================================== # when :md5sum if show_md5sum? e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) end # ===================================================================== # # === remote_url # ===================================================================== # when :remote_url e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === program_full_name # ===================================================================== # when :program_full_name e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === base_dir # ===================================================================== # when :base_dir e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === real_short_name # ===================================================================== # when :real_short_name e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === archive_type # ===================================================================== # when :archive_type e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) # ===================================================================== # # === short_name # # Is steelblue. # ===================================================================== # when :short_name e (left_pad+entry.to_s+': ').ljust(ljust_value)+ steelblue(send_this_method_and_sanitize_arrays(entry.to_s+'?')) else e (left_pad+entry.to_s+': ').ljust(ljust_value)+ sfancy(send_this_method_and_sanitize_arrays(entry.to_s+'?')) end } end
#¶ ↑
#skip_configure?¶ ↑
Query-method over as to whether we will skip configure or whether we will not.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 936 def skip_configure? obtain(:skip_configure) end
#¶ ↑
#substitute_macros¶ ↑
Do “macro” expansion with this method. We will sanitize some variables, which we assume were meant to be “macros” - that is, to be substituted with another value..
Right now this is only used for kernel variable, PROGRAM_NAME, PNAME, NAME, KERNEL_V and PROGRAM_VERSION but maybe someone else wants to do more macro processing, so we will keep this bundled here together.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 629 def substitute_macros(input) if input.is_a? Array input.map {|entry| substitute_macros(entry) } # Recursive call. else i = input.to_s.dup # Work on a new copy here. if i.include? 'PROGRAM_VERSION' i.gsub!(/PROGRAM_VERSION/, program_version?) end if i.include? 'PNAME' i.gsub!(/PNAME/, short_name?) elsif i.include? 'NAME' i.gsub!(/NAME/, short_name?) elsif i.include? 'PROGRAM_NAME' i.gsub!(/PROGRAM_NAME/, short_name?) end if ENV['KERNEL_V'] && i.include?('KERNEL_V') i.gsub!(/#{i}/, ENV['KERNEL_V']) end i end end
#¶ ↑
#symlink_headers?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 111 def symlink_headers? obtain(:symlink_headers) end
#¶ ↑
#symlink_pkgconfig_files?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 179 def symlink_pkgconfig_files? obtain(:symlink_pkgconfig_files) end
#¶ ↑
#sync_yaml_dataset_down_one_level¶ ↑
#¶ ↑
# File lib/cookbooks/class/dataset.rb, line 132 def sync_yaml_dataset_down_one_level( this_program = seek_which_program? ) dataset = ihash[:yaml_dataset] # ======================================================================= # # Obtain the dataset, through the pointer to the program being sought. # ======================================================================= # shortened_dataset = dataset[this_program] ensure_that_this_hash_has_only_valid_keys(shortened_dataset) # Must come early. update_yaml_dataset(shortened_dataset) # ======================================================================= # # Next, remove the old pointer. # ======================================================================= # dataset.delete(this_program) # ======================================================================= # # We can also sync towards real_short_name, since real_short_name # is the variant without any '-' characters. We can not yet determine # short_name though. # ======================================================================= # set_real_short_name(this_program) end
#¶ ↑
#to_bool¶ ↑
#¶ ↑
# File lib/cookbooks/class/class.rb, line 101 def to_bool(i) case i when 't','true','yes','y' return true when 'f','false','no','n' return false end i end
#¶ ↑
#try_to_sanitize_sed_entry (sed tag)¶ ↑
sed entry allows us to make some very simple replacements in files.
We will guarantee that it will be an Array.
#¶ ↑
# File lib/cookbooks/class/sanitize.rb, line 282 def try_to_sanitize_sed_entry # ======================================================================= # # Only sanitize the sed entry if we have that key. # ======================================================================= # if has_key? :sed if sed? _ = sed? _ = _.split(N) if _.is_a? String if _ _ = [_] unless _.is_a? Array # Will be an Array. _.compact! # We don't want to store nil values here. set_sed(_) end end end end
#¶ ↑
#update_kde_plasma¶ ↑
Use this method, as delegation, in order to update the KDE5 plasma components.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 469 def update_kde_plasma unless Cookbooks.const_defined? :UpdateKdePlasma require 'cookbooks/check_for_updates/update_kde_plasma.rb' end UpdateKdePlasma.new end
#¶ ↑
#update_kde_porting_aids¶ ↑
To invoke this, try:
cookbooks --update-kde-porting-aids
#¶ ↑
# File lib/cookbooks/class/class.rb, line 492 def update_kde_porting_aids unless Cookbooks.const_defined? :UpdateKdePortingAids require 'cookbooks/check_for_updates/update_kde_porting_aids.rb' end UpdateKdePortingAids.new end
#¶ ↑
#update_mate_desktop_components¶ ↑
Update mate-desktop via this method.
Invocation example:
cookbooks --update-mate
#¶ ↑
# File lib/cookbooks/class/class.rb, line 507 def update_mate_desktop_components unless Cookbooks.const_defined? :CheckForMateDesktopUpdates require 'cookbooks/check_for_updates/check_for_mate_desktop_updates.rb' end CheckForMateDesktopUpdates.new end
#¶ ↑
#update_with_this_program¶ ↑
This is a compound-method. It will first set the new program to be searched for; and then it will conditionally load the yaml dataset, if the program is included.
#¶ ↑
# File lib/cookbooks/class/dataset.rb, line 183 def update_with_this_program(i = search_which_program?) i = i.to_s.dup if i.frozen? i.delete!('-') if i.include? '-' if i.end_with? '.yml' i.sub!(/\.yml$/,'') elsif i.end_with? '.pc' i.sub!(/\.pc$/,'') end set_search_for_this_program(i) load_yaml_dataset_from_this_file(i) end
#¶ ↑
#update_yaml_dataset¶ ↑
This can be used to update the yaml dataset.
However had, for boolean values that are to be added, we will ALWAYS sanitize them, so that “t” becomes true, and “f” becomes false. But only if it is a boolean value.
#¶ ↑
# File lib/cookbooks/class/dataset.rb, line 163 def update_yaml_dataset(i) if i.keys.size > 1 # This check excludes Hashes that were not yet synced down one level. i.update(i) {|key, value| if is_a_boolean_configuration_value?(key) value = to_boolean(value) else value end } end ihash[:yaml_dataset].update(i) # .update() will replace in-place. end
#¶ ↑
urls?¶ ↑
This method will return all available URLs in Array format.
We only support 5 URLs at max right now. Since Jul 2012 we will not return empty values, as they are useless anyway.
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 746 def urls? # ======================================================================= # # Build our Array that will hold all 5 URLs. # ======================================================================= # array = %w( url1 url2 url3 url4 url5 ) _ = dataset?.values_at(*array) # We require the * here. _.compact! _.reject!(&:empty?) # We don't want empty entries, hence we filter them away. return _ end
#¶ ↑
#use_autogen?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 126 def use_autogen? obtain(:use_autogen) end
#¶ ↑
#use_glib_schema?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 104 def use_glib_schema? obtain(:use_glib_schema) end
#¶ ↑
#use_this_build_directory?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 346 def use_this_build_directory? obtain(:use_this_build_directory) end
#¶ ↑
use_this_connective_token?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 800 def use_this_connective_token? @internal_hash[:use_this_connective_token] end
#¶ ↑
#use_this_make_command?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 159 def use_this_make_command? obtain(:use_this_make_command) end
#¶ ↑
valid_key?¶ ↑
You can use this method to determine whether we have a specific, valid key or whether we don't.
#¶ ↑
# File lib/cookbooks/class/class.rb, line 85 def valid_key?(key) _ = true _ = false unless registered_cookbook_entries?.include? key.to_s # The key must be a String. return _ end
#¶ ↑
wrap_result?¶ ↑
#¶ ↑
# File lib/cookbooks/class/obtain.rb, line 605 def wrap_result? @internal_hash[:wrap_result] end