class RBT::RegisterProgramFilesIntoGlobalDatabase
Constants
- YAML_DATABASE_INSTALLED_FILES
#¶ ↑
YAML_DATABASE_INSTALLED_FILES
¶ ↑#¶ ↑
Public Class Methods
new( program = nil, run_already = true )
click to toggle source
Public Instance Methods
load_yaml_database()
click to toggle source
program?()
click to toggle source
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 183 def register_this_program( program = program? ) if !program.include?('/') program = programs_dir?+program.capitalize+'/Current' end program = File.absolute_path(program) _ = "#{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 opnwarn '___ '+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. opne sfancy('Creating the file ')+ sfile(_)+ simp(' now.') array = Dir["#{current}**/*"] # =================================================================== # # Select only files next. # =================================================================== # array.select! {|f| File.file? f } create_file(_) append_what_into(array.join("\n"), _) end end end
Also aliased as: register
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 44 def reset super() infer_the_namespace # ======================================================================= # # === @program # ======================================================================= # @program = 'htop' # ← Need a default program. # ======================================================================= # # === @debug # ======================================================================= # @debug = false # ======================================================================= # # === @run_simulation # ======================================================================= # @run_simulation = false end
run()
click to toggle source
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 92 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? opnwarn 'For the program `'+simp(@program.to_s)+'` we found '\ 'an error: '+@program.to_s opnwarn '(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 opne 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 135 def save_into_yaml_file_after_permission_check(this_file, hash) if File.exist? this_file if File.writable? this_file opne simp('Saving into the yaml file ') opne sfile(" #{this_file}") opne 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 opnwarn 'You do not have sufficient permissions to modify ' opne sfile(" #{this_file}") end else opne "The file `#{sfile(this_file)}` does not exist." opne 'Please create it.' end end
save_yaml(into, what)
click to toggle source
set_program(i)
click to toggle source
show_registered_keys()
click to toggle source