class RBT::UpdateEntry
Constants
- ARE_WE_ALLOWED_TO_SAVE
#¶ ↑
ARE_WE_ALLOWED_TO_SAVE
¶ ↑#¶ ↑
- BR
#¶ ↑
BR
¶ ↑#¶ ↑
- CHANGELOG_SEPARATOR_LINE
#¶ ↑
CHANGELOG_SEPARATOR_LINE
¶ ↑This is the same line used by slackware.
#¶ ↑
- DEFAULT_URL
#¶ ↑
DEFAULT_URL
¶ ↑This URL is only for testing purposes. Do not actively set it if you are NOT testing the functionality.
#¶ ↑
- IS_THE_WGET_WRAPPER_AVAILABLE
- SHALL_WE_ALSO_DOWNLOAD_THE_PACKAGE
#¶ ↑
SHALL_WE_ALSO_DOWNLOAD_THE_PACKAGE
¶ ↑#¶ ↑
- SHALL_WE_ALSO_UPDATE_THE_LAST_UPDATE_ENTRY
#¶ ↑
SHALL_WE_ALSO_UPDATE_THE_LAST_UPDATE_ENTRY
¶ ↑If true then we will add such an entry.
#¶ ↑
- SHALL_WE_TRY_TO_CHANGE_DIRECTORY_INTO_THE_BASE_DIR
#¶ ↑
SHALL_WE_TRY_TO_CHANGE_DIRECTORY_INTO_THE_BASE_DIR
¶ ↑If true we will cd() if we are in the wrong directory.
#¶ ↑
- SHALL_WE_UPLOAD_THE_COOKBOOK_RECIPE
#¶ ↑
SHALL_WE_UPLOAD_THE_COOKBOOK_RECIPE
¶ ↑If the following constant is set to true, then we will also attempt to upload this program to a remote FTP site. As of August 2018, I have changed the default here to false, since the real benefit of automatically uploading is too small compared to the disadvantages (in particular that this class would take longer before it completes its job).
#¶ ↑
- TRY_TO_REPACKAGE_INTO_TAR_XZ_FORMAT
#¶ ↑
TRY_TO_REPACKAGE_INTO_TAR_XZ_FORMAT
¶ ↑If the following constant is true then incremented programs will be repackaged into .tar.xz, unless they are already in this format.
This constant is thus mostly a convenience setting, if you wish to keep archives in .tar.xz, which I do. However had, by default, this class will NOT repackage, since other users may not want to have this. Currently only class RBT::IncrementProgramVersion will enable this repackaging action specifically.
If we are on a roebe-system then this will be switched to true, aka on.
#¶ ↑
Public Class Methods
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 117 def initialize( i = nil, run_already = true ) reset set_remote_url(i) # ======================================================================= # # === Handle blocks next: # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :do_not_ftp_upload # ===================================================================== # when :do_not_ftp_upload do_not_upload_the_cookbook_recipe else # =================================================================== # # === Handle Hashes next # =================================================================== # if yielded.is_a? Hash # ================================================================= # # === :repackage_into_tar_xz_format # ================================================================= # if yielded.has_key? :repackage_into_tar_xz_format if yielded[:repackage_into_tar_xz_format] == true do_try_to_repackage_into_tar_xz_format end end # ================================================================= # # === :do_not_ftp_upload # ================================================================= # if yielded.has_key? :do_not_ftp_upload do_not_upload_the_cookbook_recipe if yielded.delete(:do_not_ftp_upload) == true end end end end run if run_already end
Public Instance Methods
#¶ ↑
backup_the_old_yaml_file
¶ ↑
We will copy the old file to a backup-location through this method here.
This will usually be at the following location:
/home/Temp/rbt/OldCookbooks/
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 687 def backup_the_old_yaml_file unless @old_file_content == @save_this_data # Only do so if we don't have the same data. location_of_the_yaml_file = location_of_the_yaml_file? _ = rbt_temp_directory?+'OldCookbooks/' mkdir(_) unless Dir.exist? _ output 'Backing up the old file at '+sfile(location_of_the_yaml_file) output 'to `'+sfile(_+File.basename(location_of_the_yaml_file))+'`.' copy_file(location_of_the_yaml_file, _) end end
#¶ ↑
check_whether_file_exists_or_not
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 381 def check_whether_file_exists_or_not unless File.exist? location? e output tomato('We were unable to find `')+ sfile(location?)+ tomato('`.') output 'Make sure that it exists, in case that it should exist.' output 'Exiting now.' e exit end end
#¶ ↑
consider_changing_directory
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 446 def consider_changing_directory if SHALL_WE_TRY_TO_CHANGE_DIRECTORY_INTO_THE_BASE_DIR _ = source_directory?+@program_information.short_name?.downcase # .upcase # No longer need .upcase() since Jun 2015. _ << '/' unless _.end_with? '/' _.delete!('_') if _.include? '_' # Directories must not contain a '_' character. _.delete!('-') if _.include? '-' unless (Dir.pwd+'/').squeeze('/') == _ # Need the .squeeze to append a '/'. output "#{rev}Now changing to the directory `#{sdir(_)}#{rev}`." cd _, :ensure_that_the_directory_exists end end end
#¶ ↑
consider_downloading_this_package
(download tag, wget tag)¶ ↑
In this method we may download the remote file package, but only if we can not find a file with the same name in the directory.
Once the download has finished, we may also repackage the archive into the .tar.xz format.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 714 def consider_downloading_this_package( i = remote_url? ) consider_changing_directory if shall_we_also_download_the_package? if is_on_roebe? rename_kde_konsole_tab( File.basename(i) ) end case use_which_download_mode? # ===================================================================== # # === :ruby_wrapper_over_wget # ===================================================================== # when :ruby_wrapper_over_wget Wget.new(i) {{ namespace: 'RBT→Wget' }} # Delegate to Wget here. # ===================================================================== # # === :system_wget # ===================================================================== # when :system_wget esystem "wget #{i}" else e 'Not allowed mode: '+use_which_download_mode?.to_s exit end if @try_to_repackage_into_tar_xz_format # =================================================================== # # Presently the formats .tar.gz, .tar.bz2, .tgz and .gzip will # be repackaged, if the class is instructed to do so. # =================================================================== # if i.end_with?('.tar.gz') or i.end_with?('.tar.bz2') or i.end_with?('.tgz') or i.end_with?('.zip') repackage( File.basename(i) ) end end end unless File.exist?(File.basename(i)) end
#¶ ↑
consider_downloading_this_package_and_then_updating_the_expanded_cookbooks_dataset
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 806 def consider_downloading_this_package_and_then_updating_the_expanded_cookbooks_dataset consider_downloading_this_package consider_updating_the_expanded_cookbooks_dataset end
#¶ ↑
consider_handling_a_changelog_entry
¶ ↑
This method can be used to keep a “changelog” entry of last updates.
Whenever we update a program via class UpdateEntry
, we will also upload to a remote .html page, if we are on a roebe-system.
We will keep a format that is very similar to slackware changelogs.
An example for that can be seen here:
www.slackware.com/changelog/current.php?cpu=x86_64
Keep in mind that we will use a SIMPLIFIED version.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 227 def consider_handling_a_changelog_entry if is_on_roebe? remote_url = URL_TO_REMOTE_CHANGELOG # ===================================================================== # # Check if the remote website exists. If so we download it via # open-uri. # ===================================================================== # #if Wget.does_this_remote_website_exist?(remote_url) # dataset = open(remote_url).read # ===================================================================== # # Else we have to generate the String anew. # ===================================================================== # #else #end string_to_append = CHANGELOG_SEPARATOR_LINE.dup+N+BR.dup # ===================================================================== # # We will use a UTC format, similar to slackware too. # ===================================================================== # string_to_append << return_utc_time_in_a_format_similar_to_slackware+ BR.dup+N+BR.dup+N string_to_append << File.basename(location?).sub(/\.yml$/,'')+ ' version: '+@new_program_version.to_s+N # ===================================================================== # # Put it into a .html file. # ===================================================================== # html_page_content = '<html><title>RBT Changelog</title>'.dup html_page_content << '<body>'+string_to_append+'</body></html>' into = log_dir?+ File.basename(remote_url).downcase opne "Storing into `#{sfile(into)}`. #{steelblue('[Changelog]')}" write_what_into(html_page_content, into) # ===================================================================== # # Uploading the recipe as well. # ===================================================================== # if @shall_we_upload_the_cookbook_recipe opne "Next trying to upload the file `#{sfile(into)}` onto "\ "the remote website." begin FtpParadise.upload(into) rescue Net::FTPTempError => error pp error pp error.class opne 'The above error occurred.' end end end end
#¶ ↑
consider_modifying_the_dataset
¶ ↑
This method will work on @save_this_data and do some modifications, if a certain constant was set to true.
It will update the “last_update: ” entry in the corresponding .yml file at hand.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 820 def consider_modifying_the_dataset if @save_this_data.any? {|line| line.include? 'last_update' } # Then remove this line. @save_this_data.reject! {|line| line.include? 'last_update' } end # It is ok to add it as last line. @save_this_data << " last_update: #{get_extended_date}" end
#¶ ↑
consider_updating_the_expanded_cookbooks_dataset
¶ ↑
This method will try to update the dataset stored in the expanded cookbooks. This should help us avoid full-scale regeneration of these yaml files.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 647 def consider_updating_the_expanded_cookbooks_dataset if expanded_cookbooks_directory_exists? # ===================================================================== # # In this case, simply dump the entry. # ===================================================================== # program_name = ProgramInformation.new(remote_url?).program_name?.delete('_-') cookbook_dataset = action(:SanitizeCookbook, program_name) { :simple } hash_to_store = cookbook_dataset.return_hash # ===================================================================== # # Save the Hash next. # ===================================================================== # what = YAML.dump(hash_to_store) into = "#{RBT.expanded_cookbooks?}#{program_name.downcase}.yml" opne 'Also saving the expanded dataset into `'+sfile(into)+'`.' write_what_into(what, into) # ===================================================================== # # Store it into my home-directory as well. This can then be used # when updating the rbt-gem. # ===================================================================== # if is_on_roebe? into = "#{RUBY_SRC_DIR_RBT_YAML_AT_HOME}expanded_cookbooks/#{program_name.downcase}.yml" opne 'Also saving the expanded dataset into `'+sfile(into)+'`.' write_what_into(what, into) require 'rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb' RBT.expand_cookbooks(program_name) end end end
#¶ ↑
handle_triggered_post_download_events
¶ ↑
The method here can handle some post-download events, at the least on my home system.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 505 def handle_triggered_post_download_events if @remote_url.include?('linux-') and @remote_url.include?('/www.kernel.org') and @remote_url.split('/').last.start_with?('linux-') # This here to avoid: http://www.kernel.org/pub/linux/utils/util-linux/v2.35/util-linux-2.35.2.tar.xz is_on_roebe? # ===================================================================== # # Also install the linux kernel headers on my home system at once # in this case. # ===================================================================== # require 'rbt/requires/require_the_installer_class.rb' action(:Installer, ['linux', :do_not_run_yet]). install_the_linux_kernel_header_files_via_appdir_prefix end end
#¶ ↑
keep_track_of_all_programs_that_were_updated
¶ ↑
Since as of 01.01.2020 we will also store the timestamp into that file.
The .yml file may typically reside e. g. here:
/home/Temp/rbt/these_programs_were_updated.yml
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 592 def keep_track_of_all_programs_that_were_updated # ======================================================================= # # Next designate which timestamp is to be used: # ======================================================================= # current_timestamp = "#{dd_mm_yyyy}-#{ss_mm_hh}" what = " - #{name_of_the_program_that_was_updated?.ljust(30)} "\ "# program_version: #{program_version?.to_s.rjust(10)} "\ "#{current_timestamp}#{N}" into = "#{rbt_log_dir?}these_programs_were_updated.yml" opne "#{rev}Appending `#{sfancy(what.strip)}#{rev}#{rev}` "\ "into `#{sfile(into)}#{rev}`." append_what_into(what, into) # ======================================================================= # # === Generate a copy as well # # And generate a copy too - this copy is important, as it will # be deleted whenever the RBT project is manually uploaded. # ======================================================================= # append_what_into(what, into.delete_suffix('.yml')+'_copy.yml') if is_on_roebe? # ===================================================================== # # And use this on my home directory as well. # ===================================================================== # into = "#{RUBY_SRC_DIR_AT_HOME}/rbt/lib/rbt/"\ "yaml/these_programs_were_updated.yml" opne "Appending `#{sfancy(what.strip)}` into `#{sfile(into)}`." append_what_into(what, into) new_into = into.sub(/\.yml$/,'')+'_copy.yml' opne "#{rev}Appending `#{sfancy(what.strip)}#{rev}` "\ "into `#{sfile(new_into)}#{rev}`." append_what_into(what, new_into) end end
#¶ ↑
location?¶ ↑
This feedbacks the local yaml file in question, such as ‘htop.yml’ and similar.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 281 def location? @location end
#¶ ↑
name_of_the_program_that_was_updated?¶ ↑
This method will return the name of the remote program, with ‘-’ and ‘_’ removed.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 486 def name_of_the_program_that_was_updated? File.basename(location?). sub(/\.yml$/,''). delete('-_') end
#¶ ↑
read_file
¶ ↑
This will read in the dataset. We must be careful with File.readlines() as the encoding may be US-ASCII.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 328 def read_file output 'Now working on the file' e report_the_file_location_via_elegant_colours e if File.exist? location? @old_file_content = readlines_with_proper_encoding(location?) @old_file_content.map!(&:chomp) # Remove the newlines next. _ = @old_file_content.dup # Work on a copy here. _.each {|line| line = line.dup # Next we work on only those entries which contain an " url1:" entry if line =~ / url1:/ position = line.index(':') # Find the first : # Next, simply append it after the position character. if remote_url?.include? '/' # Here we assume this to be a full url. line[position..-1] = ': '+remote_url? else # Here we assume it not be a full url yet. full_url = line[(position+2)..-1] splitted = full_url.split('/') url = splitted[0..-2].join('/')+'/' # =============================================================== # # Find out the archive type of a package. # =============================================================== # archive = archive_type_of?(splitted[-1]) # bl $RUBY_RBT/lib/cookbooks/archive_type.rb assign_line_to_this = ': '+url+remote_url?+archive.to_s line[position..-1] = assign_line_to_this end use_this_as_new_program_version = ProgramInformation.new(line[position..-1]).program_version? set_new_program_version(use_this_as_new_program_version) end @save_this_data << line } end end
#¶ ↑
remote_url?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 476 def remote_url? @remote_url end
#¶ ↑
report_the_file_location_via_elegant_colours
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 314 def report_the_file_location_via_elegant_colours _ = location? dirname = File.dirname(_) basename = File.basename(_) e " #{sfile(dirname)}/#{tomato(basename)}"\ " (#{royalblue(@program_information.name?.downcase)})" end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 162 def reset super() infer_the_namespace # ======================================================================= # # === :shall_we_also_download_the_package # ======================================================================= # @internal_hash[:shall_we_also_download_the_package] = SHALL_WE_ALSO_DOWNLOAD_THE_PACKAGE # ======================================================================= # # === :use_this_download_mode # # This variable determines how this class will download the remote # archive. # # The default is :ruby_wrapper_over_wget, meaning we will make use of # the wget-wrapper, if it is available. If it is not available then # the raw system wget will be used instead, denoted via :system_wget. # # Note that the assigment :ruby_wrapper_over_wget may be changed # when the wrapper is not available. # ======================================================================= # @internal_hash[:use_this_download_mode] = :ruby_wrapper_over_wget # ======================================================================= # # === @new_program_version # ======================================================================= # @new_program_version = nil # ======================================================================= # # === @save_this_data # ======================================================================= # @save_this_data = [] # Is an Array. # ======================================================================= # # === @shall_we_upload_the_cookbook_recipe # ======================================================================= # @shall_we_upload_the_cookbook_recipe = SHALL_WE_UPLOAD_THE_COOKBOOK_RECIPE # ======================================================================= # # === @try_to_repackage_into_tar_xz_format # ======================================================================= # @try_to_repackage_into_tar_xz_format = TRY_TO_REPACKAGE_INTO_TAR_XZ_FORMAT if is_on_roebe? # On my home system I will repackage. @try_to_repackage_into_tar_xz_format = true end end
#¶ ↑
run (run tag, main logic)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 830 def run set_location check_whether_file_exists_or_not read_file backup_the_old_yaml_file # We must back up the old .yml file. save_the_file # We keep a backup too, just in case. sanitize_the_download_mode consider_downloading_this_package_and_then_updating_the_expanded_cookbooks_dataset if is_on_roebe? do_perform_rinstall2 end consider_handling_a_changelog_entry keep_track_of_all_programs_that_were_updated handle_triggered_post_download_events end
#¶ ↑
sanitize_the_download_mode
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 768 def sanitize_the_download_mode _ = use_which_download_mode? case _ # ======================================================================= # # === :ruby_wrapper_over_wget # ======================================================================= # when :ruby_wrapper_over_wget unless IS_THE_WGET_WRAPPER_AVAILABLE @internal_hash[:use_this_download_mode] = :system_wget end end end
#¶ ↑
save_the_file
¶ ↑
Specialized old save functionality.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 525 def save_the_file store_into_this_file = location? if store_into_this_file.include? RUBY_SRC_DIR_AT_HOME # ===================================================================== # # This is the wrong path for now, since we will add the correct # path on roebe lateron. # ===================================================================== # store_into_this_file = "#{individual_cookbooks_directory?}"\ "#{File.basename(store_into_this_file).downcase}" end if are_we_allowed_to_save? if @old_file_content == @save_this_data output 'Can not store the new file because it holds the '\ 'same data as the old file did.', :tomato # Colourize this a bit. else if SHALL_WE_ALSO_UPDATE_THE_LAST_UPDATE_ENTRY consider_modifying_the_dataset # ← This will modify the "last_update: " entry. end output "Storing into the file: #{sfile(store_into_this_file)}" what = @save_this_data.join(N) write_what_into(what, store_into_this_file) # =================================================================== # # If we are on roebe, thus at home, we also backup the old file # directly. # =================================================================== # if is_on_roebe? _ = RUBY_SRC_RBT_COOKBOOKS target = _+File.basename(store_into_this_file).downcase output 'We will also store at `'+sfile(target)+'`.' write_what_into(what, target) # ================================================================= # # On my system, I will also update the programs_version yaml file. # The next few lines of code does precisely that. # ================================================================= # file_programs_version = RBT.file_programs_version if File.exist? file_programs_version new_hash = YAML.load_file(file_programs_version) # ================================================================= # # Need to update only THAT particular program and the version. # ================================================================= # new_hash[program_name?.to_s.downcase] = new_program_version?.to_s # Be careful not to use the old program version here. RBT.generate_programs_version_yaml_file( new_hash ) else output "No file exists at #{sfile(file_programs_version)}." end end end else output 'We are not allowed to save into '\ '`'+sfile(store_into_this_file)+'`.' end end
#¶ ↑
set_location
¶ ↑
Use this method to set the @location variable. This will also set on the @program_information variable.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 291 def set_location @program_information = ProgramInformation.new(remote_url?) _ = @program_information.real_name? if _ _.downcase! _.delete!('_') end # ======================================================================= # # Determine which yaml file is to be used. # ======================================================================= # @location = return_location_to_this_programs_yaml_file(_) end
#¶ ↑
set_remote_url
(url tag, entry tag)¶ ↑
Use this method whenever you wish to set the default URL entry, captured in the @remote_url variable.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 400 def set_remote_url( i = nil ) i = i.first if i.is_a? Array # Only take the first parameter if it is an Array. if i.nil? opne 'Please provide a remote URL to class UpdateEntry.' exit end i = i.to_s.dup # It is now unfrozen. # ======================================================================= # # As of June 2014, we get rid of '~' characters if they come last. # ======================================================================= # i.chop! if i.end_with? '~' # ======================================================================= # # Same as above for when we end with ':' or ',' # ======================================================================= # i.chop! if i.end_with? ':',',' if i.end_with? '?download' i.delete_suffix!('?download') end # ======================================================================= # # We also need to get rid of .tar.bz2 and so forth. Hmm but is this # good? Does not seem to be good, so I disabled it as of Mar 2013. # ======================================================================= # # i = remove_extension(i) # ======================================================================= # # In Jun 2013, the following logic section was added - if the URL # includes the string "sourceforge", and the last part is "download", # we will chop it off that part and use the modified variant instead. # ======================================================================= # if i.include?('sourceforge') and i[-'/download'.size,'/download'.size] == '/download' i[-'/download'.size,'/download'.size] = '' # chop it off here. end @remote_url = i end
#¶ ↑
toggle_the_mode
¶ ↑
This method can be used to simply toggle between the two major modes of this class.
#¶ ↑
# File lib/rbt/utility_scripts/update_entry/update_entry.rb, line 787 def toggle_the_mode _ = use_which_download_mode? case _ # ======================================================================= # # === :system_wget # ======================================================================= # when :system_wget @internal_hash[:use_this_download_mode] = :ruby_wrapper_over_wget # ======================================================================= # # === :ruby_wrapper_over_wget # ======================================================================= # when :ruby_wrapper_over_wget @internal_hash[:use_this_download_mode] = :system_wget end end