Class: RBT::UpdateEntry

Inherits:
Base show all
Defined in:
lib/rbt/utility_scripts/update_entry/update_entry.rb

Overview

RBT::UpdateEntry

Constant Summary collapse

DEFAULT_URL =
#

DEFAULT_URL

This URL is only for testing purposes. Do not actively set it if you are NOT testing the functionality.

#
'ftp://ftp.kernel.org/pub/software/scm/git/git-1.6.6.tar.bz2'
ARE_WE_ALLOWED_TO_SAVE =
#

ARE_WE_ALLOWED_TO_SAVE

#
true
SHALL_WE_ALSO_DOWNLOAD_THE_PACKAGE =
#

SHALL_WE_ALSO_DOWNLOAD_THE_PACKAGE

#
true
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.

#
true
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.

#
true
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).

#
false
CHANGELOG_SEPARATOR_LINE =
#

CHANGELOG_SEPARATOR_LINE

This is the same line used by slackware.

#
'+--------------------------+'
BR =
#

BR

#
'<br>'.freeze
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.

#
false

Constants inherited from LeanPrototype

LeanPrototype::ALL_COLOUR_METHODS, LeanPrototype::ARRAY_KDE_KONSOLE_COLOURS_IN_USE, LeanPrototype::DAY_NAMES, LeanPrototype::NAMESPACE, LeanPrototype::SILENT_REDIRECTION

Instance Method Summary collapse

Methods inherited from Base

#cat, #cd_back_to_the_current_working_directory, #consider_reporting_how_many_programs_are_registered, #cookbook_files?, #copy_recursively, #delete_code_of_conduct?, #determine_appdir_prefix_from_this_input, #directory_validation?, #do_not_show_names, #fast_return_file_size_of_this_program, #file_last_symlinked_program?, #file_programs_version_url, #gem_version, #is_a_64bit_system?, #is_ccache_available?, #is_porg_available?, #is_this_binary_registered?, #is_this_program_included?, #make_command?, #make_install_command?, #new_cookbook_instance_for, #program_exists?, #publish_list_of_all_programs_version, #rcp, registered_binaries?, #remove_symlink, #rename_kde_konsole_tab, #repackage, #report_n_programs, #report_working_directory, #return_compile_time_statistics, #return_n_random_characters, #return_version_of_this_program, #run_make_then_make_install, #sanitize_url1_entry, #set_source_directory, #show_overview_over_available_utility_scripts, #symlink_all_files_from_this_directory_to_that_directory, #system_tags?, #upload_list_of_all_programs_version, #use_yaml_database_for_tags?, #warn_and_exit, #wget

Methods inherited from LeanPrototype

