class RBT::SymlinkThisProgram

Constants

ARRAY_ALLOWED_SUBDIRECTORIES
#

ARRAY_ALLOWED_SUBDIRECTORIES

Which subdirectories are allowed for this class. bin/, sbin/ and lib/ are the three main directories.

#
DO_REGISTER_INTO_THE_LOCAL_YAML_DATABASE
#

DO_REGISTER_INTO_THE_LOCAL_YAML_DATABASE

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( commandline_arguments = ARGV, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/symlink_this_program/initialize.rb, line 42
def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  case run_already
  when :do_not_run_yet,
       :dont_run_yet
    run_already = false
  end
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_run_yet
    # ===================================================================== #
    when :do_not_run_yet
      run_already = false
    # ===================================================================== #
    # === :do_not_register
    # ===================================================================== #
    when :do_not_register
      do_not_register_into_the_local_yaml_database
    end
  end
  run if run_already
end

Public Instance Methods

consider_removing_empty_directories() click to toggle source
#

consider_removing_empty_directories

#
# File lib/rbt/symlink_this_program/misc.rb, line 203
def consider_removing_empty_directories
  do_remove_empty_directories if @remove_empty_directories
end
consider_symlinking_headers() click to toggle source
#

consider_symlinking_headers

This must be conditionally - some programs will specify that we symlink headers whereas others will not.

#
# File lib/rbt/symlink_this_program/misc.rb, line 22
def consider_symlinking_headers
  _ = program_name?
  require 'rbt/cookbooks/class/class.rb'
  # ======================================================================= #
  # Next, load up the yaml file.
  # ======================================================================= #
  if @shall_we_symlink_the_headers
    shall_we_symlink_the_headers = @shall_we_symlink_the_headers
  else
    @dataset = RBT::Cookbooks::Cookbook.new(_) { :bypass_menu_check }
    shall_we_symlink_the_headers = @dataset.shall_we_symlink_the_headers?
  end
  if shall_we_symlink_the_headers
    # ===================================================================== #
    # Ok, in this case we delegate to class SymlinkHeaders.
    # ===================================================================== #
    require 'rbt/utility_scripts/symlink_headers.rb'
    RBT::SymlinkHeaders.new(_)
  end
end
consider_symlinking_pkgconfig_files() click to toggle source
#

consider_symlinking_pkgconfig_files

This method can be used to symlink .pc files into the /usr/lib/pkgconfig hierarchy.

#
# File lib/rbt/symlink_this_program/symlink.rb, line 19
def consider_symlinking_pkgconfig_files
  appdir_target = full_path_to_the_target_program?
  # ======================================================================= #
  # The appdir_target variable may be incorrect, such as when we symlink
  # another version.
  # ======================================================================= #
  if appdir_target.respond_to? :split
    splitted = appdir_target.split('/')
    unless splitted.last == full_path_to_the_target_program?.split('/').last
      appdir_target = full_path_to_the_target_program?
    end
  else
    opnn; e 'A minor problem - appdir_target does not respond to the method .split.'
    opnn; e 'We will still continue, though.'
  end
  if @dataset.symlink_pkgconfig_files? and
     appdir_target.include?(programs_dir?)
    require 'rbt/utility_scripts/symlink_pkgconfig_files.rb'
    opnn; e "Next, we will symlink all .pc files found "\
            "under `#{sdir(appdir_target)}`."
    SymlinkPkgconfigFiles.new(appdir_target)
  end
end
current_target?() click to toggle source
#

current_target?

This will yield a String as a result, such as '/Programs/Htop/Current/'.

These constitute our the symlink-targets.

We must retain a trailing '/' here.

#
# File lib/rbt/symlink_this_program/misc.rb, line 102
def current_target?
  _  = programs_directory?.to_s.dup
  if name_of_the_program?
    if do_capitalize?
      _ << name_of_the_program?.capitalize
    else
      _ << name_of_the_program?
    end
  else
    #opnn; e swarn('No name of the program is known.')
  end
  _ << '/Current/'
  _ = rds(_)
  return _
end
Also aliased as: target?
do_keep_empty_directories() click to toggle source
#

do_keep_empty_directories

#
# File lib/rbt/symlink_this_program/misc.rb, line 189
def do_keep_empty_directories
  @remove_empty_directories = false
end
Also aliased as: keep_empty_directories
do_not_register()
do_not_register_into_the_local_yaml_database() click to toggle source
#

do_not_register_into_the_local_yaml_database

#
# File lib/rbt/symlink_this_program/misc.rb, line 121
def do_not_register_into_the_local_yaml_database
  @do_register_into_the_local_yaml_database = false
end
Also aliased as: do_not_register
do_register_into_yaml_database( i = full_path? ) click to toggle source
#

do_register_into_yaml_database

#
# File lib/rbt/symlink_this_program/misc.rb, line 421
def do_register_into_yaml_database(
    i = full_path?
  )
  if i
    unless i.include? '/'
      i = static_appdir_prefix_of?(i, program_version?)
    end
    if RBT.register_program_files_into_yaml_database?
      RBT::RegisterProgramFilesIntoYamlDatabase.new(i)
    end
  end
end
do_remove_empty_directories() click to toggle source
#

do_remove_empty_directories

This method will remove directories that are empty. For this, we will make of the method remove() which resides in shared.rb.

#
# File lib/rbt/symlink_this_program/misc.rb, line 168
def do_remove_empty_directories
  if run_simulation?
    opnn; e 'As we are running in simulation mode, we will not remove '
    opnn; e 'any of the following directories:'
    e
    pp remove_these_directories?
    e
  else # Removing the directories next.
    unless remove_these_directories?.empty?
      opnn; e "Removing these #{slateblue('(empty)')} directories next:"
      remove_these_directories?.each {|entry|
        e "  #{sdir(entry)}"
      }
      remove(remove_these_directories?)
    end
  end
end
full_path?()
full_path_to_the_target_program?() click to toggle source
#

full_path_to_the_target_program?

#
# File lib/rbt/symlink_this_program/misc.rb, line 219
def full_path_to_the_target_program?
  @full_path_to_the_target_program
end
Also aliased as: prefix?, full_path?
inform_the_user_what_will_be_done() click to toggle source
#

inform_the_user_what_will_be_done (inform tag)

#
# File lib/rbt/symlink_this_program/misc.rb, line 227
def inform_the_user_what_will_be_done
  opnn; e "Working on #{sfancy(program_name?)}. The "\
          "subdirectories found at"
  opnn; e "`"\
          "#{sfancy(@full_path_to_the_target_program)}` "\
          "will be symlinked."
end
input?()
keep_empty_directories()
keep_empty_directories?() click to toggle source
#

keep_empty_directories?

#
# File lib/rbt/symlink_this_program/misc.rb, line 196
def keep_empty_directories?
  !@remove_empty_directories
end
keep_track_which_program_was_last_symlinked() click to toggle source
#

keep_track_which_program_was_last_symlinked

This method will save the name of the program that this class has been working on, into a local file.

The reasoning behind this behaviour is so that we can use this in other classes, such as when we use :last on the commandline. The class that will act on :last will then pick up the content of the file that we have been using to store this information into. This then allows us to always refer to the “last program that was symlink_program-ed”, which is quite convenient as we don't have to remember the name.

#
# File lib/rbt/symlink_this_program/misc.rb, line 412
def keep_track_which_program_was_last_symlinked
  what = program_name?
  into = file_last_symlinked_program?
  write_what_into(what, into)
end
menu(i) click to toggle source
#

menu (menu tag)

All commandline options for this class can be passed through the menu() method here.

#
name_of_the_program?()
prefix?()
program?()
program_name?()
program_version?() click to toggle source
#

program_version?

This method should return the program-version of the program at hand.

#
# File lib/rbt/symlink_this_program/misc.rb, line 212
def program_version?
  @program_version
end
register_for_removal(i) click to toggle source
#

register_for_removal

This method will register a directory for removal. Store the absolute path here.

The check whether the directory is empty or not is done in another part of this class.

#
# File lib/rbt/symlink_this_program/misc.rb, line 151
def register_for_removal(i)
  @array_remove_these_directories << i
end
remove_and_store_commandline_arguments_from(i) click to toggle source
#

remove_and_store_commandline_arguments_from

Keep in mind that the input may be either an Array or a String.

Presently we will support only Array as input here - Strings are ignored.

#
# File lib/rbt/symlink_this_program/misc.rb, line 132
def remove_and_store_commandline_arguments_from(i)
  if i.is_a? Array
    if i.any? {|entry| entry.include? '--' }
      menu(i.select {|entry| entry.include? '--' })
      i.reject! {|entry| entry.include? '--'}
    end
  end
  return i
end
remove_these_directories?() click to toggle source
#

remove_these_directories?

#
# File lib/rbt/symlink_this_program/misc.rb, line 158
def remove_these_directories?
  @array_remove_these_directories
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/symlink_this_program/reset.rb, line 14
def reset
  super()
  @namespace = NAMESPACE
  @be_verbose = true
  @use_opn = true
  @program_version = nil
  # ======================================================================= #
  # The next variable determines if we will actually symlink or whether
  # we will not.
  # ======================================================================= #
  @will_we_symlink = true
  # ======================================================================= #
  # The next variable will store the NAME of the program at hand, in
  # a downcased manner. We must initialize it to nil here first, though.
  # ======================================================================= #
  @symlink_this_program = nil
  @full_path_to_the_target_program = nil
  # ======================================================================= #
  # The next instance variable determines whether we will remove empty
  # directories or not. By default we will do so, but this behaviour
  # has to be modifiable as not every user may wish to have this,
  # hence why this instance variable exists.
  # ======================================================================= #
  @remove_empty_directories = true
  @array_remove_these_directories = []
  @shall_we_symlink_the_headers = false
  @do_register_into_the_local_yaml_database =
    DO_REGISTER_INTO_THE_LOCAL_YAML_DATABASE
end
return_program_version_of_this_program_at(i) click to toggle source
#

return_program_version_of_this_program_at

This method will attempt to determine the version of a given program to which the “Current” symlink should point at.

#
# File lib/rbt/symlink_this_program/misc.rb, line 49
def return_program_version_of_this_program_at(i)
  directories = Dir["#{i}*"].select {|entry| File.directory? entry }
  result = directories.sort.first
  return result
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/symlink_this_program/run.rb, line 14
def run
  run_everything
end
run_everything() click to toggle source
#

run_everything

#
# File lib/rbt/symlink_this_program/run.rb, line 21
def run_everything
  if @will_we_symlink
    determine_which_program_to_symlink
    # ===================================================================== #
    # We must next ensure that the -> Current symlink exists.
    # ===================================================================== #
    ensure_that_the_current_symlink_exists
    do_symlink_all_entries
    consider_removing_empty_directories
    # ===================================================================== #
    # Register into the yaml database, before symlinking pkgconfig
    # files.
    # ===================================================================== #
    do_register_into_yaml_database if @do_register_into_the_local_yaml_database
    consider_symlinking_headers # <- Should come before symlinking pkgconfig files
    consider_symlinking_pkgconfig_files # <- Should come before saving the name of the program into a local file.
    keep_track_which_program_was_last_symlinked
  end
end
set_commandline_arguments(i) click to toggle source
#

set_commandline_arguments

#
# File lib/rbt/symlink_this_program/setters.rb, line 37
def set_commandline_arguments(i)
  i = [i].flatten.compact
  i = remove_and_store_commandline_arguments_from(i) # <- This also passes into menu().
  @commandline_arguments = i
end
set_full_path_to_the_target_program( i = :default ) click to toggle source
#

set_full_path_to_the_target_program

#
# File lib/rbt/symlink_this_program/setters.rb, line 53
def set_full_path_to_the_target_program(
    i = :default
  )
  case i
  when :default
    i = static_appdir_prefix_of?(name_of_the_program?, program_version?)
  else
    unless i.include? '/'
      i = static_appdir_prefix_of?(i, program_version?)
    end
  end
  @full_path_to_the_target_program = i
end
Also aliased as: set_prefix
set_name_of_the_program( i = :default )
set_prefix( i = :default )
set_program_version(i) click to toggle source
#

set_program_version

#
# File lib/rbt/symlink_this_program/setters.rb, line 46
def set_program_version(i)
  @program_version = i
end
Also aliased as: set_version
set_use_this_program( i = :default )
set_version(i)
Alias for: set_program_version
target?()
Alias for: current_target?
try_to_save_the_name_of_the_program_into_a_local_file()