class RBT::CreateProgram
Constants
- ARRAY_CREATE_THESE_SUBDIRECTORIES
#¶ ↑
ARRAY_CREATE_THESE_SUBDIRECTORIES
¶ ↑#¶ ↑
- ARRAY_KEEP_SYMLINKS_FOR_THESE_PROGRAMS
#¶ ↑
ARRAY_KEEP_SYMLINKS_FOR_THESE_PROGRAMS
¶ ↑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
#¶ ↑
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_current_symlink
¶ ↑
Invoke this part only if you really want to create the symlink called `Current`
#¶ ↑
# File lib/rbt/create_program/create_program.rb, line 398 def create_current_symlink # ======================================================================= # # The following instance variable can be used to disable the creation # of the Current symlink. # ======================================================================= # create_current_symlink = @create_current_symlink if create_current_symlink _ = target_directory_and_program_name?+'Current' # _ will be something like "/Programs/Samba/Current" # ===================================================================== # # Intercept some programs here. # ===================================================================== # return if ARRAY_KEEP_SYMLINKS_FOR_THESE_PROGRAMS.include?(@program_name.downcase) if File.symlink? _ # remove symlink if it exists. if @debug # Give info only when in debug mode. opnn; ewarn '=> Removing symlink: '+sfancy(_)+swarn(' next.') end remove_file(_) end # ===================================================================== # # === Let the method symlink() handle the symlinking action # ===================================================================== # symlink( # Delegate towards rbt/symlink.rb full_target?, _, :default, use_colours? ) end end
#¶ ↑
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
¶ ↑
#¶ ↑
# 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
¶ ↑
#¶ ↑
# 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?¶ ↑
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
#¶ ↑
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
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
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
#¶ ↑
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_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_create_current_symlink
¶ ↑
#¶ ↑
# File lib/rbt/create_program/create_program.rb, line 186 def set_create_current_symlink(i = true) @create_current_symlink = i end
#¶ ↑
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
¶ ↑
#¶ ↑
# 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
¶ ↑
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
#¶ ↑
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_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
¶ ↑
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