module Cookbooks
#¶ ↑
require 'cookbooks/base/debug.rb'
#¶ ↑
#¶ ↑
This file will hold the relevant remote URL entries for the classes found in this directory.
#¶ ↑
require 'cookbooks/check_for_updates/remote_urls.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/class/constants.rb'
#¶ ↑
#¶ ↑
#¶ ↑
class Cookbook also has to ensure that certain values are set to default (and thus correct) values. This file here ensures this.
All methods that have something to do with ensure-functionality are bundled together in this file here.
#¶ ↑
require 'cookbooks/class/ensure.rb'
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
require 'cookbooks/class/help.rb'
#¶ ↑
#¶ ↑
Constants that are essentially archive-extensions can be kept here.
#¶ ↑
require 'cookbooks/constants/archives.rb'
#¶ ↑
#¶ ↑
All constants related to different encodings will be stored here.
#¶ ↑
require 'cookbooks/constants/encoding.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/constants/misc.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/constants/namespace.rb'
#¶ ↑
#¶ ↑
This file collects useful regexes that can be used within the scope of the Cookbooks project.
#¶ ↑
require 'cookbooks/constants/regexes.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/constants/show_names.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/directory/cookbooks_base_directory.rb
#¶ ↑
#¶ ↑
Cookbooks::FileDoesNotExist¶ ↑
When a file does not exist, this error can be raised.
#¶ ↑
#¶ ↑
Cookbooks::SaveFile¶ ↑
This file provides file-saving capabilities. This is already possible within ruby itself via File.open but I wanted to use a simpler API to memorize.
#¶ ↑
require 'cookbooks/misc/save_file.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/are_we_on_gobolinux.rb'
#¶ ↑
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/e.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/is_on_roebe.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/remove_archive_from_the_end.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/return_archive_type.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/time.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/validate_entries.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/module_methods/verbose_truth.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/project_settings/project_base_directory.rb'
#¶ ↑
#¶ ↑
We will also enable a custom variant to load yaml files.
#¶ ↑
#¶ ↑
require 'cookbooks/utility_scripts/generate_homepage/html_tags.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/utility_scripts/generate_homepage/initialize.rb'
#¶ ↑
#¶ ↑
require 'cookbooks/utility_scripts/generate_homepage/run.rb'
#¶ ↑
#¶ ↑
#¶ ↑
require 'cookbooks/version/version.rb'
#¶ ↑
Constants
- ALL_BINARIES
- ALL_HEADERS
- ALL_LIBRARIES
- ALL_PROGRAMS
#¶ ↑
ALL_PROGRAMS¶ ↑
This constant keeps track of all programs available.
#¶ ↑
- ALL_TAGS
- BASE_URL_TO_GNOME_SOURCES
#¶ ↑
BASE_URL_TO_GNOME_SOURCES¶ ↑
#¶ ↑
- BLFS_CHANGELOG_WEBPAGE
#¶ ↑
Cookbooks::CheckForBlfsUpdates::BLFS_CHANGELOG_WEBPAGE¶ ↑
#¶ ↑
- CHECK_FOR_BINARY_NAMES
#¶ ↑
CHECK_FOR_BINARY_NAMES¶ ↑
#¶ ↑
- CHECK_FOR_LIBRARY_NAMES
#¶ ↑
CHECK_FOR_LIBRARY_NAMES¶ ↑
#¶ ↑
- COMPILE_EVERYTHING_INTO_STANDALONE_DIRECTORY
#¶ ↑
COMPILE_EVERYTHING_INTO_STANDALONE_DIRECTORY¶ ↑
Whether to compile everything into a standalone directory or not.
#¶ ↑
- CONFIGURATION_DIRECTORY
#¶ ↑
Cookbooks::CONFIGURATION_DIRECTORY¶ ↑
#¶ ↑
- COOKBOOKS_BASE_DIRECTORY
#¶ ↑
Cookbooks::COOKBOOKS_BASE_DIRECTORY¶ ↑
The following constant is actually only useful for my system, and only if I don't use any other setting. So this is mostly just used for legacy reasons.
#¶ ↑
- COOKBOOKS_CONFIGURATION
- COOKBOOKS_CONFIGURATION_DIR
#¶ ↑
Cookbooks::COOKBOOKS_CONFIGURATION_DIR¶ ↑
Where we keep the yaml files for our cookbooks.
#¶ ↑
- COOKBOOKS_DIR
- COOKBOOKS_DIRECTORY
- COOKBOOKS_YAML_DIRECTORY
- COOKBOOK_ALIASES
- COOKBOOK_DIRECTORY
COOKBOOKS_BASE_DIRECTORY = INDIVIDUAL_COOKBOOKS_DIRECTORY # Not good as it is defined somewhere else.
- COOKBOOK_UTILITY_SCRIPTS
#¶ ↑
Cookbooks::COOKBOOK_UTILITY_SCRIPTS¶ ↑
This constant will work because we pull in the file project_base_directory.rb in this file here.
#¶ ↑
- COOKBOOK_VALIDATION_SCRIPTS
#¶ ↑
Cookbooks::COOKBOOK_VALIDATION_SCRIPTS¶ ↑
This constant will work because we pull in the file project_base_directory.rb in this file here.
#¶ ↑
- COOKBOOK_VERSION
- DEFAULT_ARCHIVE_TYPE
#¶ ↑
DEFAULT_ARCHIVE_TYPE¶ ↑
This constant may be required so that other classes know which is the default archive. This can then be used to, for example, repackage archives into this format.
#¶ ↑
- DEFAULT_BASE_DIRECTORY
#¶ ↑
Cookbooks::DEFAULT_BASE_DIRECTORY¶ ↑
Hardcoded default value. Should not be needed ever, but just for simplicity, we will also define it.
#¶ ↑
- DEFAULT_COLOUR_TO_USE
#¶ ↑
DEFAULT_COLOUR_TO_USE¶ ↑
Specify what is our main colour to use for the Cookbooks project.
#¶ ↑
- DEFAULT_ENTRY
- DEFAULT_PROGRAM_ENTRY
#¶ ↑
DEFAULT_PROGRAM_ENTRY¶ ↑
#¶ ↑
- DEPOT_DIR
#¶ ↑
DEPOT_DIR¶ ↑
#¶ ↑
- DIRECTORY_EXPANDED_COOKBOOKS
- DIRECTORY_VALIDATION
#¶ ↑
Cookbooks::DIRECTORY_VALIDATION¶ ↑
#¶ ↑
- ENCODING_ISO
#¶ ↑
ENCODING_ISO¶ ↑
#¶ ↑
- FILE_ALLOWED_TAGS
#¶ ↑
Cookbooks::FILE_ALLOWED_TAGS¶ ↑
#¶ ↑
- FILE_COOKBOOK_CHAINED_PROGRAMS
#¶ ↑
Cookbooks::FILE_COOKBOOK_CHAINED_PROGRAMS¶ ↑
Easier constant to keep track of the chained cookbook programs.
This will then yield to a path such as this here:
"/Programs/Ruby/2.3.1/lib/ruby/site_ruby/2.3.0/cookbooks/yaml/cookbook_chained_programs.yml"
#¶ ↑
- FILE_PREDEFINED_INSTALLATION_INSTRUCTIONS
#¶ ↑
FILE_PREDEFINED_INSTALLATION_INSTRUCTIONS¶ ↑
Define where the yaml file is kept.
#¶ ↑
- FILE_PROGRAMS_VERSION
#¶ ↑
Cookbooks::FILE_PROGRAMS_VERSION¶ ↑
This file, when existing, holds a shorter name: version dataset for all programs.
#¶ ↑
- FILE_REGISTERED_COOKBOOK_ENTRIES
#¶ ↑
Cookbooks::FILE_REGISTERED_COOKBOOK_ENTRIES¶ ↑
#¶ ↑
- FILE_REGISTERED_HEADERS
#¶ ↑
FILE_REGISTERED_HEADERS¶ ↑
#¶ ↑
- FILE_SHORT_TUTORIAL
#¶ ↑
Cookbooks::FILE_SHORT_TUTORIAL¶ ↑
#¶ ↑
- FILE_SOURCE_DIRECTORY
#¶ ↑
Cookbooks::FILE_SOURCE_DIRECTORY¶ ↑
#¶ ↑
- FILE_SOURCE_DIRECTORY_YAML
- FILE_SPECIFICATION_OF_REGISTERED_COOKBOOK_ENTRIES
#¶ ↑
Cookbooks::FILE_SPECIFICATION_OF_REGISTERED_COOKBOOK_ENTRIES¶ ↑
#¶ ↑
- FILE_TEMP_DIRECTORY_YAML
#¶ ↑
Cookbooks::FILE_TEMP_DIRECTORY_YAML¶ ↑
Pointer towards the project's temp_directory.yml file.
#¶ ↑
- FILE_USE_COLOURS
#¶ ↑
Cookbooks::FILE_USE_COLOURS¶ ↑
#¶ ↑
- FILE_USE_MD5SUM
#¶ ↑
Cookbooks::FILE_USE_MD5SUM¶ ↑
#¶ ↑
- FILE_USE_PSYCH_OR_SYCK
#¶ ↑
Cookbooks::FILE_USE_PSYCH_OR_SYCK¶ ↑
#¶ ↑
- GetCookbooks
- HASH_INSTALLATION_INSTRUCTIONS
#¶ ↑
HASH_INSTALLATION_INSTRUCTIONS¶ ↑
This Hash gives us an easier handle to sanitize our data.
It has some constant-shortcuts that are convenient for use lateron.
For instance, RINSTALL means “ruby install”, PINSTALL means “python install”.
#¶ ↑
- INDIVIDUAL_COOKBOOKS
- INDIVIDUAL_COOKBOOKS_DIRECTORY
#¶ ↑
Cookbooks::INDIVIDUAL_COOKBOOKS_DIRECTORY¶ ↑
The above constant was added at around 16.09.2014.
It is one of the most important constant, because it specifies where to find all the individual yaml entries.
#¶ ↑
- ISO_ENCODING
- KONSOLE
#¶ ↑
Cookbooks::KONSOLE¶ ↑
#¶ ↑
- LOCATION_REGISTERED_BINARIES
#¶ ↑
LOCATION_REGISTERED_BINARIES¶ ↑
This may be a file path such as:
/Programs/Ruby/2.4.1/lib/ruby/site_ruby/2.4.0/cookbooks/yaml/registered_binaries.yml
cat $COOKBOOKS/yaml/registered_binaries.yml
#¶ ↑
- LOCATION_REGISTERED_HEADERS
#¶ ↑
LOCATION_REGISTERED_HEADERS¶ ↑
cat $COOKBOOKS/yaml/registered_headers.yml
#¶ ↑
- LOCATION_REGISTERED_LIBRARIES
#¶ ↑
LOCATION_REGISTERED_LIBRARIES¶ ↑
This may be a file path such as:
/Programs/Ruby/2.4.1/lib/ruby/site_ruby/2.4.0/cookbooks/yaml/registered_libraries.yml
cat $COOKBOOKS/yaml/registered_libraries.yml
#¶ ↑
- LOCATION_REGISTERED_TAGS
#¶ ↑
LOCATION_REGISTERED_TAGS¶ ↑
cat $COOKBOOKS/yaml/registered_tags.yml
#¶ ↑
- MAKE_COMMAND_TO_USE
#¶ ↑
MAKE_COMMAND_TO_USE¶ ↑
Which make command to use.
#¶ ↑
- N
#¶ ↑
N¶ ↑
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE¶ ↑
Which namespace we shall use. This is no longer as important anymore, since as of ~2016 though.
#¶ ↑
- PII
- PREDEFINED_INSTALLATION_INSTRUCTIONS
- PROGRAMS_DIR
- PROGRAMS_DIRECTORY
#¶ ↑
PROGRAMS_DIRECTORY¶ ↑
#¶ ↑
- PROJECT_BASE_DIR
- PROJECT_BASE_DIRECTORY
#¶ ↑
Cookbooks::PROJECT_BASE_DIRECTORY¶ ↑
#¶ ↑
- PROJECT_YAML_DIR
- PROJECT_YAML_DIRECTORY
#¶ ↑
Cookbooks::PROJECT_YAML_DIRECTORY¶ ↑
This constant specifies where our project-specific YAML files are to be kept - the yaml base directory.
There are several “aliases” to this constant here.
#¶ ↑
- RBT_YAML
- REGEX_TO_SANITIZE_LIBRARIES
#¶ ↑
REGEX_TO_SANITIZE_LIBRARIES¶ ↑
Use this regex if you wish to sanitize some libraries.
#¶ ↑
- REGEX_TO_USE_FOR_FOR_GITHUB
#¶ ↑
Cookbooks::REGEX_TO_USE_FOR_FOR_GITHUB¶ ↑
This constant is used to grab archives from github. These archives have a form like “github.com/ninja-build/ninja/archive/v1.7.1.tar.gz”.
The following example on rubular shows how to use this:
http://rubular.com/r/xTVfP9TWKG
#¶ ↑
- REGISTERED_COOKBOOK_ENTRIES
- REMOTE_DOWNLOAD_URL_FOR_KDE_PLASMA
#¶ ↑
REMOTE_DOWNLOAD_URL_FOR_KDE_PLASMA¶ ↑
#¶ ↑
- REMOTE_PUB_MATE_DESKTOP_RELEASES
#¶ ↑
REMOTE_PUB_MATE_DESKTOP_RELEASES¶ ↑
#¶ ↑
- REMOTE_PUB_MATE_DESKTOP_RELEASES_LATEST_VERSION
#¶ ↑
REMOTE_PUB_MATE_DESKTOP_RELEASES_LATEST_VERSION (mate tag)¶ ↑
This should be used as the base for the download-functionality in the file check_for_mate_desktop_updates.rb
#¶ ↑
- REMOTE_SLACKWARE_HOMEPAGE
#¶ ↑
REMOTE_SLACKWARE_HOMEPAGE¶ ↑
#¶ ↑
- REMOTE_URL_FOR_KDE_APPLICATIONS
#¶ ↑
REMOTE_URL_FOR_KDE_APPLICATIONS¶ ↑
#¶ ↑
- REMOTE_URL_FOR_KDE_FRAMEWORKS
#¶ ↑
REMOTE_URL_FOR_KDE_FRAMEWORKS¶ ↑
This URL should point to the latest KDE-frameworks release, which presently (13 March 2017) is 5.44.0 (the URL, oddly enough, does not include the trailing “0” though).
#¶ ↑
- REMOTE_URL_FOR_KDE_PLASMA
#¶ ↑
REMOTE_URL_FOR_KDE_PLASMA¶ ↑
Always point to the latest KDE-Plasma (upstream) URL here.
To invoke updating all KDE-plasma components from the commandline, you may do this:
update_kde_plasma
#¶ ↑
- REMOTE_URL_FOR_KDE_PORTING_AIDS
#¶ ↑
REMOTE_URL_FOR_KDE_PORTING_AIDS¶ ↑
#¶ ↑
- REMOTE_URL_TO_THE_MATE_DESKTOP_COMPONENTS
#¶ ↑
REMOTE_URL_TO_THE_MATE_DESKTOP_COMPONENTS¶ ↑
This constant specifies where we can find the (remote) source code to the mate-desktop, via HTTP-file listing.
#¶ ↑
- ROEBE_PATH_TO_COOKBOOKS
#¶ ↑
ROEBE_PATH_TO_COOKBOOKS¶ ↑
Path to my cookbooks. Won't be too relevant for other people.
#¶ ↑
- RUBY_SRC_DIR_AT_HOME
#¶ ↑
RUBY_SRC_DIR_AT_HOME¶ ↑
Deliberately hard-coded.
#¶ ↑
- SHOW_EXTRA_INFORMATION
#¶ ↑
SHOW_EXTRA_INFORMATION¶ ↑
#¶ ↑
- SOURCE_DIR
SOURCE_DIR¶ ↑
#¶ ↑
- SOURCE_DIRECTORY
#¶ ↑
SOURCE_DIRECTORY¶ ↑
#¶ ↑
- SPECIFICATION_OF_REGISTERED_COOKBOOK_ENTRIES
- SRC_DIR
#¶ ↑
Cookbooks::SRC_DIR¶ ↑
A constant is obviously static, but the user can also overrule the source directory from the commandline. If you need to refer to the source directory then you should not use this constant; instead, make use of:
Cookbooks.source_directory?
The constant below exists mostly for legacy reasons.
#¶ ↑
- STORE_INTO_THIS_DIRECTORY
#¶ ↑
STORE_INTO_THIS_DIRECTORY¶ ↑
#¶ ↑
- STORE_THE_LAST_CONFIGURATION_OPTIONS_IN_THIS_FILE
#¶ ↑
STORE_THE_LAST_CONFIGURATION_OPTIONS_IN_THIS_FILE¶ ↑
#¶ ↑
- SYSBIN_DIR
- SYSBIN_DIRECTORY
#¶ ↑
SYSBIN_DIRECTORY¶ ↑
#¶ ↑
- SYSINCLUDE_DIR
- SYSLIB_DIR
And we also define some more constants such as SYSLIB_DIR SYSBIN_DIR and SYSINCLUDE_DIR. Since these depend on SYSTEM_DIRECTORY, they must be defined here.
#¶ ↑
- SYSTEM_DIR
- SYSTEM_DIRECTORY
#¶ ↑
SYSTEM_DIRECTORY¶ ↑
#¶ ↑
- SYS_DIR
- TARBZ2
- TARGZ
- TARXZ
- TAR_BZ2
#¶ ↑
TAR_BZ2¶ ↑
#¶ ↑
- TAR_GZ
#¶ ↑
TAR_GZ¶ ↑
#¶ ↑
- TAR_XZ
#¶ ↑
TAR_XZ¶ ↑
Several archive types are kept here.
#¶ ↑
- TEMP_DIR
#¶ ↑
Cookbooks::TEMP_DIR¶ ↑
#¶ ↑
- TMP_DIR
- TMP_DIRECTORY
- URL_TO_REMOTE_CHANGELOG
#¶ ↑
URL_TO_REMOTE_CHANGELOG¶ ↑
Where to keep the remote changelog.
#¶ ↑
- USE_MAIN_ENCODING
- USE_THIS_ENCODING
#¶ ↑
USE_THIS_ENCODING¶ ↑
Main pointer towards the main Encoding for the Cookbooks project.
#¶ ↑
- USR_INCLUDE_DIR
#¶ ↑
Cookbooks::SYSINCLUDE_DIR¶ ↑
This can be standalone because it will be ALWAY absolute, pointing towards “/usr/included/”.
#¶ ↑
- VERSION
#¶ ↑
Cookbooks::VERSION¶ ↑
#¶ ↑
- YAML_FILE_REGISTERED_BINARIES
- YAML_FILE_REGISTERED_HEADERS
- YAML_FILE_REGISTERED_LIBRARIES
- YAML_FILE_REGISTERED_TAGS
- ZIP
#¶ ↑
Cookbooks::ZIP¶ ↑
#¶ ↑
Public Class Methods
#¶ ↑
::are_we_on_gobolinux?¶ ↑
Determine whether we are on GoboLinux or whether we are not.
#¶ ↑
# File lib/cookbooks/module_methods/are_we_on_gobolinux.rb, line 14 def self.are_we_on_gobolinux? return_this = false use_this_env_key = 'IS_ON_GOBOLINUX' if ENV.has_key? use_this_env_key if ENV[use_this_env_key].to_s == '1' return_this = true end end return return_this end
#¶ ↑
::available_cookbooks?¶ ↑
The resulting Array that will be returned here will always be sorted.
Note that there are at the least 5 different aliases to this method, such as Cookbooks.available_programs(). The variant that is preferred is the one named here, aka “Cookbooks.available_cookbooks?”.
#¶ ↑
# File lib/cookbooks/misc/available_cookbooks.rb, line 213 def self.available_cookbooks? Cookbooks::AvailableCookbooks.new.results? end
#¶ ↑
::check_and_report_whether_file_exists¶ ↑
The first argument to this method must be the path to the archive.
#¶ ↑
# File lib/cookbooks/module_methods/report_extended_information_about_this_program.rb, line 17 def self.check_and_report_whether_file_exists( i, optional_cookbook_object = nil ) i = i.to_s unless File.exist? i opnn; Colours.ewarn 'This archive does not exist locally, at' opnn; Colours.ewarn ' `'+Colours.sfile(i)+swarn('`') if optional_cookbook_object if optional_cookbook_object.do_not_download? opnn; e 'This is, however had, no problem as it will not' opnn; e 'be downloaded anyway.' end end cliner :lightblue end end
#¶ ↑
::check_this_cookbook_file_for_errors¶ ↑
The first file should be an existing .yml file holding the dataset that may be faulty.
#¶ ↑
# File lib/cookbooks/module_methods/check_this_cookbook_file_for_errors.rb, line 58 def self.check_this_cookbook_file_for_errors( this_file = '/Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/cookbooks/lib/cookbooks/yaml/individual_cookbooks/jasper.yml' ) if this_file.is_a? Array this_file = this_file.first end if this_file.nil? this_file = '/Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/cookbooks/lib/cookbooks/yaml/individual_cookbooks/jasper.yml' end if File.exist? this_file registered_cookbook_entries = Cookbooks.registered_cookbook_entries? dataset = YAML.load_file(this_file) key = dataset.keys.first available_entries_from_the_cookbooks_file = dataset[key].keys # ===================================================================== # # Next, obtain the entries that were not registered. Keep in mind # that this Array may be entry. # ===================================================================== # these_entries_were_not_registered = available_entries_from_the_cookbooks_file.reject {|entry| registered_cookbook_entries.include? entry } unless these_entries_were_not_registered.empty? opn; e 'The file at `'+sfile(this_file)+'`' opn; e 'contains at the least one erroneous entry.' these_entries_were_not_registered.each {|this_entry_is_not_included| opn; e 'The entry `'+sfancy(this_entry_is_not_included)+'` is not registered.' } end else opn; e 'No file exists at '+this_file+'.' end end
#¶ ↑
::create_html_page_for_these_programs¶ ↑
This method works on an Array as its input. This Array should be about programs that you want to see an auto-generated webpage containing some information about this program.
#¶ ↑
# File lib/cookbooks/module_methods/create_html_page_for_these_programs.rb, line 26 def self.create_html_page_for_these_programs(array = ARGV) if array.is_a?(String) and array.start_with?(':') array = array.to_s.delete(':').to_sym end if array.is_a? Symbol unless Cookbooks.const_defined? :SearchForTags require 'cookbooks/utility_scripts/search_for_tags/search_for_tags.rb' end # ===================================================================== # # Handle special cases such as KDE5. # ===================================================================== # case array # case tag # ===================================================================== # # === cookbooks --create_html_page_for_these_programs=:kde5 # ===================================================================== # when :kde, :kde5 array = ::Cookbooks.return_all_programs_that_match_this_tag(:kde5) # ===================================================================== # # === cookbooks --create_html_page_for_these_programs=:kde5_toolchain # ===================================================================== # when :kde5_toolchain # =================================================================== # # This variant here should be equivalent to LFS/BLFS, in the proper # order. This thus requires a yaml file. # =================================================================== # dataset = YAML.load_file(FILE_COOKBOOK_CHAINED_PROGRAMS) array = dataset['kde5_foundation']+ dataset['kde5_plasma']+ dataset['kde5_applications']+ dataset['kde5_porting_aids'] array.delete!(' ') array = array.split(',') end end if array.is_a? Array if array.first.is_a?(String) and array.first.include?(',') # <- Input such as ["php,kio,ruby"] array = array.first.split(',') end array.flatten! if array.size > 20 opn; e 'More than 20 entries were given (exactly '+ sfancy(array.size.to_s)+'). This may take a while.' end @html_page_content = "<html><head><title>HTML Pages for programs</title>"\ "<style>pre { font-size: 1.4em; }</style>"\ "</head><body><hr>\n".dup # Reset again. array.each_with_index {|this_program, index| index += 1 # =================================================================== # # For each program, we do the same actions: # (1) Obtain the dataset via Cookbooks::Cookbook.new() OR # from the expanded directory containing all yaml files. # (2) # =================================================================== # if File.directory?(DIRECTORY_EXPANDED_COOKBOOKS) and File.exist?(target_file = "#{DIRECTORY_EXPANDED_COOKBOOKS}#{this_program}.yml") dataset = YAML.load_file(target_file) remote_url = dataset['url1'] description = dataset['raw_description'] licence = dataset['licence'] homepage = dataset['homepage'].to_s else dataset = Cookbooks::Cookbook.new(this_program) remote_url = dataset.url1? description = dataset.raw_description? licence = dataset.licence? homepage = dataset.homepage? end if licence.is_a? Array licence = licence.join(', ') end @html_page_content << "<p>\n<h3 style=\"color:darkgreen\"><b style=\"color:darkblue\">"\ "#{index})</b> #{this_program}</h3><br>\n" @html_page_content << " <span style=\"margin-left: 1em; font-weight:bold; color: darkblue\">wget #{remote_url}<span><br><br>\n" unless description.to_s.empty? # <- Ignore empty descriptions. @html_page_content << "<pre>#{description}</pre>\n" end @html_page_content << "licence: #{licence}<br><br>\n" @html_page_content << "homepage: <a href=\"#{homepage}\">#{homepage}</a><br>\n" @html_page_content << "</p><br><hr>\n" } # ===================================================================== # # Next, store that HTML page somewhere. # ===================================================================== # what = @html_page_content into = "#{log_dir?}programs.html" opn; e "Storing these #{sfancy(array.size)} programs into the file:" opn; e " #{sfile(into)}" write_what_into(what, into) @html_page_content = ''.dup # Clear it again here. else opn; e 'This method requires an Array as input.' end end
#¶ ↑
::create_program_version_url_file¶ ↑
This method will create a local .txt file that will show the name of a program, the version and the remote (first) URL to the program at hand.
The boolean argument that can be passed to this method determines as to whether we will also show the time when the program has been last updated. By default this is true, meaning that we WILL show when a program has been last updated.
To invoke this method from the commandline, do:
cookbooks --create_program_version_url_file
#¶ ↑
# File lib/cookbooks/module_methods/create_program_version_url_file.rb, line 27 def self.create_program_version_url_file( also_show_last_update = :default # Since Feb 2018, we will show the last update by default. ) case also_show_last_update # case tag when :also_show_last_update, :include_last_update, :default also_show_last_update = true end newline = "\n".dup array_to_be_stored = [] _ = DIRECTORY_EXPANDED_COOKBOOKS if File.directory?(_) all_cookbooks = Dir["#{_}*.yml"].sort all_cookbooks.each {|yaml_file| dataset = YAML.load_file(yaml_file) program_name = File.basename(yaml_file.sub(/\.yml$/,'')) program_version = dataset['program_version'] program_url = dataset['url1'] array_to_be_stored << [ program_name, program_version, program_url ] if also_show_last_update # ================================================================= # # In this case, append more information. # ================================================================= # last_update = dataset['last_update'] array_to_be_stored[-1] << last_update end } # ===================================================================== # # Now that we have populated array_to_be_stored, we must # use it to create a .txt file. # ===================================================================== # what = ''.dup array_to_be_stored.each {|entry| program_name, program_version, program_url = entry[0], entry[1], entry[2] if also_show_last_update last_update = entry[3] # It is the last element. end # =================================================================== # # Add what we need here - name of the program, the version and # the remote URL. This will be properly padded. # =================================================================== # what << program_name.to_s.ljust(28)+ program_version.to_s.ljust(22) # =================================================================== # # Append when the last update happened, if we use that entry at # all. # =================================================================== # if also_show_last_update what << last_update.to_s.strip.ljust(14) end # =================================================================== # # Next, append the remote URL to the line. # =================================================================== # what << program_url.to_s.rstrip.ljust(44).rstrip+ newline } into = "#{Cookbooks.log_dir?}CookbookDirectory/programs_version_url.txt" opn; e 'Now storing into `'+sfile(into)+'`.' write_what_into(what, into) else # all_programs = Cookbooks.available_programs? opn; e 'Currently, this functionalitye depends on the expanded '\ 'cookbook dataset.' opn; e 'Generate it anew via:' opn; e ' cookbooks --expand' end end
#¶ ↑
::create_programs_version_html_file¶ ↑
The default input file can be found at:
/Depot/Temp/CookbookDirectory/programs_version.txt
#¶ ↑
# File lib/cookbooks/module_methods/create_programs_version_html_file.rb, line 21 def self.create_programs_version_html_file( use_this_file = Cookbooks.store_into_this_directory+'programs_version.txt' ) updated_when = Cookbooks.return_date+' '+Cookbooks.return_time # ======================================================================= # # Generate a .html file. # ======================================================================= # dataset = '<html><title>Programs of Cookbooks Version: '+::Cookbooks.version?+ ' Last updated: '+updated_when+ '</title><body> Last update: <b>'+updated_when+'</b><br> <pre style="font-size:1.2em">'+ File.read(use_this_file)+'</pre></body></html>' # ======================================================================= # # Store that file next: # ======================================================================= # use_this_file = ::Cookbooks.temp_directory?+'programs_version.html' opn; e 'Generating a new file at `'+sfile(use_this_file)+'`.' ::Cookbooks::SaveFile.write_what_into( dataset, use_this_file ) # Store it here. end
#¶ ↑
::does_this_cookbook_file_have_any_erroneous_entry?¶ ↑
This method will return a boolen value - true or false.
If true then the cookbook file in question has had an erroneous entry.
#¶ ↑
# File lib/cookbooks/module_methods/check_this_cookbook_file_for_errors.rb, line 25 def self.does_this_cookbook_file_have_any_erroneous_entry?( this_file = '/Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/cookbooks/lib/cookbooks/yaml/individual_cookbooks/jasper.yml' ) if this_file.is_a? Array this_file = this_file.first end if this_file.nil? this_file = '/Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/cookbooks/lib/cookbooks/yaml/individual_cookbooks/jasper.yml' end if File.exist? this_file registered_cookbook_entries = Cookbooks.registered_cookbook_entries? dataset = YAML.load_file(this_file) key = dataset.keys.first available_entries_from_the_cookbooks_file = dataset[key].keys # ===================================================================== # # Next, obtain the entries that were not registered. Keep in mind # that this Array may be entry. # ===================================================================== # these_entries_were_not_registered = available_entries_from_the_cookbooks_file.reject {|entry| registered_cookbook_entries.include? entry } !these_entries_were_not_registered.empty? else false # You have to ensure that the file exists on your own. end end
#¶ ↑
::enable_module_programs¶ ↑
This method will be invoked when we require the cookbooks project in a special manner.
We add the individual cookbooks onto the Cookbooks. namespace directly there.
This will then allow us to call methods such as:
Cookbooks.htop
Do note that we will also radically override already existing methods, so this is functionality that should be used with care.
Testing this method can happen either like this:
Cookbooks.enable_module_programs; Cookbooks.htop require 'cookbooks/module_programs'; htop = Cookbooks.htop
#¶ ↑
# File lib/cookbooks/module_methods/enable_module_programs.rb, line 32 def self.enable_module_programs available_programs?.each {|this_program| self.class.class_eval { _ = this_program.to_sym if respond_to? _ # This here happens when we enable the methods. # This is just here as a placeholder, if we ever want # to debug this. else # ::Cookbooks.e 'Defining the method `'+_.to_s+'` next.' # <- This is more o a debug-statement. define_method(_) { # Simply delegate to class Cookbook then. ::Cookbooks::Cookbook.new(this_program) } end } } end
#¶ ↑
::ensure_that_the_required_directories_exist¶ ↑
This method ensures that the base-directory exists.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 94 def self.ensure_that_the_required_directories_exist( use_this_as_directory = ::Cookbooks.store_into_this_directory? ) unless Dir.exist? use_this_as_directory if File.writable?(File.dirname(use_this_as_directory)) opn; e "Creating directory `#{use_this_as_directory}`." FileUtils.mkdir_p(use_this_as_directory) else e "Can not write into the directory #{use_this_as_directory}"\ ". You should use another" e 'setting for temp_directory.yml perhaps.' e e 'This file can be found here:' e " #{file_temp_directory}" end end end
#¶ ↑
::fast_return_file_size_of_this_program¶ ↑
This method will quickly return the file
#¶ ↑
# File lib/cookbooks/module_methods/fast_return_file_size_of_this_program.rb, line 18 def self.fast_return_file_size_of_this_program(i) if i.is_a? Array i = i.join(' ').strip end if File.directory? DIRECTORY_EXPANDED_COOKBOOKS target_file = DIRECTORY_EXPANDED_COOKBOOKS+i+'.yml' if File.exist? target_file dataset = YAML.load_file(target_file) archive_size = dataset['archive_size'] return archive_size else e 'No file exists at '+target_file end else e 'No directory exists at '+ DIRECTORY_EXPANDED_COOKBOOKS end end
#¶ ↑
::feedback_program_description¶ ↑
This will feedback the description of the program at hand.
#¶ ↑
# File lib/cookbooks/module_methods/feedback_program_description.rb, line 16 def self.feedback_program_description( i ) i = i.first if i.is_a? Array if i _ = Cookbooks::Cookbook.new _.find_this_program(i) e _.description? end end
#¶ ↑
::file_cookbook_aliases¶ ↑
Simply return where the cookbook_aliases.yml file resides.
This is, for instance, here:
/Programs/Ruby/2.3.1/lib/ruby/site_ruby/2.3.0/cookbooks/yaml/cookbook_aliases.yml
#¶ ↑
# File lib/cookbooks/constants/file_cookbook_aliases.rb, line 18 def self.file_cookbook_aliases "#{Cookbooks.project_yaml_dir?}cookbook_aliases.yml" end
#¶ ↑
::file_registered_cookbook_entries¶ ↑
Tell use where the file registered_cookbook_entries.yml is stored.
It is a part of the SanitizeCookbookDataset project.
#¶ ↑
# File lib/cookbooks/constants/registered_cookbook_entries.rb, line 25 def self.file_registered_cookbook_entries FILE_REGISTERED_COOKBOOK_ENTRIES end
#¶ ↑
::find_url_for¶ ↑
Use this method to find a specific URL quickly. We will return the first URL always, also called url1.
Usage example:
Cookbooks.find_url_for() Cookbooks.find_url_for(:htop)
#¶ ↑
# File lib/cookbooks/module_methods/find_url_for.rb, line 19 def self.find_url_for(i = ARGV) i = i.first if i.is_a? Array i = i.to_s _ = ::Cookbooks::Cookbook.new(i) { :skip_menu_interface } _.url1?.to_s.strip # Return the URL here. end
#¶ ↑
::generate_programs_version_yaml_file¶ ↑
This method will create one big yaml file that is a Hash. This big Hash will have the name of all programs and the corresponding version of said programs.
The key will be the name of the program and the value will be the respective program version.
You can also pass in your own dataset. If you do so, remember to use a hash, with specific key->value pairs that reflect the name of the program and the specific version of said program.
You can invoke this method from the commandline, by issuing:
cookbook --generate_version_file
#¶ ↑
# File lib/cookbooks/module_methods/generate_programs_version_yaml_file.rb, line 37 def self.generate_programs_version_yaml_file( use_this_dataset = nil ) _ = ''.dup # We will append onto this String. unless use_this_dataset # This is the default behaviour/clause. hash = {} # We store into this hash here. all_programs = ::Cookbooks.available_programs all_programs.each {|this_program| opn; e 'Now working on the program `'+simp(this_program)+'`.' cookbook = ::Cookbooks::Cookbook.new(this_program) { :bypass_menu } # =================================================================== # # Add onto the Hash next. Should keep it as a String. # =================================================================== # hash[this_program] = cookbook.version?.to_s } use_this_dataset = hash end use_this_dataset.each_pair {|key, value| value = '"'+value.to_s+'"' unless value.include? '"' _ << key.to_s+': '+value.to_s+N } # ======================================================================= # # Ok, now we should have all programs and the respective version # at hand - we can store it next. In the past, this made use of # YAML.dump() but for some strange reason, YAML.dump() gave strange # results; which is why I decided to generate the .yml file # on my own. # ======================================================================= # what = _ into = ::Cookbooks.yaml_directory?+'programs_version.yml' opn; e 'Will store into `'+sfile(into)+'`.' ::Cookbooks::SaveFile.write_what_into(what, into) # Store into the file programs_version.yml # ======================================================================= # # Store for my home-system as well. # ======================================================================= # if is_roebe? # On my system. into = RUBY_SRC_DIR_AT_HOME+'cookbooks/lib/cookbooks/yaml/programs_version.yml' opn; e 'Will also store into `'+sfile(into)+'`.' ::Cookbooks::SaveFile.write_what_into(what, into) end end
#¶ ↑
Coobooks.get_date¶ ↑
As of Sep 2014, this method will return a string such as:
"12 Jan 2015"
#¶ ↑
# File lib/cookbooks/module_methods/time.rb, line 32 def self.get_date current_day = Time.now.strftime('%d') # This will return a string such as "30". current_day+' '+Date::MONTHNAMES[Date.today.month][0,3]+' '+Time.now.strftime('%Y') end
#¶ ↑
::include_this_program?¶ ↑
This will always check without using aliases. If you need aliases, have a look at Cookbooks.really_does_include?() instead.
#¶ ↑
# File lib/cookbooks/module_methods/available_programs.rb, line 15 def self.include_this_program?(i) i.delete!('-') if i.include? '-' # Can not have '-' characters. Cookbooks.available_programs?.include?(i) end
#¶ ↑
::initialize_configuration¶ ↑
This method will be used to initialize the configuration object.
Currently we will use class Cookbooks::SimpleConfigurationLoader, but in principle, we could also use other implementations, such as class Configuration.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 242 def self.initialize_configuration( initialize_a_new_object_no_matter_what = false ) if initialize_a_new_object_no_matter_what set_configuration_object(Cookbooks::SimpleConfigurationLoader.new) set_configuration_dependent_variables else unless @configuration_object # Initialize anew here. set_configuration_object(Cookbooks::SimpleConfigurationLoader.new) set_configuration_dependent_variables end end end
#¶ ↑
::is_an_alias?¶ ↑
This method will return true if the input is an alias, and otherwise it will return false.
We will get rid of ':' in the input.
To test this method, do:
Cookbooks.is_an_alias? 'htop' Cookbooks.is_an_alias? 'blkid'
#¶ ↑
# File lib/cookbooks/module_methods/is_included.rb, line 35 def self.is_an_alias?(i) _ = Cookbooks::Aliases.new(i) _.is_an_alias? end
#¶ ↑
::is_included?¶ ↑
This method can be used to query whether a given input is included or whether it is not.
By default we will also include aliases, but this can be disabled, such as via the Symbol :do_not_check_for_aliases.
Remember that all aliases in use are stored in a yaml file. If you want to add new aliases or change the existing ones, you have to modify that yaml file.
In principle, we could also restrict this method here to only-aliases but I found that the API reads differently than this intent.
Usage examples:
Cookbooks.is_included? 'abiword' Cookbooks.is_included? 'aclocal'
#¶ ↑
# File lib/cookbooks/module_methods/is_included.rb, line 62 def self.is_included?( i, honour_aliases = true ) if i i = i.join(' ').strip if i.is_a? Array i.delete!(':') if i.include? ':' # We ignore ':' tokens. keys = Cookbooks.available_programs? case honour_aliases when :default # Restore the default state in this case. honour_aliases = true when :do_not_honour_aliases, :do_not_check_for_aliases, :do_not_use_aliases, :ignore_aliases, :user_disabled_this_setting_via_the_commandline honour_aliases = false end if honour_aliases aliases = Cookbooks::Aliases.new(i) all_aliases = aliases.dataset # =================================================================== # # Merge the keys together next, starting with the default programs. # ==================================================================== # keys << all_aliases.keys end keys.flatten! return keys.include?(i) else false end end
#¶ ↑
::is_registered?¶ ↑
With this method you can check whether a given program is included.
Note that for legacy reasons mostly, we will NOT check for aliases here. If you must do a check that includes aliases then you MUST use Cookbooks.really_does_include?() instead.
Usage examples:
Cookbooks.is_registered? 'ruby' Cookbooks.is_registered? 'ruby2'
#¶ ↑
# File lib/cookbooks/misc/available_cookbooks.rb, line 265 def self.is_registered?(i) Cookbooks.available_programs?.include?(i.to_s) # We require a String. end
#¶ ↑
::permanently_disable_colours¶ ↑
This method can be used to permanently disable the colours for the Cookbooks project. This essentially just saves into the file 'use_colours.yml'.
To invoke this from the commandline, do:
cookbooks --permanently-disable-colours
#¶ ↑
# File lib/cookbooks/colours/colours.rb, line 149 def self.permanently_disable_colours into = FILE_USE_COLOURS what = YAML.dump(false) opn; e 'Permanently disabling the colours for the '\ 'Cookbooks project.' opn; e "(file: #{sfile(into)})" write_what_into(what, into) if is_on_roebe? into = "#{RUBY_SRC_DIR_AT_HOME}cookbooks/lib/cookbooks/yaml/configuration/"\ "#{File.basename(FILE_USE_COLOURS)}" opn; e 'Permanently disabling the colours for the '\ 'Cookbooks project.' opn; e "(file: #{sfile(into)})" write_what_into(what, into) end end
#¶ ↑
Cookbooks::Configuration.permanently_set_path_to_this_source_directory¶ ↑
The first argument should be the path to a directory.
This directory will then serve as the new base directory where you may keep your archives.
Usage example from the commandline:
cookbooks --source_directory=/Depot/Files
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 400 def self.permanently_set_path_to_this_source_directory( i ) i = i.to_s unless i.is_a? String i = i.dup if i.frozen? unless i.end_with? '/' i << '/' end opn; e "Setting a new source directory to: #{sdir(i)}" ::Cookbooks.set_source_directory(i) # ======================================================================= # # Next, we have to save this value as well, for it to make it # permanent. # ======================================================================= # write_what_into(i, FILE_SOURCE_DIRECTORY) # Must save it here. end
#¶ ↑
::permanently_set_source_directory¶ ↑
Use this method if you wish to permanently modify the source directory, that is, the directory where our archives will be stored.
Invocation example from the commandline:
cookbooks --set_source_dir=/opt cookbooks --permanently-set-base-directory-to=/opt
#¶ ↑
# File lib/cookbooks/module_methods/permanently_set_source_directory.rb, line 23 def self.permanently_set_source_directory(i) i << '/' unless i.end_with? '/' # ======================================================================= # # Modify the yaml file next: # ======================================================================= # what = i into = FILE_SOURCE_DIRECTORY_YAML ::Cookbooks::SaveFile.write_what_into(what, into) opn; e 'Setting the new source directory to point towards '+sdir(what)+'.' opn; e 'Storing into the file `'+sfile(into)+'` next.' # ======================================================================= # # And also modify it on my home system, if IS_ROEBE is true. This will # go right into the configuration/ subirectory. # ======================================================================= # if is_on_roebe? into = RUBY_SRC_DIR_AT_HOME+'cookbooks/lib/cookbooks/yaml/configuration/'+ File.basename(into) opn; e 'Will also store into the file `'+sfile(into)+'`.' ::Cookbooks::SaveFile.write_what_into(what, into) end Cookbooks.set_source_directory(i) # And also sync it back. end
#¶ ↑
::permanently_set_temp_directory¶ ↑
Use this method if you wish to permanently modify the temp directory, that is, the directory we will extract to.
#¶ ↑
# File lib/cookbooks/module_methods/permanently_set_temp_directory.rb, line 14 def self.permanently_set_temp_directory(i) i << '/' unless i.end_with? '/' # ======================================================================= # # Modify the yaml file next: # ======================================================================= # what = i into = FILE_TEMP_DIRECTORY_YAML Cookbooks::SaveFile.write_what_into(what, into) # ======================================================================= # # And also modify it on my home system, if IS_ROEBE is true. # ======================================================================= # if is_on_roebe? into = RUBY_SRC_DIR_AT_HOME+'cookbooks/lib/cookbooks/yaml/configuration/'+ File.basename(into) Cookbooks::SaveFile.write_what_into(what, into) end Cookbooks.set_temp_directory(i) # And also sync it. end
#¶ ↑
::project_yaml_directory?¶ ↑
Query method for the constant PROJECT_YAML_DIRECTORY. Two aliases exist for this constant.
#¶ ↑
# File lib/cookbooks/project_settings/project_yaml_directory.rb, line 27 def self.project_yaml_directory? PROJECT_YAML_DIRECTORY end
#¶ ↑
::publish_list_of_all_programs_version¶ ↑
To invoke this method, do:
cookbooks --publish-list-of-all-programs-version
#¶ ↑
# File lib/cookbooks/module_methods/ftp.rb, line 26 def self.publish_list_of_all_programs_version( file_programs_version = FILE_PROGRAMS_VERSION # This is the file 'programs_version.yml' ) _ = ''.dup opn; e 'The file '+sfile(file_programs_version)+' will next '\ 'be FTP-uploaded/published.' hash = YAML.load_file(file_programs_version) hash.each_pair {|name_of_the_program, program_version| _ << name_of_the_program.ljust(28)+program_version.to_s+N } what = _ into = Cookbooks.store_into_this_directory+'programs_version.txt' opn; e 'Storing into `'+sfile(into)+'`.' ::Cookbooks::SaveFile.write_what_into(what, into) ::Cookbooks.upload_list_of_all_programs_version(into) # ========================================================================= # # Also upload a .html variant. # ========================================================================= # ::Cookbooks.upload_list_of_all_programs_version(into, :html) end
#¶ ↑
::remove_archive_from_the_end¶ ↑
This will remove the trailing archive type such as .tar.xz or .tar.gz and so forth.
#¶ ↑
# File lib/cookbooks/module_methods/remove_archive_from_the_end.rb, line 12 def self.remove_archive_from_the_end(i) i = i.dup if i.frozen? if i.end_with? '.tar.gz' i.sub!(/\.tar\.gz$/,'') elsif i.end_with? '.tar.xz' i.sub!(/\.tar\.xz$/,'') elsif i.end_with? '.tar.bz2' i.sub!(/\.tar\.bz2$/,'') elsif i.end_with? '.jar' i.sub!(/\.jar$/,'') elsif i.end_with? '.phar' i.sub!(/\.phar$/,'') end return i end
#¶ ↑
::remove_file_suffix¶ ↑
This method will remove a file suffix, such as '.tar.bz2', from the given input.
#¶ ↑
# File lib/cookbooks/module_methods/remove_file_suffix.rb, line 9 def self.remove_file_suffix(i) _ = i.dup if _.include? '.' _.sub!(/\.[a-z]{1,5}$/,'') if _.end_with? '.tar' _.sub!(/\.tar}$/,'') end end return _ end
#¶ ↑
::report_extended_information_about_this_program¶ ↑
(feedback tag, debug tag, main tag)
Use this feedback-method to report extended information about a program, in a colourful manner. This program must have been registered in the Cookbooks namespace - otherwise we can not really display much about that program at hand.
The input to this method can be either be a String or an Array.
#¶ ↑
# File lib/cookbooks/module_methods/report_extended_information_about_this_program.rb, line 47 def self.report_extended_information_about_this_program( i ) i = i.first if i.is_a? Array if i _ = Cookbooks::Cookbook.new _.find_this_program(i) _.report check_and_report_whether_file_exists(_.full_path?, _) end end
#¶ ↑
::report_how_many_binaries_are_registered¶ ↑
#¶ ↑
# File lib/cookbooks/module_methods/report_how_many_binaries_are_registered.rb, line 17 def self.report_how_many_binaries_are_registered n_binaries = ALL_BINARIES.keys.uniq.size opn; e 'There are '+sfancy(n_binaries.to_s)+' registered binaries in '\ 'all cookbook files.' end
#¶ ↑
::report_n_programs_available¶ ↑
This is similar to ::n_programs_available? but will report the amount of cookbooks registered.
#¶ ↑
# File lib/cookbooks/module_methods/available_programs.rb, line 33 def self.report_n_programs_available _ = Cookbooks.n_programs_available? e sfancy(_)+' programs are registered in our cookbooks at '+ simp(return_date)+'.' end
#¶ ↑
::report_total_size_of_all_archives¶ ↑
This method can be used to report the total size of all locally available archives.
Invocation example from the commandline:
cookbooks --report_total_size_of_all_archives
#¶ ↑
# File lib/cookbooks/module_methods/report_total_size_of_all_archives.rb, line 22 def self.report_total_size_of_all_archives total_size = 0 available_programs = available_programs? available_programs.each {|this_program| possible_target = "#{DIRECTORY_EXPANDED_COOKBOOKS}#{this_program}.yml" if File.exist? possible_target dataset = YAML.load_file(possible_target) program_path = dataset['program_path'] else # =================================================================== # # The expanded-cookbooks file does not exist, so use # Cookbooks::Cookbook instead. # =================================================================== # unless Cookbooks.const_defined? :Cookbook require 'cookbooks/class/class.rb' end program_path = Cookbooks::Cookbook.new(this_program).program_path? end if File.exist? program_path total_size += File.size(program_path) end } n_kilobytes = total_size / 1024.0 n_megabytes = n_kilobytes / 1024.0 n_gigabytes = n_megabytes / 1024.0 # ======================================================================= # # Finally, report it here. # ======================================================================= # e 'The total file size of all '+sfancy(available_programs.size.to_s)+ ' programs is '+total_size.to_s+' bytes ' e "(#{n_kilobytes.round(2)} KB; "+ n_megabytes.round(2).to_s+' MB; '+ crimson(n_gigabytes.round(2).to_s+' GB')+')' end
#¶ ↑
::require_validation_scripts¶ ↑
use this method to require the validation scripts.
#¶ ↑
# File lib/cookbooks/requires/require_validation_scripts.rb, line 15 def self.require_validation_scripts Dir[Cookbooks.validation_directory+'*.rb'].uniq.each {|file| require 'cookbooks/validation/'+File.basename(file) } end
#¶ ↑
::return_alias_program_name_for¶ ↑
This method will return the (aliased) program name for the given input. If no alias name was found, it will return the input.
#¶ ↑
# File lib/cookbooks/aliases/aliases.rb, line 299 def self.return_alias_program_name_for(i) Cookbooks::Aliases.new(i).translate_alias end
#¶ ↑
::return_all_blfs_entries¶ ↑
This method will (silently) return an Array with all entries that have a specific tag.
This currently uses grep.
The result will look like this:
["libpcap", "http://www.linuxfromscratch.org/blfs/view/svn/basicnet/libpcap.html"], ["xulrunner", "http://www.linuxfromscratch.org/blfs/view/7.5/x/xulrunner.html"],
#¶ ↑
# File lib/cookbooks/utility_scripts/blfs.rb, line 207 def self.return_all_blfs_entries cmd = 'grep -r "^ blfs" '+Cookbooks.individual_cookbooks_directory? result = `#{cmd}`.split(N).map {|entry| entry.gsub!(/ blfs: /,' ') if entry.include? ':' splitted = entry.split ':' splitted[0] = File.basename(splitted[0]).gsub(/\.yml/,'') entry = splitted.join ':' end entry.split(': ') } return result end
#¶ ↑
::return_archive_type¶ ↑
The default will be, as you can see from the default argument, .tar.xz. Note that this assumption is not always correct, e. g. if you do not repackage.
Note that the simple archives, such as .gem or .zip, could be detected automatically, but entries such as .tar.gz are harder detect, hence why we will use a hardcoded case menu here.
#¶ ↑
# File lib/cookbooks/module_methods/return_archive_type.rb, line 17 def self.return_archive_type(i = '.tar.xz') if i.end_with? '.tar.xz' '.tar.xz' elsif i.end_with? '.xz' '.tar.xz' elsif i.end_with? '.tar.gz' '.tar.gz' elsif i.end_with? '.tar.bz2' '.tar.bz2' elsif i.end_with? '.tar.lz' '.tar.lz' elsif i.end_with? '.gem' '.gem' elsif i.end_with? '.zip' '.zip' elsif i.end_with? '.jar' '.jar' elsif i.end_with? '.phar' '.phar' else i end end
#¶ ↑
::return_array_of_programs_without_a_blfs_entry¶ ↑
This method will return an Array that keeps track of all local cookbook files without a BLSF entry.
This functionality can then be used to output this Array on the commandline
#¶ ↑
# File lib/cookbooks/module_methods/return_array_of_programs_without_a_blfs_entry.rb, line 21 def self.return_array_of_programs_without_a_blfs_entry array_of_programs_without_a_blfs_entry = [] # ======================================================================= # # First, obtain all available programs. # ======================================================================= # all_available_programs = ::Cookbooks.available_programs? all_available_programs.each {|this_program| location = Cookbooks.individual_cookbooks_directory?+this_program+'.yml' dataset = File.read(location) unless dataset.include? ' blfs: http' array_of_programs_without_a_blfs_entry << this_program end } return array_of_programs_without_a_blfs_entry end
#¶ ↑
::return_array_of_this_tag¶ ↑
This method will return an Array of programs that qualify for a given tag.
Usage example:
Cookbooks.return_array_of_this_tag 'php' # => ["drupal", "eaccelerator"] Cookbooks.return_array_of_this_tag 'kde5'
#¶ ↑
# File lib/cookbooks/utility_scripts/search_for_tags/search_for_tags.rb, line 529 def self.return_array_of_this_tag(i) SearchForTags.new(i) { :be_quiet }.array_of_programs.sort end
#¶ ↑
::return_blfs_page_of_this_program¶ ↑
This method will return the BLfS page of a program, or nil if it was not registered.
Returns:
- either a string - or nil
Invocation example:
result = Cookbooks.return_blfs_page_of_this_program('gcc')
#¶ ↑
# File lib/cookbooks/utility_scripts/blfs.rb, line 241 def self.return_blfs_page_of_this_program(i) _ = Cookbooks::Blfs.new(i) { :be_quiet_and_do_not_tamper_with_the_xorg_buffer } result = _.remote_url? result = result.first if result.is_a? Array return result end
#¶ ↑
::return_configuration_options_for?¶ ↑
We delegate towards class Cookbooks::Cookbook here.
Usage example:
php_options = Cookbooks.return_configuration_options_for? 'php'
#¶ ↑
# File lib/cookbooks/misc/show_configuration_options.rb, line 375 def self.return_configuration_options_for?(this_program) ::Cookbooks::Cookbook.new(this_program).configuration_options? end
#¶ ↑
::return_location_of_this_yaml_file¶ ↑
Invocation example:
Cookbooks.return_location_of_this_yaml_file 'ruby'
#¶ ↑
# File lib/cookbooks/module_methods/return_location_of_this_yaml_file.rb, line 18 def self.return_location_of_this_yaml_file(i) i = i.to_s unless i.is_a? String unless i.end_with? '.yml' i = i.dup if i.frozen? i << '.yml' end if is_on_roebe? # ===================================================================== # # Hardcoded on my own system. # ===================================================================== # _ = RUBY_SRC_DIR_AT_HOME+'cookbooks/lib/cookbooks/yaml/individual_cookbooks/' _+i else Cookbooks.individual_cookbooks_directory?+i end end
#¶ ↑
::return_version_of_this_program¶ ↑
Usage example:
Cookbooks.return_version_of_this_program 'htop'
#¶ ↑
# File lib/cookbooks/module_methods/return_version_of_this_program.rb, line 15 def self.return_version_of_this_program(i = 'htop') if i.is_a? Array i = i.first end i = i.to_s # We have to work on Strings. if ::Cookbooks::Cookbook.does_include? i dataset = ::Cookbooks::Cookbook.new(i) { :bypass_menu } return dataset.program_version? else nil end end
#¶ ↑
::set_configuration_dependent_variables¶ ↑
This method will set some configuration-dependent values, such as the location of the source directory.
The various @ variables defined here should be preferentially used as opposed to their CONSTANT values. But ideally, simply use the getter methods, such as “::Cookbooks.source_directory?” or “::Cookbooks.temp_directory?”.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 172 def self.set_configuration_dependent_variables( i = @configuration_object ) if i.respond_to? :source_directory ::Cookbooks.set_source_directory(i.source_directory) else # ===================================================================== # # else simply hardcode it. This allows us to not have to # depend on any .yml file. # ===================================================================== # i = '/Users/x/SRC/' ::Cookbooks.set_source_directory(i) end if i.respond_to? :temp_directory ::Cookbooks.set_temp_directory(i.temp_directory) else # ===================================================================== # # else simply hardcode it. This allows us to not have to # depend on any .yml file. # ===================================================================== # i = '/tmp/' ::Cookbooks.set_temp_directory(i) end if i.respond_to? :system_directory ::Cookbooks.set_system_directory(i.system_directory) else # ===================================================================== # # else simply hardcode it. This allows us to not have to # depend on any .yml file. # ===================================================================== # i = '/System/' ::Cookbooks.set_system_directory(i) end if i.respond_to? :programs_directory ::Cookbooks.set_programs_directory(i.programs_directory) else # ===================================================================== # # else simply hardcode it. This allows us to not have to # depend on any .yml file. # ===================================================================== # i = '/Programs/' ::Cookbooks.set_programs_directory(i) end if i.respond_to? :store_into_this_directory ::Cookbooks.set_store_into_this_directory(i.store_into_this_directory) else # ===================================================================== # # else simply hardcode it. This allows us to not have to # depend on any .yml file. # ===================================================================== # i = '/Depot/Cookbooks/' ::Cookbooks.set_store_into_this_directory(i) end # ======================================================================= # # Define the instance variable @use_yaml_database_for_tags next, so # that we can, in some queries, use grep or a pure ruby solution to # find patterns in text. # ======================================================================= # @use_yaml_database_for_tags = i.use_yaml_database_for_tags end
#¶ ↑
::set_programs_directory¶ ↑
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 130 def self.set_programs_directory(i = '/Programs/') i = i.dup if i.frozen? i = convert_global_env(i) if i.include? '$' # ======================================================================= # # If there are still '$' entries then this variable does not # exist. In this case, use a hardcoded entry. # ======================================================================= # i = '/Programs/' if i.include? '$' i << '/' unless i.end_with? '/' @programs_directory = i end
#¶ ↑
::set_source_directory¶ ↑
Set the value of @source_directory here. A trailing “/” must be kept for these variables, as they are directories.
On my system this constant equals to the String “/Users/x/SRC/”. On other systems it can be different, settable via the commandline.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 72 def self.set_source_directory(i) i = i.dup if i.frozen? i = convert_global_env(i) if i.include? '$' i << '/' unless i.end_with? '/' @source_directory = i end
#¶ ↑
::set_store_into_this_directory¶ ↑
We will store Cookbooks-related output into this directory preferentialy. This is the reason why the ensure-method is called, to make sure that these directories exist.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 119 def self.set_store_into_this_directory(i) i = i.dup if i.frozen? i = convert_global_env(i) if i.include? '$' i << '/' unless i.end_with? '/' @store_into_this_directory = i ensure_that_the_required_directories_exist(i) end
#¶ ↑
::set_system_directory¶ ↑
The system directory.
This will depend on the yaml configuration. Alternatively it will be set to a hardcode default value.
This constant equals to “/System/”.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 152 def self.set_system_directory( i = '/System/' ) i = i.dup if i.frozen? i = convert_global_env(i) if i.include? '$' i << '/' unless i.end_with? '/' @system_directory = i end
#¶ ↑
::show_available_utility_scripts¶ ↑
Simply show all available utility scripts.
Invocation example from the commandline:
cookbooks --show-available-scripts
#¶ ↑
# File lib/cookbooks/module_methods/show_available_utility_scripts.rb, line 21 def self.show_available_utility_scripts files = Dir[utility_scripts?+'*.rb'].sort.map {|file| File.basename(file) } files = files - ['utility_scripts.rb'] e; files.each_with_index {|file, index| index += 1 e sfancy(index.to_s.rjust(4))+') '+simp(file) }; e end
#¶ ↑
::show_last_configure_option¶ ↑
#¶ ↑
# File lib/cookbooks/module_methods/show_last_configure_option.rb, line 12 def self.show_last_configure_option _ = STORE_THE_LAST_CONFIGURATION_OPTIONS_IN_THIS_FILE if File.exist? _ e File.read(_) else e 'No configure options have been stored yet (File checked: '+_+').' end end
#¶ ↑
::show_overview_over_available_utility_scripts¶ ↑
This method will show all available utility scripts and provide an overview over them.
To trigger this method, do:
cookbooks OVERVIEW cookbooks --show-available-utility-scripts
#¶ ↑
# File lib/cookbooks/module_methods/show_overview_over_available_utility_scripts.rb, line 26 def self.show_overview_over_available_utility_scripts target = "#{utility_scripts?}*.rb" available_files = Dir[target] if Object.const_defined? :ClassDocuShower available_files.each {|file| cliner ClassDocuShower[file] # Delegate towards ClassDocuShower here. } else opn; e 'The class ClassDocuShower is not available.' e opn; e 'It can be installed via:' e opn; e ' gem install class_docu_shower' e end end
#¶ ↑
::show_registered_binaries¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/registered_binaries.rb, line 188 def self.show_registered_binaries _ = Cookbooks.registered_binaries? RegisteredBinaries.opnn; e 'These '+_.size.to_s+' binaries are registered:' e _.reject {|entry| entry.to_s.empty? }.join(', ').strip.chop end
#¶ ↑
::show_tutorial¶ ↑
This will show a tutorial to the user, instructing them how to use the Cookbooks project.
Usage example:
cookbooks --tutorial
#¶ ↑
# File lib/cookbooks/class/tutorial.rb, line 18 def self.show_tutorial( try_to_use_colours = true ) require 'io/console' display_this_message = "\n[Press any key to continue; q to exit early]" # ========================================================================= # # The file for the short tutorial can be seen in # "tutorial/short_tutorial.md". # ========================================================================= # _ = Cookbooks.file_short_tutorial? if File.exist? _ dataset = File.readlines(_) # Display the file next. chunks = dataset.each_slice(20).to_a counter = 0 e # And a newline to start with. loop { content_that_will_be_displayed = chunks[counter] if try_to_use_colours content_that_will_be_displayed.map! {|line| # ================================================================= # # Next colourize anything that is indented with 4 leading spaces. # ================================================================= # line.gsub(/^( .+)$/, lightgreen('\1')) } end e content_that_will_be_displayed # ===================================================================== # # Next, display the "press any key to continue" message. # ===================================================================== # if try_to_use_colours display_this_message = mediumseagreen(display_this_message) end e display_this_message case STDIN.getch when 'q' exit else counter += 1 exit if counter >= chunks.size end } end end
#¶ ↑
::source_directory?¶ ↑
Simpler query method for the source directory in use.
This defaults to /Users/x/SRC on my system - may be different on other computers, which is why this has to be settable and modifiable by the user.
#¶ ↑
# File lib/cookbooks/module_methods/initialize_configuration.rb, line 270 def self.source_directory? @source_directory end
#¶ ↑
::swift_return_version_of_this_program¶ ↑
This method here is different from ::return_version_of_this_program
Rather than instantiate a new Cookbooks::Cookbook object, we just query the version from a yaml file directly. This is obviously much faster.
The obvious drawback is that we may have to manually update that yaml file and keep it up-to-date - but the advantage by far outweights this disadvantage. This method here will be much faster than ::return_version_of_this_program - and ideally, you should use it, rather than the other method.
If the program in question can not be found, this method will return nil.
Invocation examples:
Cookbooks.swift_return_version_of_this_program(:ruby) # => "2.3.1" Cookbooks.swift_return_version_of_this_program(:htop) # => "2.0.2" Cookbooks.swift_return_version_of_this_program(:awk) # => "2.0.2"
#¶ ↑
# File lib/cookbooks/module_methods/swift_return_version_of_this_program.rb, line 37 def self.swift_return_version_of_this_program( this_program = :htop ) this_program = this_program.to_s # ======================================================================= # # Next, try to pass it against a list of aliases, if it has not # been yet "findable". # ======================================================================= # if !Cookbooks.does_include?(this_program, :ignore_aliases) possible_alternative_name = Cookbooks.find_cookbook_alias_for(this_program) if possible_alternative_name if possible_alternative_name != this_program this_program = possible_alternative_name end end end _ = FILE_PROGRAMS_VERSION if File.exist? _ dataset = YAML.load_file(_) if dataset.has_key? this_program program_version = dataset.fetch(this_program) return program_version end else e "No file called `#{sfile(_)}` exists." raise FileDoesNotExist, _.to_s+' does not exist.' end return nil # Default return value here. end
#¶ ↑
::update_all_ruby_gems¶ ↑
This method can be used to update all local ruby gems (.gem files).
#¶ ↑
# File lib/cookbooks/module_methods/update_all_ruby_gems.rb, line 19 def self.update_all_ruby_gems _ = Cookbooks::CheckForNewReleaseOnRubygems.new(:dont_run_yet) base_dir = Cookbooks.individual_cookbooks_directory? # ======================================================================= # # First, we must obtain all entries thave have the strings "url1" # and ".gem". We will ask ruby to perform a grep-operation. We will # store these in an array. # ======================================================================= # array_ruby_gems = [] available_programs = Cookbooks.available_programs? available_programs.each {|this_program| target_yaml_file = "#{base_dir}#{this_program}.yml" if File.exist? target_yaml_file dataset = File.read(target_yaml_file) if dataset.include?('url1') line_holding_url1 = dataset.scan(/^ url1: (.+)$/).flatten.first if line_holding_url1.end_with? '.gem' # Found ruby gems. array_ruby_gems << [this_program, line_holding_url1] end end end } # ======================================================================= # # Ok - now that we have obtained the files that are .gem files, # we can proceed them and check for an updated. This taps into # a specialized class that will do so for us. # ======================================================================= # array_ruby_gems.each {|this_ruby_gem, remote_url| _.check_this_remote_url(remote_url) } end
#¶ ↑
::upload_list_of_all_programs_version¶ ↑
This will use my FTP wrapper to upload this file.
The local .txt file is usually kept or autogenerated here:
/Depot/Temp/CookbookDirectory/programs_version.txt
#¶ ↑
# File lib/cookbooks/module_methods/ftp.rb, line 56 def self.upload_list_of_all_programs_version( this_file = Cookbooks.store_into_this_directory+'programs_version.txt', type = :txt # type can be :txt or :html ) if File.exist? this_file case type when :html ::Cookbooks.create_programs_version_html_file(this_file) this_file.sub!(/\.txt$/,'') end opn; e 'Uploading the file '+sfile(this_file)+' next.' if Object.const_defined? :FtpParadise _ = FtpParadise::Connection.new(:dont_run_yet) _.set_be_verbose _.set_mode :ascii _.set_data('SHEVY') _.do_login('SHEVY') _.upload(this_file, :be_silent) end else opn; e 'No file exists at `'+sfile(this_file)+'`.' end end
Public Instance Methods
#¶ ↑
#get_cookbooks¶ ↑
You can use this method whenever you ought to retrieve all available cookbooks.
A sorted array will be returned, consisting of all the various cookbooks.
#¶ ↑
# File lib/cookbooks/misc/available_cookbooks.rb, line 199 def get_cookbooks(apply_filter = true) _ = AvailableCookbooks.new(apply_filter) return _.result end
#¶ ↑
Constants.individual_cookbooks_directory?¶ ↑
#¶ ↑
# File lib/cookbooks/directory/individual_cookbooks_directory.rb, line 44 def individual_cookbooks_directory? Cookbooks.individual_cookbooks_directory? end
#¶ ↑
#registered_cookbook_entries?¶ ↑
Just a pointer to the module-method with the same name.
#¶ ↑
# File lib/cookbooks/constants/registered_cookbook_entries.rb, line 64 def registered_cookbook_entries? Cookbooks.registered_cookbook_entries? end