class RBT::Action::CreateAppDirSkeleton

Constants

ARRAY_CREATE_THESE_SUBDIRECTORIES
#

ARRAY_CREATE_THESE_SUBDIRECTORIES

This Array will list the subdirectories that are to be created.

Since as of 06.12.2019, these entries should include a trailing ‘/’.

While this is not ultimately necessary, I have found that it makes it a bit more easier to reason about these entries. We can also instantly see that these are directories.

The directory called ‘Resources/` will list various files such as the file `Dependencies`, which lists all dependencies for the given program at hand, on a GoboLinux system.

#
#

We must keep the symlinks for the following programs, as otherwise compilation may fail.

Do note that since as of January 2020, an additional way to specify these entries dynamically exists. In the long run, I will probably merge these two separate instances, but for the time being we will keep having two variants instead.

#
DEFAULT_PROGRAM_VERSION
#

DEFAULT_PROGRAM_VERSION

This constant specifies which program-version to use if it is otherwise omitted. That is just a generic number, though.

#
DEFAULT_RUN_ALREADY
#

DEFAULT_RUN_ALREADY

#
DEFAULT_TEST_INPUT
#

DEFAULT_TEST_INPUT

This should yield a fairly complicated use-case, to test the ability of this class to be useful.

#

Public Class Methods

[](i = ARGV, &block) click to toggle source
#

RBT::Action::CreateAppDirSkeleton[]

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 790
def self.[](i = ARGV, &block)
  new(i, &block)
end
new( commandline_arguments = DEFAULT_TEST_INPUT, run_already = DEFAULT_RUN_ALREADY ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 116
def initialize(
    commandline_arguments = DEFAULT_TEST_INPUT,
    run_already           = DEFAULT_RUN_ALREADY, # ← This is true by default.
    &block
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded # Handle Symbols first.
    # ===================================================================== #
    # === :disable_colours
    # ===================================================================== #
    when :disable_colours
      disable_colours
      @internal_hash[:hash_for_opn].update(use_colours: false)
    end
    # ===================================================================== #
    # === Handle Hashes given to that block next
    # ===================================================================== #
    if yielded.is_a? Hash
      # =================================================================== #
      # === :use_colours
      # =================================================================== #
      if yielded.has_key? :use_colours
        @internal_hash[:hash_for_opn].update(use_colours: false) if yielded.delete(:use_colours) == false
      end
      # =================================================================== #
      # === :use_this_directory_as_the_program_directory
      # =================================================================== #
      if yielded.has_key? :use_this_directory_as_the_program_directory
        @internal_hash[:internal_programs_directory] = yielded.delete(:use_this_directory_as_the_program_directory)
      end
      # =================================================================== #
      # === :use_opn
      # =================================================================== #
      if yielded.has_key? :use_opn
        @internal_hash[:hash_for_opn].update(
          use_opn: yielded.delete(:use_opn)
        )
      end
      # =================================================================== #
      # === :do_not_symlink_these_programs
      #
      # Handle the case where the user does not want us to symlink
      # certain programs, such as 'make'.
      # =================================================================== #
      if yielded.has_key? :do_not_symlink_these_programs
        @internal_hash[:array_do_not_symlink_these_programs] << yielded.delete(:do_not_symlink_these_programs)
        @internal_hash[:array_do_not_symlink_these_programs].flatten!
      end
    end
  end
  case run_already
  # ======================================================================= #
  # === :dont_run_yet
  # ======================================================================= #
  when :dont_run_yet,
       :do_not_run_yet
    run_already = false
  else
    if run_already and !run_already.is_a?(TrueClass) and
      (run_already =~ /^\d+$/)
      set_program_version(run_already)
      run_already = DEFAULT_RUN_ALREADY
    end
  end
  run if run_already
end

Public Instance Methods

create_app_dir_skeleton_at_this_target( _ = first_non_hyphen_argument? )
create_directories( _ = first_non_hyphen_argument? )
create_settings_directory( this_directory = " click to toggle source
#

create_settings_directory

The settings directory will be created at the target_directory?.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 650
def create_settings_directory(
    this_directory = "#{target_directory?}Settings/"
  )
  this_directory = this_directory.dup
  unless this_directory.end_with?('Settings/')
    this_directory << 'Settings/'
  end
  if in_simulation?
    opne "Normally `#{sdir(this_directory)}` would be created but"
    opne 'as we run in '+steelblue('simulation-mode')+', no change '\
         'will be made.'
  else
    opne "#{rev}Creating a directory at #{sdir(this_directory)} #{rev}next."
    create_directory(this_directory, :be_quiet) # Also create a Settings/ subdir:
  end