#a_or_an?, #abbreviations?, #absolute_path, #action, #add_to_the_commandline_arguments, #all_binaries?, #all_files_from, #all_libraries?, #allowed_cookbook_entries?, #appdir_location_of?, #append_onto_the_internal_hash, #append_what_into, #archive_type_of?, #available_programs?, #be_quiet?, #be_verbose?, #begins_with_a_comment?, #capitalize_first_alphabetical_character, #cd_to_the_log_directory, #cd_to_the_temp_directory, #change_directory, #change_permission, #cheering_person?, #chmod, #chop_off_archive, #clear_commandline_arguments, #cliner, #coloured_and_padded_e, #coloured_and_padded_esystem, #coloured_esystem, #colourize_directory_for_system_results, #colourize_this_error, #colourize_this_file_path, #colourize_this_warning, #commandline_arguments?, #commandline_arguments_without_hyphens?, #comment, #convert_dd_mm_yyyy_to_its_long_variant, #convert_env_variable, #copy_directory, #copy_files, #cpr, #create_directory, #current_hour?, #dd_mmm_yyy, #debug, #debug?, #directory_expanded_cookbooks?, #disable_colours, #display_md5sum?, #do_not_debug, #does_the_cookbook_include_this_program?, #does_this_expanded_cookbook_file_exist_for_this_program?, #does_this_file_exist?, #does_this_file_exist_and_is_it_a_file?, #e, #eblue, #ecomment, #ecrimson, #edir, #editor?, #efancy, #eimp, #enable_colours, #enable_debug, #ensure_main_encoding_for, #eparse, #esystem, #esystem_gold, #etomato, #ewarn, #exit_program, #expanded_cookbooks_directory_exists?, #extract_this_archive, #extract_to?, #file_compiled_programs?, #file_dirname_retaining_trailing_slash, #file_predefined_installation_instructions?, #file_specification_of_registered_cookbook_entries, #find_cookbook_alias_for, #find_this_yaml_file, #first_argument?, #first_non_hyphen_argument?, #get_all_directories_from, #get_all_files_from, #get_all_programs, #get_date, #get_extended_date, #get_files_and_directories_from, #go_to_base_dir, #home_dir?, #host_system?, #infer_the_namespace, #internal_hash?, #internal_hash_set_commandline_arguments, #is_an_archive?, #is_directory?, #is_file?, #is_github_url?, #is_make_available?, #is_meson_installed?, #is_on_gobolinux?, #is_on_windows?, #is_roebe?, #is_superuser?, #is_symlink?, #is_this_a_header?, #is_this_a_library?, #is_this_program_included?, #iso_encoding?, #load_dataset_from_this_expanded_cookbook, #load_yaml, #load_yaml_file_from_the_cookbook_directory_for_this_program, #log_directory?, #main_encoding?, #meson_build_file_exists?, #months?, #move_file, #n_programs_are_available?, #n_programs_available?, #namespace?, #no_directory_exists_at, #no_directory_was_found_at, #no_opn, #no_such_file_exists, #open_in_browser, #open_in_editor, #opncomment, #opne, #opnef, #opnerev, #opnerror, #opnesystem, #opnewarn, #opnfancy, #opnn, #otomato, #packages_directory?, #path_to_this_expanded_cookbooks_dataset, #pkgconfig_directory?, #populate_the_internal_hash_with_default_values, #predefined_installation_instructions?, #prepend_this_commandline_argument, #program_version_of?, #project_base_directory?, #project_yaml_directory?, #query_path?, #rarrow?, #read_file_in_default_encoding, #read_file_with_default_encoding, #readlines, #readlines_with_proper_encoding, #register_sigint, #registered_cookbook_entries?, #remove, #remove_archive_from_the_end, #remove_comments_from_each_line, #remove_directory, #remove_double_slashes, #remove_file, #remove_newlines, #remove_parens, #remove_symlink, #remove_the_first_commandline_argument, #remove_this_commandline_argument, #remove_this_entry_from_the_commandline_arguments, #remove_trailing_ANSII_escape_code, #remove_unnecessary_data_from_url, #rename, #report_pwd, #require_the_rbt_aliases, #reset_the_internal_hash, #return_all_archives_from_this_directory, #return_appdir_prefix, #return_commandline_arguments_with_leading_hyphens, #return_current_hour_minutes_second, #return_date, #return_day_of_the_month_based_on_utc, #return_full_time, #return_hours_minutes_seconds_based_on_utc, #return_location_to_this_programs_yaml_file, #return_month_based_on_this_number, #return_month_based_on_utc, #return_opnn, #return_program_name, #return_program_name_for_gobolinux_systems, #return_program_name_via_program_information, #return_pwd, #return_unicode_warning_symbol_or_empty_string, #return_utc, #return_utc_time_in_a_format_similar_to_slackware, #return_weekday_based_on_utc, #return_year_based_on_utc, #rev, #rpn, #run_simulation=, #run_simulation?, #sdir, #sdir_return_pwd, #set_be_silent, #set_be_verbose, #set_first_commandline_argument, #set_namespace, #set_use_colours, #set_use_opn, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #silently_create_this_directory_if_it_does_not_yet_exist, #simp, #source_base_directory?, #ssym, #stderr, #store_into_this_directory?, #string_right_arrow?, #swarn, #symlink, #sysbin_directory?, #sysetc_directory?, #sysinclude_directory?, #syslib_directory?, #sysshare_directory?, #system_directory?, #temp_directory?, #to_bool, #to_camelcase, #to_iso_encoding, #to_unicode, #today?, #touch, #try_to_require_beautiful_url, #try_to_require_the_environment_information_gem, #try_to_require_the_extracter_gem, #try_to_require_the_open_gem, #try_to_require_the_xorg_buffer, #try_to_require_wget, #try_to_return_a_special_compile_component, #unicode_cliner, #unicode_middle_cliner, #use_colours=, #use_colours?, #use_opn=, #use_opn?, #utf_encoding?, #verbose_truth, #word_wrap, #write_what_into, #write_what_into_via_unicode, #yes_or_no

Constructor Details

#initialize(i = nil, run_already = true) ⇒ UpdateEntry

#

initialize

#


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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

Instance Method Details

#are_we_allowed_to_save?Boolean

#

are_we_allowed_to_save?

#

Returns:

  • (Boolean)


439
440
441
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 439

def are_we_allowed_to_save?
  ARE_WE_ALLOWED_TO_SAVE
end

#backup_the_old_yaml_fileObject

#

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/
#


687
688
689
690
691
692
693
694
695
696
# 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_notObject

#

check_whether_file_exists_or_not

#


381
382
383
384
385
386
387
388
389
390
391
392
# 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_directoryObject

#

consider_changing_directory

#


