class RBT::CreateProgram

Constants

ARRAY_CREATE_THESE_SUBDIRECTORIES
#

ARRAY_CREATE_THESE_SUBDIRECTORIES

#
#

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

#
DEFAULT_PROGRAM_VERSION
#

DEFAULT_PROGRAM_VERSION

This constant specifies which program-version to use if it is otherwise omitted.

#
DEFAULT_TEST_INPUT
#

DEFAULT_TEST_INPUT

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

[](i = '') click to toggle source
#

RBT::CreateProgram[]

#
# File lib/rbt/create_program/create_program.rb, line 491
def self.[](i = '')
  self.new(i)
end
new( i = DEFAULT_TEST_INPUT, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/create_program/create_program.rb, line 89
def initialize(
    i           = DEFAULT_TEST_INPUT,
    run_already = true
  )
  reset
  set_input(i)
  case run_already
  when :dont_run_yet,
       :do_not_run_yet
    run_already = false
  end
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    if yielded.is_a? Hash
      if yielded.has_key? :use_colours
        @hash_for_opn.update(use_colours: false) if yielded.delete(:use_colours) == false
      end
      if yielded.has_key? :use_opn
        @hash_for_opn.update(use_opn: false) if yielded.delete(:use_opn) == false
      end
    end
  end
  run if run_already
end

Public Instance Methods

create_main_directory_and_the_required_subdirectories( i = full_target? ) click to toggle source
#

create_main_directory_and_the_required_subdirectories

This method will create the main directory, and all the required subdirectories - unless these already exist 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.

#
# File lib/rbt/create_program/create_program.rb, line 285
def create_main_directory_and_the_required_subdirectories(
    i = full_target?
  )
  unless File.directory? i
    opnn; e "Creating the directory #{sdir(i)} next."
    mkdir(i, verbosity: :be_quiet)
    create_settings_directory
  end
  # ======================================================================= #
  # Next, create the subdirectories.
  # ======================================================================= #
  opnn; e 'Several subdirectories will now be created in that '\
          'directory, namely:'
  opnn; e '  '+sdir(@array_create_these_subdirectories.join('/, ')+'/')
  @array_create_these_subdirectories.each {|this_directory|
    new_target = rds("#{i}#{this_directory}")
    if run_simulation?
      opnn; e 'We run in simulation mode, thus we will not'
      opnn; e "create the directory `#{sdir(new_target)}`."
    else
      unless File.directory? new_target
        mkdir(new_target, { verbosity: :be_quiet, permissions: 0755 } )
      end
    end
  }
  opnn; e 'Done!'
end
create_settings_directory() click to toggle source
#

create_settings_directory

#
# File lib/rbt/create_program/create_program.rb, line 364
def create_settings_directory
  this_directory = target_directory_and_program_name?+'Settings'
  if in_simulation?
    opnn; e "Normally `#{sdir(this_directory)}` would be created but"
    opnn; e 'as we run in simulation-mode, no change will be made.'
  else
    create_directory(this_directory, :be_quiet) # Also create a Settings/ subdir:
  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/create_program/create_program.rb, line 326
def determine_program_name_and_program_version_from_this_directory(
    i = return_pwd
  )
  i = File.basename(i)
  set_input(i)
  # ======================================================================= #
  # This ^^^ alone suffices, because the rest of the program will handle
  # the logic properly.
  # ======================================================================= #
end
full_target?() click to toggle source
#

full_target?

This method assembles back the program base directory, the program name and the program version.

#
# File lib/rbt/create_program/create_program.rb, line 319
def full_target?
  "#{program_base_dir?}#{program_name?}/#{program_version?}/"
end
Also aliased as: target?
input?() click to toggle source
#

input?

#
# File lib/rbt/create_program/create_program.rb, line 133
def input?
  @input
end
menu( i = input? ) click to toggle source
#

menu (menu tag)

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

notify_the_user_about_the_target_directory

#
# File lib/rbt/create_program/create_program.rb, line 271
def notify_the_user_about_the_target_directory
  opnn; e "The target directory will be at `#{sdir(full_target?)}`."
end
opnn() click to toggle source
#

opnn (opnn tag)

#
Calls superclass method RBT::Base#opnn
# File lib/rbt/create_program/create_program.rb, line 140
def opnn
  super(@hash_for_opn)
end
parse_input_and_assign_to_the_proper_values() click to toggle source
#

parse_input_and_assign_to_the_proper_values

#
# File lib/rbt/create_program/create_program.rb, line 229
def parse_input_and_assign_to_the_proper_values
  _ = input?
  # ======================================================================= #
  # First, check if we have a /Programs entry.
  # ======================================================================= #
  if _.include?('/') and (programs_dir?.include?(_.split('/').first))
    splitted = _.split('/')
    set_program_version(splitted.pop)
    set_program_name(splitted.pop.delete('/').capitalize)
    assume_this_as_the_base_directory = capitalize_first_alphabetical_character(
      splitted.join('/')
    )
    set_base_directory_of_the_program(assume_this_as_the_base_directory)
  # ======================================================================= #
  # Second, check for '/' characters. If these were given then we
  # will assume that the user did input something like:
  #   /home/kumar/Robert/Programs/Htop/1.0.2
  # ======================================================================= #
  elsif _.include?('/') and
    !((_.count('/') == 1) or (_.end_with?('/'))) # <- This check is for input such as "htop-0.9.7/"
    splitted = _.split('/')
    set_program_version(splitted.pop)
    set_program_name(splitted.pop)
    set_base_directory_of_the_program(splitted.join('/'))
  # ======================================================================= #
  # Else the input did not contain any '/' characters, so we have to
  # take another approach.
  # ======================================================================= #
  else
    _ = remove_archive_at_the_end(_)
    # ===================================================================== #
    # Next, delegate towards ProgramInformation.
    # ===================================================================== #
    program_information = ProgramInformation.new(_)
    set_program_version(program_information.program_version?)
    set_program_name(program_information.short_name?)
  end
end
program_base_dir?() click to toggle source
#

program_base_dir?

#
# File lib/rbt/create_program/create_program.rb, line 450
def program_base_dir?
  @base_directory_of_the_program
end
program_name()
Alias for: program_name?
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/create_program/create_program.rb, line 193
def program_name?
  @program_name
end
Also aliased as: name, name?, program_name
program_version?() click to toggle source
#

program_version?

#
# File lib/rbt/create_program/create_program.rb, line 221
def program_version?
  @program_version
end
Also aliased as: version?, version
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/create_program/create_program.rb, line 120
def reset
  super()
  @hash_for_opn = return_hash_for_opn
  @base_directory_of_the_program = programs_dir?.dup.freeze
  @array_create_these_subdirectories = ARRAY_CREATE_THESE_SUBDIRECTORIES
  set_program_name
  set_program_version
  set_create_current_symlink
end
return_hash_for_opn() click to toggle source
#

return_hash_for_opn

#
# File lib/rbt/create_program/create_program.rb, line 354
def return_hash_for_opn
 {
   namespace:   NAMESPACE,
   use_colours: use_colours?
 }
end
return_program_name_and_program_version() click to toggle source
#

return_program_name_and_program_version

#
# File lib/rbt/create_program/create_program.rb, line 428
def return_program_name_and_program_version
  "#{@program_name}-#{@program_version}"
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/create_program/create_program.rb, line 475
def run
  menu
  parse_input_and_assign_to_the_proper_values
  tell_the_user_what_will_be_done # Give information to the user.
  notify_the_user_about_the_target_directory
  create_main_directory_and_the_required_subdirectories
  # ======================================================================= #
  # We will create a symlink called 'Current' by default, but this
  # can be disabled.
  # ======================================================================= #
  create_current_symlink
end
set_base_directory( i = programs_dir? )
set_base_directory=( i = programs_dir? )
set_base_directory_of_the_program( i = programs_dir? ) click to toggle source
#

set_base_directory_of_the_program

Keep in mind that this method will ensure that there is a trailing '/' token to the instance variable @base_directory_of_the_program.

#
# File lib/rbt/create_program/create_program.rb, line 460
def set_base_directory_of_the_program(
    i = programs_dir?
  )
  i = i.first if i.is_a? Array
  i = programs_dir? if i.nil?
  i << '/' unless i.end_with? '/'
  i = rds(i)
  @base_directory_of_the_program = i.dup
end
set_input(i = '') click to toggle source
#

set_input

This method will always remove any '_' that it finds, for the time being (November 2018). However had, this is actually not so great since we may also copy/paste this input, such as “LibreOffice_6.2.2.2”. Hence, since as of April 2019, we will actually first replace the '_' found if it is only one.

#
# File lib/rbt/create_program/create_program.rb, line 153
def set_input(i = '')
  i = i.first if i.is_a? Array
  case i
  when :default
    i = DEFAULT_TEST_INPUT
  when 'PWD'
    i = File.basename(get_pwd)
  end
  i = i.to_s.dup.downcase
  if i.include? '_'
    if i.count('_') == 1
      i = i.tr('_','-')
    else
      i.delete!('_')
    end 
  end
  @input = i
end
set_program_name(i = '') click to toggle source
#

set_program_name

#
# File lib/rbt/create_program/create_program.rb, line 377
def set_program_name(i = '')
  i = i.dup
  if i
    i.downcase! # <- This is done always. On GoboLinux, we may have to change this lateron.
    if CAPITALIZE_PROGRAM_NAME # Now it is Capitalized. Defined in rbt/configuration/configuration.rb
      i.capitalize! unless i.empty?
    end
    if is_on_gobolinux?
      i = return_program_name_for_gobolinux_systems(i)
    end
    i.delete!('-') if i.include? '-'
  end
  @program_name = i
end
set_program_version( i = DEFAULT_PROGRAM_VERSION ) click to toggle source
#

set_program_version

This method sets the main program version of our program at hand.

1.0.0 is the default program version to use.

#
# File lib/rbt/create_program/create_program.rb, line 206
def set_program_version(
    i = DEFAULT_PROGRAM_VERSION
  )
  i = DEFAULT_PROGRAM_VERSION if i.nil?
  i.delete!('/') if i.include? '/'
  # ======================================================================= #
  # Get rid of any possible file extensions next.
  # ======================================================================= #
  i = remove_file_extension(i)
  @program_version = i
end
Also aliased as: set_version
set_specific_program_directory( i = programs_dir? )
set_version( i = DEFAULT_PROGRAM_VERSION )
Alias for: set_program_version
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/rbt/create_program/create_program.rb, line 340
def show_help
  opnn; e "This class will create programs under the "\
          "#{sdir(programs_dir?)} hierarchy."
  e
  opnn; e 'You can test this class by doing:'
  e
  opnn; efancy "  rcp #{programs_dir?}Htop/1.0.1"
  opnn; efancy '  rcp htop-1.0.1'
  e
end
target?()
Alias for: full_target?
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/create_program/create_program.rb, line 179
def target_directory_and_program_name?
  "#{@base_directory_of_the_program}#{program_name?}/"
end
tell_the_user_what_will_be_done() click to toggle source
#

tell_the_user_what_will_be_done

Feedback information back to the user. In Jun 2007 I lessened the amount it feedbacks. Currently this method is invoked via create_directories

#
# File lib/rbt/create_program/create_program.rb, line 439
def tell_the_user_what_will_be_done
  opnn; ee sfancy(return_program_name_and_program_version.downcase)
  if be_verbose?
    ee ' ('+simp('Program name')+': '+sfancy(program_name?)+' and '+
       simp('Program Version')+': '+sfancy(program_version?)+')'
  end; e
end
version()
Alias for: program_version?
version?()
Alias for: program_version?