class Repackage::Repackage

Constants

COMMAND_TO_CREATE_A_TAR_BZ2_ARCHIVE
#

COMMAND_TO_CREATE_A_TAR_BZ2_ARCHIVE

Command to create a .tar.bz2 archive.

#
COMMAND_TO_CREATE_A_TAR_GZ_ARCHIVE
#

COMMAND_TO_CREATE_A_TAR_GZ_ARCHIVE

Command to create a .tar.gz archive.

#
COMMAND_TO_CREATE_A_TAR_XZ_ARCHIVE
#

COMMAND_TO_CREATE_A_TAR_XZ_ARCHIVE

This is the command that is used when a .tar.xz file is to be created.

#
COMMAND_TO_CREATE_A_ZIP_ARCHIVE
#

COMMAND_TO_CREATE_A_ZIP_ARCHIVE

Command to create a .zip archive.

#
DEFAULT_EXTRACT_TO_THIS_DIRECTORY
DEFAULT_TARGET_FORMAT_TYPE
#

DEFAULT_TARGET_FORMAT_TYPE

The target format comes here, thus allowing the user to change the default.

#
DELETE_CODE_OF_CONDUCT_FILE_IF_IT_EXISTS
#

DELETE_CODE_OF_CONDUCT_FILE_IF_IT_EXISTS

The following variable is set to false by default. It has been added in September 2022 because another project (rbt) requires this setting - that is to toggle it on or off.

#
LAST_DOWNLOADED_FILE
NAMESPACE
#

NAMESPACE

#
SHALL_WE_DELETE_THE_OLD_ARCHIVE
#

SHALL_WE_DELETE_THE_OLD_ARCHIVE

Remove the old source if this constant is true. Since as of June 2021 this defaults to false, except in certain conditions met on my home setup where the variable that keeps track of it is turned to true actually. Most other users will probably never need to change this, though, so the default is to false.

#

Public Class Methods

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

Repackage::Repackage[]

#
# File lib/repackage/class/repackage.rb, line 61
def self.[](this = ARGV)
  new(this)
end
new( commandline_arguments = nil, run_already = true ) { || ... } click to toggle source
#

initialize

The first argument given to this class should be the name, or the path, to a locally existing file, such as “foobar-1.0.tar.gz”.

#
# File lib/repackage/class/misc.rb, line 74
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  register_sigint
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  # ======================================================================= #
  # === Handle given blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_delete_the_old_source
    # ===================================================================== #
    when :do_not_delete_the_old_source
      set_shall_we_delete_old_source(false)
    # ===================================================================== #
    # === :run_already
    # ===================================================================== #
    when :run_already
      run_already = true
    else
      if yielded.is_a? Hash
        # ================================================================= #
        # === :run
        # ================================================================= #
        if yielded.has_key? :run
          run_already = yielded[:run]
        end
        # ================================================================= #
        # === :delete_code_of_conduct
        # ================================================================= #
        if yielded.has_key? :delete_code_of_conduct
          set_delete_code_of_conduct(
            yielded[:delete_code_of_conduct]
          )
        end
      end
    end
  end
  run if run_already
end

Public Instance Methods

away_with_the_archive_type(i)
Alias for: remove_archive_from
cd( where_to = extract_to? ) click to toggle source
#

cd (cd tag)

#
# File lib/repackage/class/misc.rb, line 253
def cd(
    where_to = extract_to?
  )
  case where_to
  # ======================================================================= #
  # === :to_the_start_dir
  # ======================================================================= #
  when :to_the_start_dir,
       :start_dir
    where_to = start_dir?
  # ======================================================================= #
  # === :to_the_original_dir
  # ======================================================================= #
  when :to_the_original_dir
    where_to = the_original_dir?
  end
  Dir.chdir(where_to) if File.directory?(where_to)