446
447
448
449
450
451
452
453
454
455
456
457
# 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(i = remote_url? ) ⇒ Object

#

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.

#


785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 785

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::UpdateEntry→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_datasetObject

#

consider_downloading_this_package_and_then_updating_the_expanded_cookbooks_dataset

#


755
756
757
758
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 755

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_entryObject

#

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.

#


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# 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_datasetObject

#

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.

#


769
770
771
772
773
774
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 769

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_datasetObject

#

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.

#


647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# 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

#do_not_upload_the_cookbook_recipeObject

#

do_not_upload_the_cookbook_recipe

#


207
208
209
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 207

def do_not_upload_the_cookbook_recipe
  @shall_we_upload_the_cookbook_recipe = false
end

#do_perform_rinstall2Object

#

do_perform_rinstall2

#


708
709
710
711
712
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 708

def do_perform_rinstall2
  cd '/home/x/programming/ruby/src/rbt/'
  require 'roebe'
  ::Roebe.rinstall2
end

#do_try_to_repackage_into_tar_xz_formatObject

#

do_try_to_repackage_into_tar_xz_format

#


307
308
309
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 307

def do_try_to_repackage_into_tar_xz_format
  @try_to_repackage_into_tar_xz_format = true
end

#handle_triggered_post_download_eventsObject

#

handle_triggered_post_download_events

The method here can handle some post-download events, at the least on my home system.

#


505
506
507
508
509
510
511
512
513
514
515
516
517
518
# 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_updatedObject

#

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
#


592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# 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?Boolean Also known as: location_of_the_yaml_file?

#

location?

This feedbacks the local yaml file in question, such as ‘htop.yml’ and similar.

#

Returns:

  • (Boolean)


281
282
283
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 281

def location?
  @location
end

#name_of_the_program_that_was_updated?Boolean

#

name_of_the_program_that_was_updated?

This method will return the name of the remote program, with ‘-’ and ‘_’ removed.

#

Returns:

  • (Boolean)


486
487
488
489
490
# 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

#new_program_version?Boolean

#

new_program_version?

#

Returns:

  • (Boolean)


374
375
376
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 374

def new_program_version?
  @new_program_version
end

#output(i, use_this_colour = nil) ⇒ Object

#

output

Wrap opn() and e() into this single method.

#


631
632
633
634
635
636
637
638
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 631

def output(i, use_this_colour = nil)
  opnn
  if use_this_colour
    e send(use_this_colour, i)
  else
    e i
  end
end

#program_name?Boolean

#

program_name?

#

Returns:

  • (Boolean)


469
470
471
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 469

def program_name?
  @program_information.program_name?
end

#program_version?Boolean

#

program_version?

#

Returns:

  • (Boolean)


462
463
464
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 462

def program_version?
  @program_information.program_version?
end

#read_fileObject

#

read_file

This will read in the dataset. We must be careful with File.readlines() as the encoding may be US-ASCII.

#


328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# 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?Boolean Also known as: entry?

#

remote_url?

#

Returns:

  • (Boolean)


476
477
478
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 476

def remote_url?
  @remote_url
end

#report_the_file_location_via_elegant_coloursObject

#

report_the_file_location_via_elegant_colours

#


314
315
316
317
318
319
320
# 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

#resetObject

#

reset (reset tag)

#


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# 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

#runObject

#

run (run tag, main logic)

#


830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# 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_modeObject

#

sanitize_the_download_mode

#


717
718
719
720
721
722
723
724
725
726
727
728
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 717

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_fileObject

#

save_the_file

Specialized old save functionality.

#


525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# 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_locationObject

#

set_location

Use this method to set the @location variable. This will also set on the @program_information variable.

#


291
292
293
294
295
296
297
298
299
300
301
302
# 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_new_program_version(i) ⇒ Object

#

set_new_program_version

#


367
368
369
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 367

def set_new_program_version(i)
  @new_program_version = i
end

#set_remote_url(i = nil) ⇒ Object Also known as: assign_url

#

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.

#


400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# 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

#shall_we_also_download_the_package?Boolean

#

shall_we_also_download_the_package?

#

Returns:

  • (Boolean)


495
496
497
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 495

def shall_we_also_download_the_package?
  @internal_hash[:shall_we_also_download_the_package]
end

#toggle_the_modeObject Also known as: toggle_mode

#

toggle_the_mode

This method can be used to simply toggle between the two major modes of this class.

#


736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 736

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

#use_which_download_mode?Boolean

#

use_which_download_mode?

#

Returns:

  • (Boolean)


701
702
703
# File 'lib/rbt/utility_scripts/update_entry/update_entry.rb', line 701

def use_which_download_mode?
  @internal_hash[:use_this_download_mode]
end