Class: Repackage::Repackage
- Inherits:
-
Object
- Object
- Repackage::Repackage
- Defined in:
- lib/repackage/class/misc.rb,
lib/repackage/class/constants.rb,
lib/repackage/class/repackage.rb
Overview
Repackage::Repackage
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- 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.
#
'tar -vcJf'
- DEFAULT_EXTRACT_TO_THIS_DIRECTORY =
Denote where to extract the stuff to.
'/tmp/repackage/'
- 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.
#
false
- COMMAND_TO_CREATE_A_ZIP_ARCHIVE =
#
COMMAND_TO_CREATE_A_ZIP_ARCHIVE
Command to create a .zip archive.
#
'zip -r '
- COMMAND_TO_CREATE_A_TAR_GZ_ARCHIVE =
#
COMMAND_TO_CREATE_A_TAR_GZ_ARCHIVE
Command to create a .tar.gz archive.
#
'tar cfvz'
- COMMAND_TO_CREATE_A_TAR_BZ2_ARCHIVE =
#
COMMAND_TO_CREATE_A_TAR_BZ2_ARCHIVE
Command to create a .tar.bz2 archive.
#
'tar cfvj'
- DEFAULT_TARGET_FORMAT_TYPE =
#
DEFAULT_TARGET_FORMAT_TYPE
The target format comes here, thus allowing the user to change the default.
#
'.tar.xz'
- 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.
#
false
Class Method Summary collapse
-
.[](this = ARGV) ⇒ Object
# === Repackage::Repackage[] ========================================================================= #.
Instance Method Summary collapse
-
#cd(where_to = extract_to? ) ⇒ Object
(also: #chdir, #change_dir, #change_dir_to)
# === cd (cd tag) ========================================================================= #.
-
#cliner ⇒ Object
# === cliner ========================================================================= #.
-
#commandline_arguments? ⇒ Boolean
# === commandline_arguments? ========================================================================= #.
-
#consider_copying_the_new_archive_into_the_current_working_directory ⇒ Object
# === consider_copying_the_new_archive_into_the_current_working_directory ========================================================================= #.
-
#consider_creating_the_working_directory(i = working_directory? ) ⇒ Object
# === consider_creating_the_working_directory ========================================================================= #.
-
#consider_loading_the_colours_gem ⇒ Object
# === consider_loading_the_colours_gem ========================================================================= #.
-
#copy_file(this_file, to_that_location) ⇒ Object
# === copy_file ========================================================================= #.
-
#copy_this_file_to_the_working_directory(this_file) ⇒ Object
# === copy_this_file_to_the_working_directory ========================================================================= #.
-
#create_archive_from_this_directory(this_directory, repackage_to_this_format = repackage_to_which_format? ) ⇒ Object
(also: #package_this_directory)
# === create_archive_from_this_directory (create tag) ========================================================================= #.
-
#delete_file(i) ⇒ Object
# === delete_file ========================================================================= #.
-
#determine_file_size(i = repackage_which_file? ) ⇒ Object
# === determine_file_size ========================================================================= #.
-
#dir_where_the_archive_resides? ⇒ Boolean
(also: #the_original_dir?)
# === dir_where_the_archive_resides? ========================================================================= #.
-
#do_delete_code_of_conduct_file ⇒ Object
# === do_delete_code_of_conduct_file ========================================================================= #.
-
#do_repackage_the_assigned_files(i = @work_on_these_files) ⇒ Object
(also: #do_repackage_these_files)
# === do_repackage_the_assigned_files ========================================================================= #.
-
#esystem(i) ⇒ Object
# === esystem ========================================================================= #.
-
#extract(what = filename?, , extract_to = extract_to? ) ⇒ Object
# === extract (extract tag).
-
#extract_to? ⇒ Boolean
(also: #extract_to, #extract_to_this_directory?, #extracted_to?)
# === extract_to?.
-
#first_argument? ⇒ Boolean
(also: #first?)
# === first_argument? ========================================================================= #.
-
#initialize(commandline_arguments = nil, run_already = true) ⇒ Repackage
constructor
# === initialize.
-
#internal_hash? ⇒ Boolean
(also: #hash?)
# === internal_hash? ========================================================================= #.
-
#is_it_already_in_the_correct_archive_format?(this_file) ⇒ Boolean
# === is_it_already_in_the_correct_archive_format? ========================================================================= #.
-
#is_on_roebe? ⇒ Boolean
# === is_on_roebe? ========================================================================= #.
-
#menu(i = commandline_arguments? ) ⇒ Object
# === menu ========================================================================= #.
-
#opn ⇒ Object
# === opn ========================================================================= #.
-
#orange(i) ⇒ Object
# === orange ========================================================================= #.
-
#rds(i) ⇒ Object
# === rds ========================================================================= #.
-
#register_sigint ⇒ Object
# === register_sigint ========================================================================= #.
-
#remove(i) ⇒ Object
(also: #delete)
# === remove.
-
#remove_archive_from(i) ⇒ Object
(also: #remove_extension, #remove_file_extension_from, #away_with_the_archive_type)
# === remove_archive_from.
-
#remove_old_extracted_directory_should_it_exist(i = rds("#{extract_to?}/#{remove_extension(filename?)}")) ⇒ Object
(also: #remove_extracted_data)
# === remove_old_extracted_directory_should_it_exist.
-
#remove_the_old_archive(i = dir_where_the_archive_resides?+filename? ) ⇒ Object
# === remove_the_old_archive.
-
#repackage_into_which_format? ⇒ Boolean
(also: #format?)
# === repackage_into_which_format? ========================================================================= #.
-
#repackage_this_particular_file(this_file) ⇒ Object
# === repackage_this_particular_file ========================================================================= #.
-
#repackage_to_this_format? ⇒ Boolean
(also: #repackage_to_which_format?, #target_format?, #target_format_type?)
# === repackage_to_this_format? ========================================================================= #.
-
#repackage_which_file? ⇒ Boolean
(also: #filename?)
# === repackage_which_file? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_pwd ⇒ Object
# === return_pwd ========================================================================= #.
-
#rev ⇒ Object
# === rev ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#run_the_proper_to_archive_command(on_this_directory) ⇒ Object
# === run_the_proper_to_archive_command.
-
#sdir(i) ⇒ Object
# === sdir ========================================================================= #.
-
#set_commandline_arguments(i = '') ⇒ Object
# === set_commandline_arguments ========================================================================= #.
-
#set_delete_code_of_conduct(i) ⇒ Object
# === set_delete_code_of_conduct ========================================================================= #.
-
#set_extract_to(i = DEFAULT_EXTRACT_TO_THIS_DIRECTORY) ⇒ Object
(also: #set_extract_to_this_directory)
# === set_extract_to.
-
#set_repackage_this_file(this_file) ⇒ Object
(also: #set_package)
# === set_repackage_this_file ========================================================================= #.
-
#set_repackage_to_this_format(i = :default_format) ⇒ Object
(also: #set_target_format_type, #format=)
# === set_repackage_to_this_format.
-
#set_shall_we_delete_the_old_archive(i = :default) ⇒ Object
(also: #set_shall_we_delete_old_source)
# === set_shall_we_delete_the_old_archive ========================================================================= #.
-
#set_start_dir(i = return_pwd) ⇒ Object
# === set_start_dir ========================================================================= #.
-
#set_the_new_file_is_at(i = nil) ⇒ Object
(also: #set_final_location, #set_the_final_location_is_at)
# === set_the_new_file_is_at ========================================================================= #.
-
#set_work_on_these_files(i = @commandline_arguments) ⇒ Object
# === set_work_on_these_files ========================================================================= #.
-
#sfile(i) ⇒ Object
# === sfile ========================================================================= #.
-
#shall_we_delete_the_old_archive? ⇒ Boolean
# === shall_we_delete_the_old_archive? ========================================================================= #.
-
#simp(i) ⇒ Object
# === simp ========================================================================= #.
-
#start_dir? ⇒ Boolean
# === start_dir? ========================================================================= #.
-
#swarn(i) ⇒ Object
# === swarn ========================================================================= #.
-
#the_final_location_is_at? ⇒ Boolean
(also: #the_new_file_is_at?, #the_file_is_where?)
# === the_final_location_is_at? ========================================================================= #.
-
#try_glob(i) ⇒ Object
# === try_glob.
-
#warn_about_missing_file_then_exit(i = target_file? ) ⇒ Object
# === warn_about_missing_file_then_exit ========================================================================= #.
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ Repackage
#
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”.
#
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/repackage/class/misc.rb', line 67 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 |
Class Method Details
.[](this = ARGV) ⇒ Object
#
Repackage::Repackage[]
#
61 62 63 |
# File 'lib/repackage/class/repackage.rb', line 61 def self.[](this = ARGV) new(this) end |
Instance Method Details
#cd(where_to = extract_to? ) ⇒ Object Also known as: chdir, change_dir, change_dir_to
#
cd (cd tag)
#
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/repackage/class/misc.rb', line 246 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 |
#cliner ⇒ Object
#
cliner
#
901 902 903 |
# File 'lib/repackage/class/misc.rb', line 901 def cliner e rev+('=' * 80) end |
#commandline_arguments? ⇒ Boolean
#
commandline_arguments?
#
207 208 209 |
# File 'lib/repackage/class/misc.rb', line 207 def commandline_arguments? @commandline_arguments end |
#consider_copying_the_new_archive_into_the_current_working_directory ⇒ Object
#
consider_copying_the_new_archive_into_the_current_working_directory
#
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/repackage/class/misc.rb', line 393 def _ = 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? ) ⇒ Object
#
consider_creating_the_working_directory
#
270 271 272 273 274 275 276 |
# File 'lib/repackage/class/misc.rb', line 270 def consider_creating_the_working_directory( i = working_directory? ) unless File.directory? i FileUtils.mkdir_p(i) end end |
#consider_loading_the_colours_gem ⇒ Object
#
consider_loading_the_colours_gem
#
329 330 331 |
# File 'lib/repackage/class/misc.rb', line 329 def consider_loading_the_colours_gem ::Repackage.consider_requiring_the_colours_gem end |
#copy_file(this_file, to_that_location) ⇒ Object
#
copy_file
#
438 439 440 |
# File 'lib/repackage/class/misc.rb', line 438 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) ⇒ Object
#
copy_this_file_to_the_working_directory
#
281 282 283 284 285 286 287 288 289 |
# File 'lib/repackage/class/misc.rb', line 281 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? ) ⇒ Object Also known as: package_this_directory
#
create_archive_from_this_directory (create tag)
#
445 446 447 448 449 450 |
# File 'lib/repackage/class/misc.rb', line 445 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 |
#delete_file(i) ⇒ Object
#
delete_file
#
41 42 43 |
# File 'lib/repackage/class/misc.rb', line 41 def delete_file(i) File.delete(i) end |
#determine_file_size(i = repackage_which_file? ) ⇒ Object
#
determine_file_size
#
515 516 517 518 519 520 521 |
# File 'lib/repackage/class/misc.rb', line 515 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? ⇒ Boolean Also known as: the_original_dir?
#
dir_where_the_archive_resides?
#
608 609 610 |
# File 'lib/repackage/class/misc.rb', line 608 def dir_where_the_archive_resides? @internal_hash[:original_directory_where_the_archive_was_kept] end |
#do_delete_code_of_conduct_file ⇒ Object
#
do_delete_code_of_conduct_file
#
175 176 177 |
# File 'lib/repackage/class/misc.rb', line 175 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) ⇒ Object Also known as: do_repackage_these_files
#
do_repackage_the_assigned_files
#
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
# File 'lib/repackage/class/misc.rb', line 714 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)+rev+' is already in '\ 'the desired target format ('+target_format?+ rev+').' opn; e "#{rev}Repackaging into the same target format makes no sense, "\ "thus aborting now." else opn; e rev+'We will try to repackage this archive into the `'+ simp(target_format_type?)+rev+'`' opn; e rev+'format type.' opn; e rev+'It will be extracted into the directory '+ sdir(extract_to?)+ rev+'.' # ================================================================= # # 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 |
#esystem(i) ⇒ Object
#
esystem
#
336 337 338 339 |
# File 'lib/repackage/class/misc.rb', line 336 def esystem(i) e i system i end |
#extract(what = filename?, , extract_to = extract_to? ) ⇒ Object
#
extract (extract tag)
Extract it here. Before we do so, though, we must check if the target does not exist yet.
#
699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/repackage/class/misc.rb', line 699 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? ⇒ Boolean Also known as: extract_to, extract_to_this_directory?, extracted_to?
#
extract_to?
Defaults to /home/x/Temp/ on my home system.
#
370 371 372 |
# File 'lib/repackage/class/misc.rb', line 370 def extract_to? @internal_hash[:extract_to_this_directory] end |
#first_argument? ⇒ Boolean Also known as: first?
#
first_argument?
#
214 215 216 |
# File 'lib/repackage/class/misc.rb', line 214 def first_argument? @commandline_arguments.first end |
#internal_hash? ⇒ Boolean Also known as: hash?
#
internal_hash?
#
221 222 223 |
# File 'lib/repackage/class/misc.rb', line 221 def internal_hash? @internal_hash end |
#is_it_already_in_the_correct_archive_format?(this_file) ⇒ Boolean
#
is_it_already_in_the_correct_archive_format?
#
499 500 501 |
# File 'lib/repackage/class/misc.rb', line 499 def is_it_already_in_the_correct_archive_format?(this_file) this_file.include? target_format? end |
#is_on_roebe? ⇒ Boolean
#
is_on_roebe?
#
228 229 230 |
# File 'lib/repackage/class/misc.rb', line 228 def is_on_roebe? ENV['IS_ROEBE'].to_s == '1' end |
#menu(i = commandline_arguments? ) ⇒ Object
#
menu
#
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/repackage/class/misc.rb', line 615 def ( i = commandline_arguments? ) if i.is_a? Array i.select {|inner_entry| inner_entry.start_with?('--') }.each {|entry| (entry) } else case i # ===================================================================== # # Let the user determine the format type here. # ===================================================================== # when /-?-?format(-|_)?type=(.+)$/i set_target_format_type( $2.to_s.dup ) end end end |
#opn ⇒ Object
#
opn
#
581 582 583 584 585 586 587 |
# File 'lib/repackage/class/misc.rb', line 581 def opn if Object.const_defined? :Opn Opn.opn(namespace: NAMESPACE) else # else do nothing. end end |
#orange(i) ⇒ Object
#
orange
#
379 380 381 |
# File 'lib/repackage/class/misc.rb', line 379 def orange(i) ::Repackage.orange(i) end |
#rds(i) ⇒ Object
#
rds
#
48 49 50 |
# File 'lib/repackage/class/misc.rb', line 48 def rds(i) i.squeeze '/' end |
#register_sigint ⇒ Object
#
register_sigint
#
21 22 23 |
# File 'lib/repackage/class/misc.rb', line 21 def register_sigint Signal.trap('SIGINT') { exit } end |
#remove(i) ⇒ Object Also known as: delete
#
remove
Remove a file or a directory with this method.
#
30 31 32 33 34 35 36 |
# 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 |
#remove_archive_from(i) ⇒ Object Also known as: remove_extension, remove_file_extension_from, away_with_the_archive_type
#
remove_archive_from
The proper order does matter in this method.
#
798 799 800 801 802 803 804 805 |
# File 'lib/repackage/class/misc.rb', line 798 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_old_extracted_directory_should_it_exist(i = rds("#{extract_to?}/#{remove_extension(filename?)}")) ⇒ Object Also known as: remove_extracted_data
#
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.
#
355 356 357 358 359 360 361 362 363 |
# File 'lib/repackage/class/misc.rb', line 355 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 |
#remove_the_old_archive(i = dir_where_the_archive_resides?+filename? ) ⇒ Object
#
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.
#
919 920 921 922 923 924 925 926 927 |
# File 'lib/repackage/class/misc.rb', line 919 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')} "\ "#{rev}constant." remove(i) end |
#repackage_into_which_format? ⇒ Boolean Also known as: format?
#
repackage_into_which_format?
#
189 190 191 |
# File 'lib/repackage/class/misc.rb', line 189 def repackage_into_which_format? @internal_hash[:repackage_into_this_format] end |
#repackage_this_particular_file(this_file) ⇒ Object
#
repackage_this_particular_file
#
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 |
# File 'lib/repackage/class/misc.rb', line 812 def repackage_this_particular_file(this_file) opn; e rev+'The file '+sfile(this_file)+rev+' will be repackaged '\ 'into the '+rev+ orange(repackage_to_which_format?)+ rev+' 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 rev+'Working from the directory `'+sdir(working_directory)+ rev+'` next.' absolute_path = File.absolute_path(this_file) opn; e rev+'The actual file that will be used for the repackaging' opn; e rev+'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/x/Temp/repackage/htop-3.1.2.tar.gz". ) ) end end |
#repackage_to_this_format? ⇒ Boolean Also known as: repackage_to_which_format?, target_format?, target_format_type?
#
repackage_to_this_format?
#
506 507 508 |
# File 'lib/repackage/class/misc.rb', line 506 def repackage_to_this_format? @internal_hash[:repackage_to_this_format] end |
#repackage_which_file? ⇒ Boolean Also known as: filename?
#
repackage_which_file?
#
344 345 346 |
# File 'lib/repackage/class/misc.rb', line 344 def repackage_which_file? @internal_hash[:repackage_this_file] end |
#reset ⇒ Object
#
reset (reset tag)
#
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/repackage/class/misc.rb', line 117 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 ⇒ Object
#
return_pwd
#
14 15 16 |
# File 'lib/repackage/class/misc.rb', line 14 def return_pwd "#{Dir.pwd}/".squeeze('/') end |
#rev ⇒ Object
#
rev
#
908 909 910 |
# File 'lib/repackage/class/misc.rb', line 908 def rev ::Repackage.rev end |
#run ⇒ Object
#
run (run tag)
#
932 933 934 935 936 937 938 |
# File 'lib/repackage/class/misc.rb', line 932 def run 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) ⇒ Object
#
run_the_proper_to_archive_command
The argument to this method should be a String representing a directory.
#
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'lib/repackage/class/misc.rb', line 654 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) ⇒ Object
#
sdir
#
308 309 310 |
# File 'lib/repackage/class/misc.rb', line 308 def sdir(i) ::Repackage.sdir(i) end |
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
199 200 201 202 |
# File 'lib/repackage/class/misc.rb', line 199 def set_commandline_arguments(i = '') i = [i].flatten.compact @commandline_arguments = i end |
#set_delete_code_of_conduct(i) ⇒ Object
#
set_delete_code_of_conduct
#
182 183 184 |
# File 'lib/repackage/class/misc.rb', line 182 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) ⇒ Object Also known as: set_extract_to_this_directory
#
set_extract_to
Set the @extract_to variable here.
#
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'lib/repackage/class/misc.rb', line 873 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/x/Temp/' i = '/home/x/Temp/repackage/' elsif 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_repackage_this_file(this_file) ⇒ Object Also known as: set_package
#
set_repackage_this_file
#
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/repackage/class/misc.rb', line 526 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 |
#set_repackage_to_this_format(i = :default_format) ⇒ Object Also known as: set_target_format_type, format=
#
set_repackage_to_this_format
We will repackage to this format here.
#
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/repackage/class/misc.rb', line 457 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 |
#set_shall_we_delete_the_old_archive(i = :default) ⇒ Object Also known as: set_shall_we_delete_old_source
#
set_shall_we_delete_the_old_archive
#
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/repackage/class/misc.rb', line 155 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) ⇒ Object
#
set_start_dir
#
429 430 431 432 433 |
# File 'lib/repackage/class/misc.rb', line 429 def set_start_dir( i = return_pwd ) @internal_hash[:start_dir] = i end |
#set_the_new_file_is_at(i = nil) ⇒ Object Also known as: set_final_location, set_the_final_location_is_at
#
set_the_new_file_is_at
#
600 601 602 |
# File 'lib/repackage/class/misc.rb', line 600 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) ⇒ Object
#
set_work_on_these_files
#
235 236 237 238 239 240 241 |
# File 'lib/repackage/class/misc.rb', line 235 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) ⇒ Object
#
sfile
#
315 316 317 |
# File 'lib/repackage/class/misc.rb', line 315 def sfile(i) ::Repackage.sfile(i) end |
#shall_we_delete_the_old_archive? ⇒ Boolean
#
shall_we_delete_the_old_archive?
#
386 387 388 |
# File 'lib/repackage/class/misc.rb', line 386 def shall_we_delete_the_old_archive? @internal_hash[:shall_we_delete_the_old_archive] end |
#simp(i) ⇒ Object
#
simp
#
301 302 303 |
# File 'lib/repackage/class/misc.rb', line 301 def simp(i) ::Repackage.simp(i) end |
#start_dir? ⇒ Boolean
#
start_dir?
#
422 423 424 |
# File 'lib/repackage/class/misc.rb', line 422 def start_dir? @internal_hash[:start_dir] end |
#swarn(i) ⇒ Object
#
swarn
#
322 323 324 |
# File 'lib/repackage/class/misc.rb', line 322 def swarn(i) ::Repackage.swarn(i) end |
#the_final_location_is_at? ⇒ Boolean Also known as: the_new_file_is_at?, the_file_is_where?
#
the_final_location_is_at?
#
592 593 594 |
# File 'lib/repackage/class/misc.rb', line 592 def the_final_location_is_at? @internal_hash[:the_new_file_is_at] end |
#try_glob(i) ⇒ Object
#
try_glob
Try a glob with this method.
#
57 58 59 |
# File 'lib/repackage/class/misc.rb', line 57 def try_glob(i) return Dir[i+'*'] end |
#warn_about_missing_file_then_exit(i = target_file? ) ⇒ Object
#
warn_about_missing_file_then_exit
#
638 639 640 641 642 643 644 645 646 |
# File 'lib/repackage/class/misc.rb', line 638 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 |