end
Also aliased as: chdir, change_dir, change_dir_to
change_dir( where_to = extract_to? )
Alias for: cd
change_dir_to( where_to = extract_to? )
Alias for: cd
chdir( where_to = extract_to? )
Alias for: cd
cliner() click to toggle source
#

cliner

#
# File lib/repackage/class/misc.rb, line 55
def cliner
  e rev+('=' * 80)
end
commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/repackage/class/misc.rb, line 214
def commandline_arguments?
  @commandline_arguments
end
consider_copying_the_new_archive_into_the_current_working_directory() click to toggle source
#

consider_copying_the_new_archive_into_the_current_working_directory

#
# File lib/repackage/class/misc.rb, line 435
def consider_copying_the_new_archive_into_the_current_working_directory
  _ = away_with_the_archive_type(
        extracted_to?+ # This part is like "/home/Temp/repackage/".
        repackage_which_file?
     )+
     repackage_to_which_format?
  if File.exist?(_)
    cd(:to_the_original_dir)
    new_target = return_pwd+File.basename(_)
    opn; e 'Now copying '+sfile(_)+' to the current directory.'
    opn; e 'It will then reside at '+sfile(new_target)+'.'
    copy_file(_, new_target)
    if File.exist? new_target
      opn; e 'Done! The file can be found '\
             'at '+sfile(new_target)+' now.'
      set_the_final_location_is_at(File.absolute_path(new_target))
      if shall_we_delete_the_old_archive?
        remove_the_old_archive
      end
    else
      opn; e 'No file at '+sfile(new_target)+' exists, '\
             'thus we can not move anything.'
    end
  end
end
consider_creating_the_working_directory( i = working_directory? ) click to toggle source
#

consider_creating_the_working_directory

#
# File lib/repackage/class/misc.rb, line 277
def consider_creating_the_working_directory(
    i = working_directory?
  )
  unless File.directory? i
    FileUtils.mkdir_p(i)
  end
end
consider_loading_the_colours_gem() click to toggle source
#

consider_loading_the_colours_gem

#
# File lib/repackage/class/misc.rb, line 343
def consider_loading_the_colours_gem
  ::Repackage.consider_requiring_the_colours_gem
end
copy_file(this_file, to_that_location) click to toggle source
#

copy_file

#
# File lib/repackage/class/misc.rb, line 480
def copy_file(this_file, to_that_location)
  FileUtils.cp(this_file, to_that_location)
end
copy_this_file_to_the_working_directory( this_file ) click to toggle source
#

copy_this_file_to_the_working_directory

#
# File lib/repackage/class/misc.rb, line 288
def copy_this_file_to_the_working_directory(
    this_file
  )
  target = "#{working_directory?}#{File.basename(this_file)}"
  File.delete(target) if File.exist?(target)
  FileUtils.cp(
    this_file, target
  )
end
create_archive_from_this_directory( this_directory, repackage_to_this_format = repackage_to_which_format? ) click to toggle source
#

create_archive_from_this_directory (create tag)

#
# File lib/repackage/class/misc.rb, line 487
def create_archive_from_this_directory(
    this_directory,
    repackage_to_this_format = repackage_to_which_format?
  )
  esystem "#{COMMAND_TO_CREATE_A_TAR_XZ_ARCHIVE} #{this_directory}#{repackage_to_this_format} #{File.basename(this_directory)}"
end
Also aliased as: package_this_directory
delete(i)
Alias for: remove
delete_file(i) click to toggle source
#

delete_file

#
# File lib/repackage/class/misc.rb, line 41
def delete_file(i)
  File.delete(i)
end
determine_file_size( i = repackage_which_file? ) click to toggle source
#

determine_file_size

#
# File lib/repackage/class/misc.rb, line 557
def determine_file_size(
    i = repackage_which_file?
  )
  if i and File.exist?(i)
    @internal_hash[:file_size] = File.stat(i).size? # Obtain some information.
  end
