class RBT::CompileViaSQLDatabase

Constants

DEFAULT_LOCATION_OF_THE_DATABASE
#

DEFAULT_LOCATION_OF_THE_DATABASE

#

Public Class Methods

location_of_the_database?() click to toggle source
#

RBT::CompileViaSQLDatabase.location_of_the_database?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 330
def self.location_of_the_database?
  DEFAULT_LOCATION_OF_THE_DATABASE
end
new( i = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 27
def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_commandline_arguments(i)
  map_the_first_argument_onto_the_compile_this_program_variable
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

assumed_local_file_path_for?(this_program) click to toggle source
#

assumed_local_file_path_for?

This method was specifically added for the Libui GUI wrapper. It is normally not in use by this class, if used on the commandline.

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 257
def assumed_local_file_path_for?(this_program)
  if this_program and is_this_program_included_in_the_database?(this_program)
    result = `sqlite3 #{location_of_the_database?} "select * from REGISTERED_PROGRAMS where PROGRAM_NAME = '#{this_program}';"`
    splitted = result.strip.split('|')
    return splitted[2] # This is the local path - at the least on 27.08.2022.
  end
  return this_program
end
assumed_version_of_this_program?(this_program) click to toggle source
#

assumed_version_of_this_program?

This method will use a SQL query to determine the (assumed) version of a particular program. It was added specifically because the LibUI GUI may need to know this information.

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 297
def assumed_version_of_this_program?(this_program)
  this_program = this_program.dup
  this_program.delete!('-') if this_program.include?('-')
  result = `sqlite3 #{location_of_the_database?} "select * from REGISTERED_PROGRAMS where PROGRAM_NAME = '#{this_program}';"`
  if result and result.include? '|'
    result = result.split('|')[4] # Version is at position 4.
    # So we use the local name for that.
    result = ProgramInformation.return_version(File.basename(result))
  end
  return result
end
available_programs?() click to toggle source
#

available_programs?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 269
def available_programs?
  result = `sqlite3 #{location_of_the_database?} "select * from REGISTERED_PROGRAMS;"`.split("\n")
  array = result.map {|entry|
    splitted = entry.split('|')
    splitted[1]
  }
  return array
end
compile_which_program?() click to toggle source
#

compile_which_program?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 154
def compile_which_program?
  @internal_hash[:compile_this_program].to_s
end
database_location?()
do_compile_via_this_variant(i) click to toggle source
#

do_compile_via_this_variant

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 410
def do_compile_via_this_variant(i)
  if is_it_a_rubygem?
    RBT.action(:install_this_rubygem, local_path?) # Delegate to the specific action here.
    return
  end
  case i
  # ======================================================================= #
  # === configure
  # ======================================================================= #
  when 'configure'
    do_install_via_configure_then_make_then_make_install
  # ======================================================================= #
  # === meson
  # ======================================================================= #
  when 'meson'
    do_install_via_meson_then_use_ninja
  # ======================================================================= #
  # === cmake
  # ======================================================================= #
  when 'cmake'
    do_install_via_cmake
  else
    e
    opne tomato("Unhandled variant: #{i}")
    e
    opne 'Please register this compilation-mode or handle otherwise.'
  end
end
do_extract_this_locally_existing_archive( what, to = '/tmp/' ) click to toggle source
#

do_extract_this_locally_existing_archive

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 312
def do_extract_this_locally_existing_archive(
    what,
    to = '/tmp/'
  )
  _result_containing_the_extracter_class = Extracter.what_to(what, to)
end
Also aliased as: extract_the_program
do_install_via_cmake() click to toggle source
#

do_install_via_cmake (cmake tag)

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 201
def do_install_via_cmake
  esystem "cmake -DCMAKE_INSTALL_PREFIX=#{use_which_prefix?} ."
  run_make_then_make_install
end
do_install_via_configure_then_make_then_make_install() click to toggle source
#

do_install_via_configure_then_make_then_make_install

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 171
def do_install_via_configure_then_make_then_make_install
  esystem "./configure --prefix=#{use_which_prefix?}"
  run_make_then_make_install
end
do_install_via_meson_then_use_ninja() click to toggle source
#

do_install_via_meson_then_use_ninja

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 161
def do_install_via_meson_then_use_ninja
  esystem "meson --prefix=#{use_which_prefix?} --libdir=#{use_which_prefix?}lib BUILD_DIRECTORY"
  cd 'BUILD_DIRECTORY'
  esystem 'ninja'
  esystem 'ninja install'
end
do_the_actual_compilation( _ = location_of_the_database? ) click to toggle source
#

do_the_actual_compilation

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 337
def do_the_actual_compilation(
    _ = location_of_the_database?
  )
  cd(log_directory?) # We must always try to cd to the base directory.
  if File.exist? _
    e rev+'Loading the sqlite database from '+sfile(_)+' next.'
    e steelblue(n_programs_are_available?.to_s)+
      ' programs are available in that sqlite-database.'
    _ = compile_which_program?
    if _ and is_this_program_included_in_the_database?(_)
      e 'The program '+sfancy(_)+' is registered. Thus, proceeding to '\
        'compile / install it.'
      result = `sqlite3 #{location_of_the_database?} "select * from REGISTERED_PROGRAMS where PROGRAM_NAME = '#{_}';"`
      # =================================================================== #
      # Let's keep a reminder for how the splitted dataset may look like:
      #
      #    2604, php, /home/x/src/php/php-8.1.9.tar.xz, 8.1.9,
      #    /home/Temp/rbt/php-8.1.9/, configure, 1, unknown,
      #    php-8.1.9, https://www.php.net/, .tar.xz, 11787892
      #
      # =================================================================== #
      splitted = result.strip.split('|')
      local_path       = splitted[2] # is at 2.
      set_local_path(local_path) # Keep a reference, for later use.
      original_extract_where_to = splitted[4].dup # is at 4.
      compile_how      = splitted[5] # is at 5.
      archive_type     = splitted[10] # is at 10.
      @internal_hash[:archive_type] = archive_type
      @internal_hash[:program_name_and_program_version] = splitted[8]
      extract_where_to = rds(
                           File.dirname(original_extract_where_to)+'/'
                         )
      e 'The assumed local path is:'
      e
      e sfancy("  #{local_path}")
      e
      # =================================================================== #
      # Check whether the file exists locally.
      # =================================================================== #
      if File.exist?(local_path)
        e 'The file exists locally. Proceeding to compile/install it.'
        do_extract_this_locally_existing_archive(
          local_path,
          extract_where_to
        ) unless is_it_a_rubygem?(local_path)
        cd original_extract_where_to
        do_compile_via_this_variant(compile_how)
        unless are_we_on_windows?
          handle_postinstallation_symlink
        end
      else
         e 'The file does not exist locally. Trying '\
           'to download it next.'
      end
    else
      e 'The program '+steelblue(_)+' is NOT included. Please provide'
      e 'a registered program.'
    end
  else
    no_file_exists_at(_)
  end
end
extract_the_program( what, to = '/tmp/' )
internal_hash_archive_type?() click to toggle source
#

internal_hash_archive_type?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 79
def internal_hash_archive_type?
  @internal_hash[:archive_type]
end
is_it_a_rubygem?( i = internal_hash_archive_type? ) click to toggle source
#

is_it_a_rubygem? (gem tag)

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 138
def is_it_a_rubygem?(
    i = internal_hash_archive_type?
  )
  i.end_with?('.gem')
end
is_this_program_included?(i)
is_this_program_included_in_the_database?(i) click to toggle source
#

is_this_program_included_in_the_database?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 322
def is_this_program_included_in_the_database?(i)
  result = `sqlite3 #{location_of_the_database?} "select * from REGISTERED_PROGRAMS where PROGRAM_NAME = '#{i}';"`
  result and result.include?('|') and (result.split('|')[1] == i)
end
Also aliased as: is_this_program_included?
local_path?() click to toggle source
#

local_path?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 147
def local_path?
  @internal_hash[:local_path]
end
location_of_the_database?() click to toggle source
#

location_of_the_database?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 105
def location_of_the_database?
  @internal_hash[:location_of_the_database]
end
Also aliased as: database_location?
makes_use_of_an_appdir_prefix?() click to toggle source
#

makes_use_of_an_appdir_prefix?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 403
def makes_use_of_an_appdir_prefix?
  use_this_prefix_object?.makes_use_of_an_appdir_prefix? # Tap into the prefix-object.
end
map_the_first_argument_onto_the_compile_this_program_variable( i = first_argument? ) click to toggle source
#

map_the_first_argument_onto_the_compile_this_program_variable

This is normally called before menu().

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 451
def map_the_first_argument_onto_the_compile_this_program_variable(
    i = first_argument?
  ) 
  set_compile_this_program(i)
end
menu( i = commandline_arguments? ) click to toggle source
#

menu (menu tag)

Invocation examples:

sqler --random-program
sqler RANDOM
sqler random
#
n_programs_are_available()
n_programs_are_available?() click to toggle source
#

n_programs_are_available?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 130
def n_programs_are_available?
  available_programs?.size
end
n_programs_available?()
prefix?()
Alias for: use_which_prefix?
program_name_and_program_version?() click to toggle source
#

program_name_and_program_version?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 442
def program_name_and_program_version?
  @internal_hash[:program_name_and_program_version]
end
program_name_that_is_to_be_installed?()
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::CompileBase#reset
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 47
def reset
  super()
  try_to_require_the_extracter_gem
  # ======================================================================= #
  # === :location_of_the_database
  # ======================================================================= #
  @internal_hash[:location_of_the_database] =
    DEFAULT_LOCATION_OF_THE_DATABASE
  # ======================================================================= #
  # === :use_this_prefix
  # ======================================================================= #
  @internal_hash[:use_this_prefix] = RBT::Prefix.new('/usr/')
  # ======================================================================= #
  # === :local_path
  # ======================================================================= #
  set_local_path(nil)
  # ======================================================================= #
  # === :archive_type
  # ======================================================================= #
  @internal_hash[:archive_type] = nil
end
return_a_random_program_from_the_sqlite_database() click to toggle source
#

return_a_random_program_from_the_sqlite_database (random tag)

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 281
def return_a_random_program_from_the_sqlite_database
  cmd = "SELECT * FROM REGISTERED_PROGRAMS ORDER BY RANDOM() LIMIT 1;"
  result = `sqlite3 #{location_of_the_database?} "#{cmd}"`
  if result and result.include? '|'
    result = result.split('|')[1]
  end
  return result
end
run() click to toggle source
#

run

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 476
def run
  menu
  do_the_actual_compilation
end
run_make() click to toggle source
#

run_make

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 216
def run_make
  esystem 'make'
end
run_make_install() click to toggle source
#

run_make_install

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 209
def run_make_install
  esystem 'make install'
end
run_make_then_make_install() click to toggle source
#

run_make_then_make_install

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 179
def run_make_then_make_install
  run_make
  run_make_install
end
set_compile_this_program( i = :random ) click to toggle source
#

set_compile_this_program

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 112
def set_compile_this_program(
    i = :random
  )
  case i
  # ======================================================================= #
  # === :random
  #
  # In this case we query directly from the sqlite-database.
  # ======================================================================= #
  when :random
    i = return_a_random_program_from_the_sqlite_database
  end
  @internal_hash[:compile_this_program] = i.to_s
end
set_local_path(i) click to toggle source
#

set_local_path

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 72
def set_local_path(i)
  @internal_hash[:local_path] = i
end
set_new_prefix(i)
Alias for: set_prefix
set_prefix(i) click to toggle source
#

set_prefix

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 86
def set_prefix(i)
  case i
  # ======================================================================= #
  # === :appdir_prefix
  # ======================================================================= #
  when :appdir_prefix
    result = `sqlite3 #{location_of_the_database?} "select * from REGISTERED_PROGRAMS where PROGRAM_NAME = '#{compile_which_program?}';"`.split('|')[8]
    i = return_appdir_prefix_for(
          result
        )
  end
  i = i.to_s
  i << '/' unless i.end_with? '/'
  @internal_hash[:use_this_prefix].set_new_prefix(i)
end
Also aliased as: set_new_prefix
use_this_prefix?() click to toggle source
#

use_this_prefix?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 194
def use_this_prefix?
  @internal_hash[:use_this_prefix]
end
Also aliased as: use_this_prefix_object?
use_this_prefix_object?()
Alias for: use_this_prefix?
use_which_prefix?() click to toggle source
#

use_which_prefix?

#
# File lib/rbt/compile_via_sql_database/compile_via_sql_database.rb, line 187
def use_which_prefix?
  @internal_hash[:use_this_prefix].to_s
end
Also aliased as: prefix?