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.
#¶ ↑
- 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.
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
#¶ ↑
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_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
#¶ ↑
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
¶ ↑
#¶ ↑
# 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
¶ ↑
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
¶ ↑
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
#¶ ↑
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
#¶ ↑
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
#¶ ↑
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
#¶ ↑
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
¶ ↑
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
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
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_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
#¶ ↑
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_may_we_create_a_current_symlink
¶ ↑
#¶ ↑
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 248 def set_may_we_create_a_current_symlink(i) @internal_hash[:may_we_create_a_current_symlink] = i end
#¶ ↑
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
¶ ↑
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
#¶ ↑
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
#¶ ↑
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
#¶ ↑
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
#¶ ↑
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
Private Instance Methods
#¶ ↑
create_the_current_symlink
¶ ↑
Invoke this method only if you really want to create the symlink called ‘Current`.
This method is private - we don’t want users to use it directly.
#¶ ↑
# File lib/rbt/actions/individual_actions/create_app_dir_skeleton/create_app_dir_skeleton.rb, line 553 def create_the_current_symlink(at_this_directory) base_dir = file_dirname_retaining_trailing_slash(at_this_directory) # ===================================================================== # # at_this_directory may now point at "/home/Programs/Glib/2.40.0/" # and base_dir may point at "/home/Programs/Glib/". So we can # set the Current symlink. # ===================================================================== # from = at_this_directory to = "#{base_dir}Current" # This is equivalent to #{target_directory_and_program_name?}Current", aka something like "/home/Programs/Samba/Current" opne "#{rev}Next, creating a #{steelblue('symlink')} #{rev}pointing from "\ "#{sfancy(to)}" opne "#{rev}towards #{sfancy(from)}#{rev}." if File.symlink? to # remove an oldsymlink if it exists. if debug? # Give info only when in debug mode. opne "#{swarn('=> Removing symlink: ')}"\ "#{sfancy(to)}"\ "#{swarn(' next.')}" end remove_file(to) end # ======================================================================= # # Delegate towards another method next: # ======================================================================= # create_symlink(from, to, :default, use_colours?) end