end
dir_where_the_archive_resides?() click to toggle source
#

dir_where_the_archive_resides?

#
# File lib/repackage/class/misc.rb, line 650
def dir_where_the_archive_resides?
  @internal_hash[:original_directory_where_the_archive_was_kept]
end
Also aliased as: the_original_dir?
do_delete_code_of_conduct_file() click to toggle source
#

do_delete_code_of_conduct_file

#
# File lib/repackage/class/misc.rb, line 182
def do_delete_code_of_conduct_file
  @internal_hash[:delete_code_of_conduct_file_if_it_exists] = true
end
do_repackage_the_assigned_files( i = @work_on_these_files ) click to toggle source
#

do_repackage_the_assigned_files

#
# File lib/repackage/class/misc.rb, line 773
def do_repackage_the_assigned_files(
    i = @work_on_these_files
  )
  # ======================================================================= #
  # The input may look like this:
  #
  #   ["Python-3.10.7.tar.gz"]
  #
  # ======================================================================= #
  i.flatten.compact.each {|this_file|
    # ===================================================================== #
    # Clean up :the_new_file_is_at first:
    # ===================================================================== #
    @internal_hash[:the_new_file_is_at] = nil
    set_the_final_location_is_at(nil) # This is also cleanup.
    cliner
    set_repackage_this_file(this_file)
    determine_file_size if File.exist? this_file
    if File.exist? this_file
      # =================================================================== #
      # === Consider refusing the repackage-action
      #
      # Check whether the file is already in the correct target archive
      # format.
      # =================================================================== #
      if is_it_already_in_the_correct_archive_format?(this_file)
        opn; e rev+'The file at '+sfile(this_file)+' is already in '\
               'the desired target format ('+target_format?+').'
        opn; e "Repackaging into the same target format makes no sense, "\
               "thus aborting now."
      else
        opn; e 'We will try to repackage this archive into the `'+
                simp(target_format_type?)+'`'
        opn; e 'format type.'
        opn; e 'It will be extracted into the directory '+
                sdir(extract_to?)+'.'
        # ================================================================= #
        # Here we know that the file exists and that it can be repackaged
        # into another target format. Thus, we can repackage it. We
        # will delegate towards a method for this.
        # ================================================================= #
        repackage_this_particular_file(this_file)
      end
    else
      # =================================================================== #
      # Ok - in this case the file does not exist. We will first try
      # to check if we have a number as input; if so we then we may
      # try a glob-action. And if not, we will raise an error.
      #
      # This can be invoked like so:
      #
      #   repackagerb 1
      #
      # =================================================================== #
      if this_file and (this_file =~ /^\d$/) # If input is a (positional) number like "3"
        _ = Dir['*'].select {|entry| File.file?(entry) }.
            sort[this_file.to_i - 1]
        do_repackage_these_files([_])
      else
        # ================================================================= #
        # Else we can still try a glob, before giving up.
        # ================================================================= #
        _ = try_glob(this_file) if this_file
        if _.empty?
          warn_about_missing_file_then_exit
        else
          first = _.first
          if first and File.file?(first)
            do_repackage_these_files([first])
          end
        end
      end
    end
    cliner
  }
end
Also aliased as: do_repackage_these_files
do_repackage_these_files( i = @work_on_these_files )
esystem(i) click to toggle source
#

esystem

#
# File lib/repackage/class/misc.rb, line 350
def esystem(i)
  e i
  system i
end
extract( what = filename?, extract_to = extract_to? ) click to toggle source
#

extract (extract tag)

Extract it here. Before we do so, though, we must check if the target does not exist yet.

#
# File lib/repackage/class/misc.rb, line 758
def extract(
    what       = filename?,
    extract_to = extract_to?
  )
  what = what.dup if what.frozen?
  unless what.include? '/'
    what = dir_where_the_archive_resides?+File.basename(what)
  end
  remove_extracted_data
  Extracter.extract_what_to(what, extract_to)
