class RBT::GenerateSqlTable
Public Class Methods
[](i = ARGV)
click to toggle source
Public Instance Methods
into?()
click to toggle source
notify_the_user_into_which_file_we_will_store_the_database()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/sql/generate_sql_table.rb, line 41 def reset super() infer_the_namespace # ======================================================================= # # === @string_storing_the_content_of_the_table # ======================================================================= # @string_storing_the_content_of_the_table = ''.dup # ======================================================================= # # === @into # ======================================================================= # @into = 'registered_programs.db' end
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/sql/generate_sql_table.rb, line 107 def run # ======================================================================= # # Require the cookbook-class next. # ======================================================================= # require 'rbt/requires/require_the_cookbook_class.rb' notify_the_user_into_which_file_we_will_store_the_database into = into? # ======================================================================= # # Next read in our main sql-specification, which is distributed as # part of the RBT suite: # ======================================================================= # # bl $RBT/yaml/sql/CREATE_TABLE_REGISTERED_PROGRAMS.sql # ======================================================================= # sqlite_create_table_command = File.read( "#{yaml_directory?}sql/CREATE_TABLE_REGISTERED_PROGRAMS.sql" ).split("\n").map {|entry| if entry.include? '#' entry = entry.split('#').first.strip end entry }.join("\n") # ======================================================================= # # Always remove the old database: # ======================================================================= # delete_file(@into) if File.exist? @into # ======================================================================= # # Create the database here, via the commandline variant for sqlite3: # ======================================================================= # esystem 'sqlite3 '+into+' "'+sqlite_create_table_command+'"' # ======================================================================= # # Iterate over every available program next: # ======================================================================= # available_programs?.each_with_index {|this_program, program_number| program_number += 1 dataset_from_expanded_cookbooks = load_dataset_from_this_expanded_cookbook(this_program) { :be_quiet } if dataset_from_expanded_cookbooks.nil? dataset_from_expanded_cookbooks = RBT::Cookbooks::SanitizeCookbook.new(this_program) { :fast }.cookbook_dataset? end # ===================================================================== # # Next define some helper-variables, to more easily deal with the # SQL dataset at hand: # ===================================================================== # program_path = dataset_from_expanded_cookbooks[:program_path] program_version = dataset_from_expanded_cookbooks[:program_version].to_s extract_to = dataset_from_expanded_cookbooks[:extract_to] licence = dataset_from_expanded_cookbooks[:licence].to_s program_name_and_program_version = dataset_from_expanded_cookbooks[:program_name_and_program_version] use_this_build_system = dataset_from_expanded_cookbooks[:use_this_build_system] use_build_directory = dataset_from_expanded_cookbooks[:use_build_directory] use_build_directory = to_0_or_1(use_build_directory).to_s homepage = dataset_from_expanded_cookbooks[:homepage].to_s archive_type = dataset_from_expanded_cookbooks[:archive_type].to_s archive_size = dataset_from_expanded_cookbooks[:archive_size].to_s case use_this_build_system # ===================================================================== # # === :infer_automatically # ===================================================================== # when :infer_automatically use_this_build_system = 'configure' # Hardcoded assumption for now. end if extract_to.nil? or extract_to.empty? extract_to = log_dir?+ dataset_from_expanded_cookbooks[:program_name_and_program_version]+ '/' end # ===================================================================== # # We will store several entries: # # (1) the index (ID) # (2) the name of the program # (3) the "URL" to the local program path # (4) the homepage to the remote website for this program # (5) the raw archive size (typically in .tar.xz format) # # ===================================================================== # add_this_string = "INSERT INTO REGISTERED_PROGRAMS ("\ "PROGRAM_NUMBER, "\ "PROGRAM_NAME, "\ "PROGRAM_PATH, "\ "PROGRAM_VERSION, "\ "EXTRACT_TO, "\ "USE_THIS_BUILD_SYSTEM, "\ "USE_BUILD_DIRECTORY, "\ "LICENCE, "\ "PROGRAM_NAME_AND_PROGRAM_VERSION, "\ "HOMEPAGE, "\ "ARCHIVE_TYPE, "\ "ARCHIVE_SIZE"\ ") VALUES "\ "(#{program_number}, "\ "'#{this_program}', "\ "'#{program_path}', "\ "'#{program_version}', "\ "'#{extract_to}', "\ "'#{use_this_build_system}', "\ "'#{use_build_directory}', "\ "'#{licence}', "\ "'#{program_name_and_program_version}', "\ "'#{homepage}', "\ "'#{archive_type}', "\ "#{archive_size.to_i}"\ ");\n" @string_storing_the_content_of_the_table << add_this_string } store_the_main_string opne 'Next using the sqlite3-binary to pull in all the insert-statements' opne 'that were just autogenerated.' # ======================================================================= # # Next, run the insert into command next: # ======================================================================= # esystem "sqlite3 #{into} < insert_#{into}" # ======================================================================= # # And remove the helper .db next: # ======================================================================= # _ = "insert_#{into}" delete_file(_) if File.exist? _ # Past this point it should be gone. if is_on_roebe? and File.exist?(into) # ===================================================================== # # On my home system we will also copy the generated # file "registered_programs.db" to the assumed default # rbt-location. # ===================================================================== # new_target = "#{log_dir?}database/#{File.basename(into)}" opne 'As we are on a roebe-system we will also copy' opne 'this database into its new location at' opne '`'+sfile(new_target)+'`.' copy_file(into, new_target) end end
store_the_main_string( into = "insert_
click to toggle source
#¶ ↑
store_the_main_string
¶ ↑
#¶ ↑
# File lib/rbt/sql/generate_sql_table.rb, line 70 def store_the_main_string( into = "insert_#{into?}" ) if File.exist?(into) and into.start_with?('insert_') delete_file(into) end what = string_storing_the_content_of_the_table? into = File.absolute_path(into) unless into.include?('/') write_what_into(what, into) opne "Finished writing into `#{sfile(into)}`." end
string_storing_the_content_of_the_table?()
click to toggle source