end
create_the_directories( _ = first_non_hyphen_argument? )
create_these_subdirectories( i = target_directory?, &block )
deconstruct_the_commandline_arguments_if_there_is_more_than_one_of_them() click to toggle source
#

deconstruct_the_commandline_arguments_if_there_is_more_than_one_of_them

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 590
def deconstruct_the_commandline_arguments_if_there_is_more_than_one_of_them
  if commandline_arguments?.size > 1
    _ = commandline_arguments?
    set_program_name(_[0])
    set_program_version(_[1])
  end
end
determine_program_name_and_program_version_from_this_directory( i = return_pwd ) click to toggle source
#

determine_program_name_and_program_version_from_this_directory

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 670
def determine_program_name_and_program_version_from_this_directory(
    i = return_pwd
  )
  _ = File.basename(i)
  prepend_this_commandline_argument(_.delete('/'))
  if _.include? '-'
    set_program_name(ProgramInformation.return_name(_))
    set_program_version(ProgramInformation.return_version(_))
  end
  set_target_directory(_)
end
do_create_the_appdirectory_structure( _ = first_non_hyphen_argument? ) click to toggle source
#

do_create_the_appdirectory_structure

The ideal situation, as input to this method, would be that the user supplied us with the full, absolute path. But this is not always possible or necessary, as input such as “glib-2.40.0” should also work just fine. The method here, thus, has to distinguish between such different use cases.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 379
def do_create_the_appdirectory_structure(
    # ===================================================================== #
    # First, determine the target based on the first argument:
    # ===================================================================== #
    _ = first_non_hyphen_argument?
  )
  _ = sanitize_this_argument(_)
  # ======================================================================= #
  # Next we must determine the program name and the program version, as
  # this may be useful at a later time.
  # ======================================================================= #
  if _.include?('-') and !_.include?('/')
    # ===================================================================== #
    # Assume input such as: glib-2.35.3
    # ===================================================================== #
    program_information = ProgramInformation.new(_)
    set_program_name(program_information.program_name?)
    set_program_version(program_information.program_version?)
    _ = internal_programs_directory?+
        program_name?.capitalize+
        '/'+
        program_version?
  else
    # ===================================================================== #
    # Must still determine the correct program name and program version:
    # ===================================================================== #
    if _.count('/') > 1 # For instance: /home/Programs/Glib/2.40.0
      splitted = _.delete_prefix(internal_programs_directory?).split('/')
      # Now the Array may look like this: ["Glib", "2.40.0"]
      set_program_name(splitted.first)
      set_program_version(splitted.last)
      _ = internal_programs_directory?+
          program_name?.capitalize+
          '/'+
          program_version?
    else
      set_program_name(_.delete('/'))
      set_program_version(:default)
    end
  end
  set_work_on_this_target_directory(_) # Determine our target directory.
  target_directory = target_directory?
  notify_the_user_what_will_be_done
  notify_the_user_about_the_target_directory(target_directory)
  create_directory(target_directory) {{ namespace: namespace? }}
  # ========================================================================= #
  # The next clause will NOT be entered if the --blank flag has been
  # passed.
  # ========================================================================= #
  if may_we_continue_past_the_create_the_main_directory_step?
    # ======================================================================= #
    # Next create the subdirectories and the Settings directory:
    # ======================================================================= #
    do_create_the_subdirectories_and_the_settings_directory(target_directory)
    # ======================================================================= #
    # The following instance variable can be used to disable the creation
    # of the Current symlink.
    # ======================================================================= #
    may_we_create_a_current_symlink = may_we_create_a_current_symlink?
    # ======================================================================= #
    # Now we have to create the Current symlink, if this is allowed - the
    # user can disable this functionality:
    # ======================================================================= #
    if may_we_create_a_current_symlink and
      !array_do_not_symlink_these_programs?.include?(program_name?.downcase.to_sym) # ← This check was added on 20.01.2020.
      create_the_current_symlink(target_directory)
    end
  end
  opne mediumseagreen('All done!')