end
extract_to()
Alias for: extract_to?
extract_to?() click to toggle source
#

extract_to?

Defaults to /home/Temp/ on my home system.

#
# File lib/repackage/class/misc.rb, line 412
def extract_to?
  @internal_hash[:extract_to_this_directory]
end
Also aliased as: extract_to, extract_to_this_directory?, extracted_to?
extract_to_this_directory?() click to toggle source
#

extract_to_this_directory?

#
# File lib/repackage/class/misc.rb, line 308
def extract_to_this_directory?
  @internal_hash[:extract_to_this_directory]
end
Also aliased as: working_directory?
extracted_to?()
Alias for: extract_to?
filename?()
first?()
Alias for: first_argument?
first_argument?() click to toggle source
#

first_argument?

#
# File lib/repackage/class/misc.rb, line 221
def first_argument?
  @commandline_arguments.first
end
Also aliased as: first?
format=( i = :default_format )
format?()
hash?()
Alias for: internal_hash?
internal_hash?() click to toggle source
#

internal_hash?

#
# File lib/repackage/class/misc.rb, line 228
def internal_hash?
  @internal_hash
end
Also aliased as: hash?
is_it_already_in_the_correct_archive_format?(this_file) click to toggle source
#

is_it_already_in_the_correct_archive_format?

#
# File lib/repackage/class/misc.rb, line 541
def is_it_already_in_the_correct_archive_format?(this_file)
  this_file.include? target_format?
end
is_on_roebe?() click to toggle source
#

is_on_roebe?

#
# File lib/repackage/class/misc.rb, line 235
def is_on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end
menu( i = commandline_arguments? ) click to toggle source
#

menu

#
opn() click to toggle source
#

opn

#
# File lib/repackage/class/misc.rb, line 623
def opn
  if Object.const_defined? :Opn
    Opn.opn(namespace: NAMESPACE)
  else
    # else do nothing.
  end
end
orange(i) click to toggle source
#

orange

#
# File lib/repackage/class/misc.rb, line 421
def orange(i)
  ::Repackage.orange(i)
end
package_this_directory( this_directory, repackage_to_this_format = repackage_to_which_format? )
rds(i) click to toggle source
#

rds

#
# File lib/repackage/class/misc.rb, line 48
def rds(i)
  i.squeeze '/'
end
register_sigint() click to toggle source
#

register_sigint

#
# File lib/repackage/class/misc.rb, line 21
def register_sigint
  Signal.trap('SIGINT') { exit }
end
remove(i) click to toggle source
#

remove

Remove a file or a directory with this method.

#
# File lib/repackage/class/misc.rb, line 30
def remove(i)
  if File.directory?(i)
    FileUtils.rm_rf(i) unless i.strip == '/' # A tiny safeguard.
  elsif File.file?(i)
    delete_file(i)
  end
end
Also aliased as: delete
remove_archive_from(i) click to toggle source
#

remove_archive_from

The proper order does matter in this method.

#
# File lib/repackage/class/misc.rb, line 855
def remove_archive_from(i)
  i.delete_suffix('.xz').
    delete_suffix('.gz').
    delete_suffix('.bz2').
    delete_suffix('.zip').
    delete_suffix('.tgz').
    delete_suffix('.tar')
