class RBT::RegisterProgramFilesIntoGlobalDatabase

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( program = nil ) click to toggle source
#

initialize

#
Calls superclass method RBT::Base::new
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 30
def initialize(
    program = nil
  )
  super
  set_program(program)
end
show_registered_keys() click to toggle source
#

RBT::RegisterProgramFilesIntoGlobalDatabase.show_registered_keys

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 145
def self.show_registered_keys
  self.new.show_registered_keys
end

Public Instance Methods

load_yaml_database() click to toggle source
#

load_yaml_database

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 110
def load_yaml_database
  _ = "#{YAML_DATABASE_DIRECTORY}Database_InstalledFiles.yml"
  _ = YAML.load_file(_) if File.exist? _
  _
end
program?() click to toggle source
#

program?

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 61
def program?
  @program
end
register(program = program?)
register_this_program(program = program?) click to toggle source
#

register_this_program

This method registers a (single) program residing under the /Programs hierarchy into the yaml Database.

I recommend to give the absolute location as argument, but the short version should work as well.

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 167
def register_this_program(program = program?)
  if !program.include?('/')
    program = programs_dir?+program.capitalize+'/Current'
  end
  _ = "#{program}/InstalledFiles"
  unless File.exist? _
    _ = program+'yaml/registered_files.yml'
  end
  if File.exist? _ # something like "/Programs/Gif2apng/Current/InstalledFiles"
    _ = read_file(_)
    save_installed_files_into_yaml_database(_)
  else # if we do not have it, use another file.
    if Dir[program+'/*'].size > 1 # Assume that more than one file here
                                  # means we installed something worthy.
      # save_installed_files_information(program)
      current = program
      if File.symlink? current
        opnn; warn '___ '+program
        current = File.readlink(program)
        if ! current.include? '/' # assume that we have a "Current -> 0.1.7" structure, rather than a "Current -> /Programs/Foo/0.17" structure.
          current = program.split('/')[0..-2].join('/') +'/'+current
        end
      end
      current << '/' unless current.end_with? '/' # append trailing /
      _ = current+'InstalledFiles'
      remove_file(_) # just to make sure.
      opnn; e sfancy('Creating file ')+sfile(_)+simp(' now.')
      array = Dir["#{current}**/*"]
      # =================================================================== #
      # Select only files next.
      # =================================================================== #
      array.select! {|f| File.file? f }
      create_file(_)
      append_what_into( array , _)
    end
  end
end
Also aliased as: register, run
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 40
def reset
  super()
  @program = 'htop' # <- Need a default program.
  @debug = false
  @run_simulation = false
  @namespace = NAMESPACE
end
run(program = program?)
save_installed_files_into_yaml_database(data) click to toggle source
#

save_installed_files_into_yaml_database

Use this method to store info in our yaml Database. Note that we must first load the yaml file if it exists, before we can save new information.

Important:

The argument `data` must be an array listing which files will
be added to the yaml database.
#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 76
def save_installed_files_into_yaml_database(data)
  if @debug
    ewarn "DEBUG INFO FROM save_installed_files_into_yaml_database"
    cliner { pp data }
    pp "^^^^ check this data ..."
  end
  if data.empty?
    opnn; ewarn 'For the program `'+simp(@program.to_s)+'` we found '\
                'an error: '+@program.to_s
    opnn; ewarn '(Line '+__LINE__.to_s+') Sorry, dataset to the '\
                'method save_installed_files_into_yaml_database (data) '\
                'is empty.'
  end
  _ = YAML_DATABASE_INSTALLED_FILES
  if @run_simulation
    opnn; e simp('We run in simulation mode, hence we will not save '\
            'the program into the yaml file ')+sfile('  '+_)+
            simp(' now')+'.'
  else
    hash = {}
    name = data.last
    name = name.split('/')[2,2].join('-').downcase if name # assume the name of the entry here.
    begin
      hash[name.strip] = data.map {|x| x.chomp} # we hate newlines, so get rid of them.
      save_into_yaml_file_after_permission_check(_, hash)
    rescue Exception => error
      opnn; pp error
    end
  end
end
save_into_yaml_file_after_permission_check(this_file, hash) click to toggle source
#

save_into_yaml_file_after_permission_check

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 119
def save_into_yaml_file_after_permission_check(this_file, hash)
  if File.exist? this_file
    if File.writable? this_file
      opnn; e simp('Saving into the yaml file ')
      opnn; e sfile("  #{this_file}")
      opnn; e simp('now.')
      # =================================================================== #
      # Load in the old stuff into our hash.
      # =================================================================== #
      if hash && File.exist?(this_file) # if it exists, load it.
        hash = hash.merge( load_yaml_database() ) if File.size(this_file) > 0
      end
      save_yaml(this_file, hash)
    else
      opnn; ewarn 'You do not have sufficient permissions to modify '
      opnn; e sfile("  #{this_file}")
    end
  else
    opnn; e "The file `#{sfile(this_file)}` does not exist."
    opnn; e 'Please create it.'
  end
end
save_yaml(into, what) click to toggle source
#

save_yaml

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 209
def save_yaml(into, what)
  write_what_into(what, into)
end
set_program(i) click to toggle source
#

set_program

This method will set the @program variable.

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 53
def set_program(i)
  i = Dir.pwd if i.nil?
  @program = i
end
show_registered_keys() click to toggle source
#

show_registered_keys

#
# File lib/rbt/utility_scripts/register_program_files_into_global_database.rb, line 152
def show_registered_keys
  keys = load_yaml_database.keys
  opnn; e 'The registered keys in our database are:'
  opnn; e  '  [ "'+keys.join('", "')+'" ]'
end