end
do_create_the_subdirectories( i = target_directory?, &block ) click to toggle source
#

do_create_the_subdirectories

The input argument should be the target directory.

This method will create the various subdirectories.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 744
def do_create_the_subdirectories(
    i = target_directory?,
    &block
  )
  necessary_subdirectories = necessary_subdirectories?
  opne "#{rev}Several subdirectories will be created in the directory"
  opne "#{sdir(i)} #{rev}next, namely:"
  opne "  #{sdir(necessary_subdirectories.join(', ').strip)}"
  # ======================================================================= #
  # Next create the subdirectories:
  # ======================================================================= #
  necessary_subdirectories.each {|this_subdirectory|
    new_target = "#{i}#{this_subdirectory}"
    # ===================================================================== #
    # Must first consider the case where the RBT suite is running in
    # simulation-mode.
    # ===================================================================== #
    if run_simulation? 
      opne "#{rev}We run in simulation mode, thus we will not"
      opne "create the #{steelblue('subdirectory')}"\
           " #{rev}at `#{sdir(new_target)}`."
    else
      opne "Creating the directory #{sdir(new_target)}"
      mkdir(
        new_target,
        {
          verbosity: :be_quiet,
          permissions: 0755,
          namespace:   namespace?
        }
      )
    end
  }
end
Also aliased as: create_these_subdirectories
do_create_the_subdirectories_and_the_settings_directory(i) click to toggle source
#

do_create_the_subdirectories_and_the_settings_directory

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 455
def do_create_the_subdirectories_and_the_settings_directory(i)
  do_create_the_subdirectories(i)
  create_settings_directory(i)
end
do_not_create_anything_aside_from_the_main_directory() click to toggle source
#

do_not_create_anything_aside_from_the_main_directory

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 641
def do_not_create_anything_aside_from_the_main_directory
  @internal_hash[:may_we_continue_past_the_create_the_main_directory_step] = false
end
full_target?( program_name = program_name?, program_version = program_version? )
internal_programs_directory?() click to toggle source
#

internal_programs_directory?

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 716
def internal_programs_directory?
  @internal_hash[:internal_programs_directory]
end
may_we_continue_past_the_create_the_main_directory_step?() click to toggle source
#

may_we_continue_past_the_create_the_main_directory_step?

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 241
def may_we_continue_past_the_create_the_main_directory_step?
  @internal_hash[:may_we_continue_past_the_create_the_main_directory_step]
end
menu( i = commandline_arguments_with_leading_hyphens? ) click to toggle source
#

menu (menu tag)

#
name()
Alias for: program_name?
name?()
Alias for: program_name?
necessary_subdirectories?() click to toggle source
#

necessary_subdirectories?

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 583
def necessary_subdirectories?
  ARRAY_CREATE_THESE_SUBDIRECTORIES
end
Also aliased as: subdirectories?
notify_the_user_about_the_target_directory( i = target_directory? ) click to toggle source
#

notify_the_user_about_the_target_directory

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 463
def notify_the_user_about_the_target_directory(
    i = target_directory?
  )
  opne "#{rev}Next creating an #{steelblue('AppDir')} #{rev}skeleton "\
       "structure at the target directory"
  opne "#{sdir(i)}"
