class RBT::RegisterProgramFilesIntoYamlDatabase
Constants
- DEFAULT_INPUT_DIRECTORY
#¶ ↑
DEFAULT_INPUT_DIRECTORY
¶ ↑#¶ ↑
Public Class Methods
batch()
click to toggle source
#¶ ↑
RBT::RegisterProgramFilesIntoYamlDatabase.batch
¶ ↑
This method will run through all entries at /Programs, and register it.
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 305 def self.batch files = Dir["#{RBT.programs_directory?}*"].map {|entry| entry << '/Current/'} files.sort.each {|entry| e "Working on #{sfancy(entry)} next." e new(entry) # Instantiate it here. e } end
new( i = nil, run_already = true )
click to toggle source
Public Instance Methods
entries?()
click to toggle source
#¶ ↑
entries?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 278 def entries? @internal_hash[:entries] end
Also aliased as: files?
fetch_entries()
click to toggle source
#¶ ↑
fetch_entries
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 165 def fetch_entries where = where?.dup.strip if where.include? '$' where = convert_global_env(where) end orev "Obtaining all files from `#{sdir(where?)}#{rev}`." path = "#{@register_where}**/**" _ = Dir[path] # ======================================================================= # # Select only files: # ======================================================================= # _.select! {|entry| File.file? entry } @internal_hash[:entries] = _ end
register_into_yaml_file()
click to toggle source
#¶ ↑
register_into_yaml_file
¶ ↑
This method will use the Current symlink.
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 206 def register_into_yaml_file # This will register @array_register_these_files finally _ = register_where? set_versioned_directory(_) if (_.count('/') < 3) and !_.end_with?('Current/') _ << 'Current/' unless File.symlink?(_) and return_pwd.include?(programs_dir?) # Try to re-create the Symlink here if we are in the /Programs directory. target = @register_where target = File.dirname(target) if target.end_with? 'Current/' if File.directory? target cd(target) target = get_directories_from(target).sort.first set_versioned_directory(target) if target remove_directory('Current') if File.directory?('Current') # Must be a Symlink. symlink(target.chop, _.chop) # .chop to get rid of '/'. end else opne sdir(target)+swarn(' is not a directory.') end end end _ << 'yaml/' mkdir _ unless File.directory? _ # The directory should exist. # ======================================================================= # # We will store in a yaml/ subdirectory, in a file called # registered_files.yml # ======================================================================= # registered_files = rds("#{_}registered_files.yml") if run_simulation? e "We would now remove #{simp(registered_files.to_s)} if we" e 'would not be in simulation mode.' else # ===================================================================== # # Get rid of the old .yml file, if it exists. # ===================================================================== # remove(registered_files) if File.exist? registered_files end unless run_simulation? if entries?.empty? orev 'We will not store the registered files as' orev 'the dataset is empty.' else orev "Storing the dataset (#{sfancy(registered_files.size.to_s)}"\ " #{rev}files) into:" orev " `#{sfile(registered_files)}`" _ = entries?.map {|entry| entry.sub(/#{@register_where}/,'') } _.reject! {|entry| entry.include? 'registered_files.yml' } # Reject self-name. _.reject! {|entry| entry.end_with? 'Resources/full_configure_command' or entry.end_with? 'Resources/full_configure_command.md' or entry.end_with? 'Resources/Architecture' } _.map! {|entry| entry.gsub(/#{Regexp.quote(@versioned_directory)}/,'') } unless _.empty? # ================================================================= # # We must sort if alphabetically next: # ================================================================= # _ = _.sort what = YAML.dump(_) save_what_into( what, registered_files ) end end end end
register_where?()
click to toggle source
#¶ ↑
register_where?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 183 def register_where? @register_where end
Also aliased as: where?
report_files()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 87 def reset super() infer_the_namespace # ======================================================================= # # === :entries # ======================================================================= # @internal_hash[:entries] = [] # ======================================================================= # # === @run_simulation # ======================================================================= # @run_simulation = false end
run()
click to toggle source
run_simulation=(i)
click to toggle source
run_simulation?()
click to toggle source
#¶ ↑
run_simulation
?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 190 def run_simulation? @run_simulation end
Also aliased as: run_simulation
set_register_where( i = DEFAULT_INPUT_DIRECTORY )
click to toggle source
#¶ ↑
set_register_where
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 103 def set_register_where( i = DEFAULT_INPUT_DIRECTORY ) i = DEFAULT_INPUT_DIRECTORY if i.nil? i = i.to_s.dup # Get a copy here. Must be a String. case i # case tag # ========================================================================= # # === register_program_files --batch # ========================================================================= # when /^-?-?batch$/ self.class.batch # ========================================================================= # # === register_program_files --pwd # # This entry point can, for example, be invoked in a directory such # as /home/Programs/Htop/Current. # ========================================================================= # when /^-?-?pwd$/i, 'Dir.pwd', 'cwd', 'HERE' # Handle pwd i = return_pwd end i = rds(i) i << '/' unless i.end_with? '/' # ========================================================================= # # === Ensure that a trailing "Current/" string exists # # Append 'Current/'. A proper target must end with 'Current/', since # that is the symlink scheme used on GoboLinux. # ========================================================================= # if i.include? programs_dir? n_slashes = i.sub(/^#{Regexp.quote(programs_dir?)}/, '').count('/') if n_slashes < 2 i << 'Current/' unless i.include? 'Current/' end end # ========================================================================= # # i.delete!('-') if i.include? '-' # Added Aug 2014. # ^^^ Disabled the above as of Sep 2017. If we want to use this, then # we may have to use a configuration setting for the whole RBT # project. If this is done, then we can re-enable the above, # but for now, it stays disabled. # ========================================================================= # @register_where = i end
set_versioned_directory(i)
click to toggle source
#¶ ↑
set_versioned_directory
¶ ↑
We need to keep track here so that we can get rid of the version string of the directory when we save into the yaml file.
#¶ ↑
# File lib/rbt/utility_scripts/register_program_files_into_yaml_database.rb, line 156 def set_versioned_directory(i) i = i.to_s.dup i << '/' unless i.end_with? '/' @versioned_directory = i end