class RBT::GenerateSqlTable

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::GenerateSqlTable[]

#
# File lib/rbt/sql/generate_sql_table.rb, line 244
def self.[](i = ARGV)
  new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/sql/generate_sql_table.rb, line 27
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

into?() click to toggle source
#

into?

#
# File lib/rbt/sql/generate_sql_table.rb, line 92
def into?
  @into
end
notify_the_user_into_which_file_we_will_store_the_database() click to toggle source
#

notify_the_user_into_which_file_we_will_store_the_database

This will notify the user that the database will be stored into the file called “registered_programs.db”, by default.

#
# File lib/rbt/sql/generate_sql_table.rb, line 102
def notify_the_user_into_which_file_we_will_store_the_database
  opne "#{rev}This class will generate the SQL dump "\
       "into this file: `#{sfile(@into)}#{rev}`"
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#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 110
def run
  # ======================================================================= #
  # Require the cookbook-class next.
  # ======================================================================= #
  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 = action(:SanitizeCookbook, 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 "#{rev}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
#

string_storing_the_content_of_the_table?

#
# File lib/rbt/sql/generate_sql_table.rb, line 85
def string_storing_the_content_of_the_table?
  @string_storing_the_content_of_the_table
end
to_0_or_1(i) click to toggle source
#

to_0_or_1

#
# File lib/rbt/sql/generate_sql_table.rb, line 57
def to_0_or_1(i)
  case i
  when true, 't'
    i = 1
  when false, 'f'
    i = 0
  end
  return i
end