end
notify_the_user_what_will_be_done() click to toggle source
#

notify_the_user_what_will_be_done

Feedback information back to the user.

In June 2007 the amount of information displayed throught his method was reduced. Currently this method is invoked whenever this class creates the main directory hierarchy.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 480
def notify_the_user_what_will_be_done
  opnn; ee sfancy(return_program_name_and_program_version.downcase)
  if be_verbose?
    ee " #{rev}(#{simp('Program name')}: #{sfancy(program_name?)}"\
       "#{rev} and #{simp('Program Version')}#{rev}: "\
       "#{sfancy(program_version?)}#{rev})"
  end
  e # And a newline afterwards.
end
opnn(&block) click to toggle source
#

opnn (opnn tag)

#
Calls superclass method
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 317
def opnn(&block)
  super(return_hash_for_opn, &block)
end
program_name()
Alias for: program_name?
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 531
def program_name?
  @internal_hash[:program_name]
end
Also aliased as: program_name, name, name?
program_version?() click to toggle source
#

program_version?

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 540
def program_version?
  @internal_hash[:program_version]
end
Also aliased as: version?, version
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 194
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === :hash_for_opn
  # ======================================================================= #
  @internal_hash[:hash_for_opn] = return_hash_for_opn
  # ======================================================================= #
  # === :may_we_create_a_current_symlink
  # ======================================================================= #
  @internal_hash[:may_we_create_a_current_symlink] = true
  # ======================================================================= #
  # === :may_we_continue_past_the_create_the_main_directory_step
  # ======================================================================= #
  @internal_hash[:may_we_continue_past_the_create_the_main_directory_step] = true
  # ======================================================================= #
  # === :array_do_not_symlink_these_programs
  #
  # The following Array will skip setting the symlink called
  # 'Current'. This is necessary sometimes for when we upgrade
  # certain programs, such as make, as the symlinkat /usr/bin/make
  # must work at all times, if we are to compile software from
  # source via an AppDir based approach.
  #
  # A constant will populate this Array initialize. This has been
  # confirmed in September 2022.
  # ======================================================================= #
  @internal_hash[:array_do_not_symlink_these_programs] = ARRAY_KEEP_SYMLINKS_FOR_THESE_PROGRAMS
  # ======================================================================= #
  # === :internal_programs_directory
  #
  # We need to use another internal programs directory, so that we
  # can modify the target of this class.
  # ======================================================================= #
  @internal_hash[:internal_programs_directory] = programs_directory?
end
return_hash_for_opn() click to toggle source
#

return_hash_for_opn

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 263
def return_hash_for_opn
 {
   namespace:   namespace?,
   use_colours: use_colours?
 }
end
return_inferred_path_from_the_program_name_and_the_program_version( program_name = program_name?, program_version = program_version? ) click to toggle source
#

return_inferred_path_from_the_program_name_and_the_program_version

This method will assemble the proper base directory under the local AppDir (/Programs) hierarchy, including the program name, and the program version at hand.

It will thus assume (infer) a path.

In order for this to work, both @program_name and @program_version must have been determined.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 610
def return_inferred_path_from_the_program_name_and_the_program_version(
    program_name    = program_name?,
    program_version = program_version?
  )
  "#{program_dir?}#{program_name.capitalize}/#{program_version}/"
end
Also aliased as: full_target?, target?
return_program_name_and_program_version() click to toggle source
#

return_program_name_and_program_version

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 273
def return_program_name_and_program_version
  "#{program_name?.capitalize}-#{program_version?}"
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 782
def run
  menu
  do_create_the_appdirectory_structure
end
sanitize_this_argument(i) click to toggle source
#