end
remove_extension(i)
Alias for: remove_archive_from
remove_extracted_data( i = rds("
remove_file_extension_from(i)
Alias for: remove_archive_from
remove_old_extracted_directory_should_it_exist( i = rds(" click to toggle source
#

remove_old_extracted_directory_should_it_exist

This method will remove any extracted archive that exits at the target location. This will avoid “unclean” directories.

#
# File lib/repackage/class/misc.rb, line 369
def remove_old_extracted_directory_should_it_exist(
    i = rds("#{extract_to?}/#{remove_extension(filename?)}")
  )
  if File.directory?(i) # We remove a possibly-existing, extracted directory first.
    e 'Removing the existing directory '\
      'at `'+sdir(i)+'` next.'
    remove(i)
  end
end
Also aliased as: remove_extracted_data
remove_the_old_archive( i = dir_where_the_archive_resides?+filename? ) click to toggle source
#

remove_the_old_archive

Only call this when we are sure to remove the old source. I recommend to delete the old source. Of course we must make sure to delete the right package.

#
# File lib/repackage/class/misc.rb, line 742
def remove_the_old_archive(
    i = dir_where_the_archive_resides?+filename?
  )
  opn; e "Removing the old archive at #{sfile(i)}"
  opn; e "next, as requested via the "\
         "#{::Repackage.steelblue('SHALL_WE_DELETE_THE_OLD_ARCHIVE')} "\
         "constant."
  remove(i)
end
repackage_into_which_format?() click to toggle source
#

repackage_into_which_format?

#
# File lib/repackage/class/misc.rb, line 196
def repackage_into_which_format?
  @internal_hash[:repackage_into_this_format]
end
repackage_this_particular_file(this_file) click to toggle source
#

repackage_this_particular_file

#
# File lib/repackage/class/misc.rb, line 869
def repackage_this_particular_file(this_file)
  opn; e rev+'The file '+sfile(this_file)+' will be repackaged '\
         'into the '+orange(repackage_to_which_format?)+' format.'
  copy_this_file_to_the_working_directory(this_file)
  working_directory = working_directory?
  cd(working_directory) # Go to the working directory.
  set_start_dir(working_directory)
  opn; e 'Working from the directory `'+sdir(working_directory)+'` next.'
  absolute_path = File.absolute_path(this_file)
  opn; e 'The actual file that will be used for the '\
         'repackaging'
  opn; e 'step now resides at: '
  e
  e "  #{sdir(absolute_path)}"
  e
  # ======================================================================= #
  # Ok, now we have to extract it.
  # ======================================================================= #
  if File.exist? absolute_path
    extract(absolute_path)
    if DELETE_CODE_OF_CONDUCT_FILE_IF_IT_EXISTS
      target = return_pwd+
               remove_archive_from(
                 File.basename(repackage_which_file?)
               )
      all_files = Dir[target+'/*']
      if all_files.any? {|file_path| file_path.include?('CODE_OF_CONDUCT') }
        # In this case we found at the least one code-of-conduct files.
        # Delete it now.
        selection = all_files.select {|file_path|
          file_path.include?('CODE_OF_CONDUCT') and File.file?(file_path)
        }
        selection.each {|this_file|
          opn; e 'Now deleting the file '+sfile(this_file)
          opn; e 'as requested by the user.'
          delete_file(this_file)
        }
      end
    end
    # ===================================================================== #
    # If all went well then we can now create the new desired target
    # format. So if that format is '.tar.xz' then we will have to
    # run the proper command that will create such a tarball for
    # us next.
    # ===================================================================== #
    run_the_proper_to_archive_command(
      remove_file_extension_from(
        absolute_path # This here is e. g. "/home/Temp/repackage/htop-3.1.2.tar.gz".
      )
    )
    consider_copying_the_new_archive_into_the_current_working_directory
  end
end
repackage_to_this_format?() click to toggle source
#

repackage_to_this_format?

#
# File lib/repackage/class/misc.rb, line 548
def repackage_to_this_format?
  @internal_hash[:repackage_to_this_format]
end
Also aliased as: repackage_to_which_format?, target_format?, target_format_type?
repackage_to_which_format?()
repackage_which_file?() click to toggle source
#

repackage_which_file?

#
# File lib/repackage/class/misc.rb, line 358
def repackage_which_file?
  @internal_hash[:repackage_this_file]
end
Also aliased as: filename?
reset() click to toggle source
#

reset (reset tag)

#
# File lib/repackage/class/misc.rb, line 124
def reset
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :delete_code_of_conduct_file_if_it_exists
  # ======================================================================= #
  @internal_hash[:delete_code_of_conduct_file_if_it_exists] = DELETE_CODE_OF_CONDUCT_FILE_IF_IT_EXISTS
  # ======================================================================= #
  # === :file_size
  # ======================================================================= #
  @internal_hash[:file_size] = 0
  set_extract_to_this_directory(:default)
  set_start_dir
  # ======================================================================= #
  # === :repackage_into_this_format
  #
  # .tar.xz is the default target format.
  # ======================================================================= #
  set_repackage_to_this_format(:to_the_default_format)
  # ======================================================================= #
  # === :the_new_file_is_at
  #
  # This entry will keep track at which new location the file can be
  # found.
  # ======================================================================= #
  @internal_hash[:the_new_file_is_at] = nil
  set_shall_we_delete_the_old_archive(:default)
end
return_pwd() click to toggle source
#

return_pwd

#
# File lib/repackage/class/misc.rb, line 14
def return_pwd
  "#{Dir.pwd}/".squeeze('/')
end
rev() click to toggle source
#

rev

#
# File lib/repackage/class/misc.rb, line 301
def rev
  ::Repackage.rev
end
run() click to toggle source
#

run (run tag)

#
# File lib/repackage/class/misc.rb, line 926
def run
  menu
  consider_loading_the_colours_gem
  consider_creating_the_working_directory
  set_work_on_these_files(@commandline_arguments)
  do_repackage_the_assigned_files
end
run_the_proper_to_archive_command( on_this_directory ) click to toggle source
#

run_the_proper_to_archive_command

The argument to this method should be a String representing a directory.

#
# File lib/repackage/class/misc.rb, line 696
def run_the_proper_to_archive_command(
    on_this_directory
  )
  on_this_directory = on_this_directory.dup if on_this_directory.frozen?
  target_format = repackage_to_which_format?
  case target_format # case tag
  # ======================================================================= #
  # === .tar.xz
  # ======================================================================= #
  when /\.tar\.xz/i
    esystem "#{COMMAND_TO_CREATE_A_TAR_XZ_ARCHIVE} "\
            "#{on_this_directory}#{repackage_to_which_format?} "\
            "#{File.basename(on_this_directory)}"
  # ======================================================================= #
  # === .tar.gz
  # ======================================================================= #
  when /\.tar\.gz/i
    esystem "#{COMMAND_TO_CREATE_A_TAR_GZ_ARCHIVE} "\
            "#{on_this_directory}#{repackage_to_which_format?} "\
            "#{File.basename(on_this_directory)}"
  # ======================================================================= #
  # === .tar.bz2
  # ======================================================================= #
  when /\.tar\.bz2/i
    esystem "#{COMMAND_TO_CREATE_A_TAR_BZ2_ARCHIVE} "\
            "#{on_this_directory}#{repackage_to_which_format?} "\
            "#{File.basename(on_this_directory)}"
  # ======================================================================= #
  # === .zip
  # ======================================================================= #
  when /\.zip/i
    esystem "#{COMMAND_TO_CREATE_A_ZIP_ARCHIVE} "\
            "#{on_this_directory}#{repackage_to_which_format?} "\
            "#{File.basename(on_this_directory)}"
  else
    e 'Unknown target format: '+format.to_s
  end
end
sdir(i) click to toggle source
#

sdir

#
# File lib/repackage/class/misc.rb, line 322
def sdir(i)
  ::Repackage.sdir(i)
end
set_commandline_arguments(i = '') click to toggle source
#

set_commandline_arguments

#
# File lib/repackage/class/misc.rb, line 206
def set_commandline_arguments(i = '')
  i = [i].flatten.compact
  @commandline_arguments = i
end
set_delete_code_of_conduct(i) click to toggle source
#

set_delete_code_of_conduct

#
# File lib/repackage/class/misc.rb, line 189
def set_delete_code_of_conduct(i)
  @internal_hash[:delete_code_of_conduct_file_if_it_exists] = i
end
set_extract_to( i = DEFAULT_EXTRACT_TO_THIS_DIRECTORY ) click to toggle source
#

set_extract_to

Set the @extract_to variable here.

#
# File lib/repackage/class/misc.rb, line 384
def set_extract_to(
    i = DEFAULT_EXTRACT_TO_THIS_DIRECTORY # Must be the initial constant as default.
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    i = DEFAULT_EXTRACT_TO_THIS_DIRECTORY
  end
  i = i.to_s.dup
  # ======================================================================= #
  # The next clause is an override, in particular for my home system.
  # ======================================================================= #
  if File.directory? '/home/Temp/'
    i = '/home/Temp/repackage/'
  end
  i = '/tmp/' if i.empty? # Hardcoded rescue-step in this case.
  i << '/' unless i.end_with? '/' # A directory has a trailing /.
  @internal_hash[:extract_to_this_directory] = i
end
set_extract_to_this_directory( i = DEFAULT_EXTRACT_TO_THIS_DIRECTORY )
Alias for: set_extract_to
set_final_location(i = nil)
set_package(this_file)
set_repackage_this_file(this_file) click to toggle source
#

set_repackage_this_file

#
# File lib/repackage/class/misc.rb, line 568
def set_repackage_this_file(this_file)
  this_file = this_file.first if this_file.is_a? Array
  case this_file
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    # ===================================================================== #
    # Since as of May 2013 we try to fetch a random file from a list.
    # ===================================================================== #
    _ = Dir['*'].reject {|entry| File.directory? entry}
    this_file = _.first if _.size == 1 # if we only have one entry, continue here.
  # ======================================================================= #
  # === --last
  # ======================================================================= #
  when /^-?-?last(-|_)?downloaded$/i,
       /^-?-?last$/i,
       '-l'
    this_file = File.readlines(LAST_DOWNLOADED_FILE).first
    # ===================================================================== #
    # The format of the file has changed a bit. We have to check
    # whether it includes a '#' character. If so then we discard
    # all that comes after said '#' token.
    # ===================================================================== #
    if this_file.include? '#'
      this_file = this_file[0 .. (this_file.index('#')-1)].strip
    end
  end
  this_file = this_file.to_s.dup # Keep a copy.
  if File.directory?(this_file) and !this_file.end_with?('/')
    this_file << '/'
  end
  if this_file.nil? or this_file.empty?
    raise 'Please provide a valid archive to repackage.'
  end
  @internal_hash[:repackage_this_file] = this_file
  if this_file and File.exist?(this_file)
    # ===================================================================== #
    # === :original_directory_where_the_archive_was_kept
    #
    # This entry point will always refer to the directory where the
    # archive was originally situated in.
    # ===================================================================== #
    @internal_hash[:original_directory_where_the_archive_was_kept] = rds(
      File.absolute_path(
        File.dirname(this_file)
      )+'/'
    )
  end
end
Also aliased as: set_package
set_repackage_to_this_format( i = :default_format ) click to toggle source
#

set_repackage_to_this_format

We will repackage to this format here.

#
# File lib/repackage/class/misc.rb, line 499
def set_repackage_to_this_format(
    i = :default_format
  )
  i = i.downcase if i and i.is_a?(String) # Only want it downcased.
  case i # case tag
  # ======================================================================= #
  # === nil
  # ======================================================================= #
  when nil, # Assume a default here.
       :default,
       :default_format,
       :to_the_default_format
    i = DEFAULT_TARGET_FORMAT_TYPE
  # ======================================================================= #
  # === .tar.xz
  # ======================================================================= #
  when 'xz',
       'tar.xz'
    i = '.tar.xz'
  # ======================================================================= #
  # === .tar.bz2
  # ======================================================================= #
  when 'bz2',
       '.tar.bz2'
    i = '.tar.bz2'
  # ======================================================================= #
  # === .tar.gz
  # ======================================================================= #
  when 'targz',
       'gz',
       'tar.gz'
    i = '.tar.gz'
  else # else tag
    # warn 'Did not find registered format type.'
  end
  @internal_hash[:repackage_to_this_format] = i
end
Also aliased as: set_target_format_type, format=
set_shall_we_delete_old_source( i = :default )
set_shall_we_delete_the_old_archive( i = :default ) click to toggle source
#

set_shall_we_delete_the_old_archive

#
# File lib/repackage/class/misc.rb, line 162
def set_shall_we_delete_the_old_archive(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    i = SHALL_WE_DELETE_THE_OLD_ARCHIVE
    if is_on_roebe?
      i = true
    end
  end
  @internal_hash[:shall_we_delete_the_old_archive] = i
end
set_start_dir( i = return_pwd ) click to toggle source
#

set_start_dir

#
# File lib/repackage/class/misc.rb, line 471
def set_start_dir(
    i = return_pwd
  )
  @internal_hash[:start_dir] = i
end
set_target_format_type( i = :default_format )
set_the_final_location_is_at(i = nil)
set_the_new_file_is_at(i = nil) click to toggle source
#

set_the_new_file_is_at

#
# File lib/repackage/class/misc.rb, line 642
def set_the_new_file_is_at(i = nil)
  @internal_hash[:the_new_file_is_at] = i
end
set_work_on_these_files( i = @commandline_arguments ) click to toggle source
#

set_work_on_these_files

#
# File lib/repackage/class/misc.rb, line 242
def set_work_on_these_files(
    i = @commandline_arguments
  )
  i = [i].flatten.compact
  i.reject! {|entry| entry.start_with?('--') }
  @work_on_these_files = i
end
sfile(i) click to toggle source
#

sfile

#
# File lib/repackage/class/misc.rb, line 329
def sfile(i)
  ::Repackage.sfile(i)
end
shall_we_delete_the_old_archive?() click to toggle source
#

shall_we_delete_the_old_archive?

#
# File lib/repackage/class/misc.rb, line 428
def shall_we_delete_the_old_archive?
  @internal_hash[:shall_we_delete_the_old_archive]
end
simp(i) click to toggle source
#

simp

#
# File lib/repackage/class/misc.rb, line 315
def simp(i)
  ::Repackage.simp(i)
end
start_dir?() click to toggle source
#

start_dir?

#
# File lib/repackage/class/misc.rb, line 464
def start_dir?
  @internal_hash[:start_dir]
end
swarn(i) click to toggle source
#

swarn

#
# File lib/repackage/class/misc.rb, line 336
def swarn(i)
  ::Repackage.swarn(i)
end
target_format?()
target_format_type?()
the_file_is_where?()
the_final_location_is_at?() click to toggle source
#

the_final_location_is_at?

#
# File lib/repackage/class/misc.rb, line 634
def the_final_location_is_at?
  @internal_hash[:the_new_file_is_at]
end
the_new_file_is_at?()
the_original_dir?()
try_glob(i) click to toggle source
#

try_glob

Try a glob with this method.

#
# File lib/repackage/class/misc.rb, line 64
def try_glob(i)
  return Dir[i+'*']
end
warn_about_missing_file_then_exit( i = target_file? ) click to toggle source
#

warn_about_missing_file_then_exit

#
# File lib/repackage/class/misc.rb, line 680
def warn_about_missing_file_then_exit(
    i = target_file?
  )
  opn;e swarn('The file `')+sfile(i)+
        swarn('` does not exist. Must provide a valid path here.')
  raise "The argument given must be the path to an existing "\
        "(local) file.\nAs the path given does not appear "\
        "to exist, this class can not continue."
end
working_directory?()