sanitize_this_argument

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 685
def sanitize_this_argument(i)
  i = i.flatten.first.to_s if i.is_a? Array
  if is_an_archive?(i)
    i = remove_archive_at_the_end(i.dup)
  end
  # ======================================================================= #
  # Next comes a bit of an ad-hoc sanitizing event. In the past we
  # also removed every '_' in the string, but since as of April 2019
  # this was realised to not be ideal, due to input such as
  # "LibreOffice_6.2.2.2" which is valid. Thus, only the first '_'
  # is replaced with a '-', if there is only a single '_' in that
  # string.
  # ======================================================================= #
  if i.end_with? '_Linux_x86-64'
    i.delete_suffix!('_Linux_x86-64')
  end
  if i.include?('_') and
    (i.count('_') == 1) and
    !i.include?('-')
    i.tr!('_','-') # Example: "LibreOffice_96.2.2.2"
  end
  if i.end_with?('/') and (i.count('/') == 1)
    i = i.dup if i.frozen?
    i.chop!
  end
  return i
end
set_program_name( i = '' ) click to toggle source
#

set_program_name

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 723
def set_program_name(
    i = ''
  )
  if i
    i = i.dup
    i.downcase! # ← This is always done. On GoboLinux, we may have to change this lateron.
    i.delete!('-') if i.include? '-'
    if is_on_gobolinux?
      i = return_program_name_for_gobolinux_systems(i)
    end
  end
  @internal_hash[:program_name] = i
end
set_program_version( i = DEFAULT_PROGRAM_VERSION ) click to toggle source
#

set_program_version

This method will set the program version of our program at hand.

1.0.0 is the default program version to use.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 508
def set_program_version(
    i = DEFAULT_PROGRAM_VERSION
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    i = DEFAULT_PROGRAM_VERSION
  end
  i = i.dup if i.frozen?
  i.chop! if i.end_with? '.'
  # ======================================================================= #
  # Get rid of any possible file extensions next.
  # ======================================================================= #
  i = remove_file_extension(i) if i.include? '.'
  i.delete!('/') if i.include? '/'
  @internal_hash[:program_version] = i
end
Also aliased as: set_version
set_target_directory(i)
set_version( i = DEFAULT_PROGRAM_VERSION )
Alias for: set_program_version
set_work_on_this_target_directory(i) click to toggle source
#

set_work_on_this_target_directory

This method will simply do a full assignment, without any further checks.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 624
def set_work_on_this_target_directory(i)
  i = i.dup if i.frozen?
  i << '/' unless i.end_with?('/')
  @internal_hash[:work_on_this_target_directory] = i
end
Also aliased as: set_target_directory
show_help() click to toggle source
#

show_help (help tag)

Invocation example:

rcp --help
#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 285
def show_help
  programs_dir = internal_programs_directory?
  opnn { :no_trailing }
  e
  e
  e "This class will create programs under the "\
    "#{sdir(programs_dir)} #{rev}hierarchy."
  e
  e 'You can test this class by issuing any of the following:'
  e
  efancy "  rcp #{programs_dir}Htop/1.0.1"
  efancy '  rcp htop-1.0.1'
  e
  e 'A few commandline flags are supported. For instance, you can'
  e 'use --blank or --empty to avoid creating any directory, file'
  e 'or symlink in the target (main) directory that will be created.'
  e 'This may be useful in some situations, such as when the meson'
  e 'build system would otherwise complain about already existing'
  e 'directories. In most cases, though, --blank or --empty will'
  e 'be rarely needed.'
end
subdirectories?()
target?( program_name = program_name?, program_version = program_version? )
target_directory?()
target_directory_and_program_name?() click to toggle source
#

target_directory_and_program_name?

This method will return a String that includes the target directory, and the program name at hand. It also MUST return a trailing ‘/’ character.

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 497
def target_directory_and_program_name?
  "#{internal_programs_directory?}#{program_name?.capitalize}/"
end
version()
Alias for: program_version?
version?()
Alias for: program_version?
work_on_this_target_directory?() click to toggle source
#

work_on_this_target_directory?

#
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 633
def work_on_this_target_directory?
  @internal_hash[:work_on_this_target_directory]
end
Also aliased as: target_directory?, target?

Private Instance Methods