extracter 1.1.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of extracter might be problematic. Click here for more details.

@@ -0,0 +1,237 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Extracter::ExtractIt
6
+ #
7
+ # If no input was provided to this class, but a .zip file exists in
8
+ # the current working directory, then that .zip file will be used.
9
+ #
10
+ # Usage example:
11
+ #
12
+ # Extracter::ExtractIt.new(ARGV)
13
+ #
14
+ # =========================================================================== #
15
+ # require 'extracter/extract_it/extract_it.rb'
16
+ # =========================================================================== #
17
+ module Extracter
18
+
19
+ class ExtractIt # === Extracter::ExtractIt
20
+
21
+ begin
22
+ require 'opn'
23
+ rescue LoadError; end
24
+
25
+ begin
26
+ require 'remove_file_suffix'
27
+ rescue LoadError; end
28
+
29
+ begin
30
+ require 'colours'
31
+ include Colours if Object.const_defined? :Colours
32
+ rescue LoadError; end
33
+
34
+ require 'extracter/extracter.rb'
35
+
36
+ # ========================================================================= #
37
+ # === NAMESPACE
38
+ # ========================================================================= #
39
+ NAMESPACE = inspect
40
+
41
+ # ========================================================================= #
42
+ # === ExtractIt::ARRAY_ARCHIVE_TYPES
43
+ #
44
+ # Register the available (and handled) archive types here.
45
+ # ========================================================================= #
46
+ ARRAY_ARCHIVE_TYPES = %w(
47
+ .apkg
48
+ .xz
49
+ .zip
50
+ .tar
51
+ .bz2
52
+ .7z
53
+ )
54
+
55
+ # ========================================================================= #
56
+ # === initialize
57
+ # ========================================================================= #
58
+ def initialize(
59
+ optional_set_input = nil,
60
+ run_already = true
61
+ )
62
+ reset
63
+ set_input(optional_set_input)
64
+ run if run_already
65
+ end
66
+
67
+ # ========================================================================= #
68
+ # === reset (reset tag)
69
+ # ========================================================================= #
70
+ def reset
71
+ @debug = false
72
+ end
73
+
74
+ # ========================================================================= #
75
+ # === set_input
76
+ #
77
+ # We will work on an Array as value to @input, at the end of this
78
+ # method.
79
+ # ========================================================================= #
80
+ def set_input(i = N)
81
+ case i
82
+ # ======================================================================= #
83
+ # === extract_it --help
84
+ # ======================================================================= #
85
+ when /-?-?help$/i # Show some help stuff here.
86
+ e 'We will show a little bit help, then exit.'
87
+ e
88
+ e 'To extract .tar.xz, do:'
89
+ e
90
+ efancy ' -> tar -xJf *.tar.xz'
91
+ exit
92
+ end
93
+ i = [i] if i.is_a? String # Need an Array.
94
+ if @debug
95
+ opn; e 'The input given to us is: `'+sfile(i)+'`'
96
+ end
97
+ if i.is_a?(Array) and i.empty?
98
+ # ===================================================================== #
99
+ # In this case, try to see if the current directory has a .zip
100
+ # file. We will use this in that case.
101
+ # ===================================================================== #
102
+ is_there_a_zip_file = Dir['*.zip']
103
+ unless is_there_a_zip_file.empty?
104
+ use_this_zip_file = is_there_a_zip_file.first
105
+ notify_the_user_that_no_input_was_given_but_this_file_was_found(use_this_zip_file)
106
+ i << use_this_zip_file
107
+ end
108
+ is_there_at_the_least_one_tar_xz_file = Dir['*.tar.xz']
109
+ unless is_there_at_the_least_one_tar_xz_file.empty?
110
+ i << is_there_at_the_least_one_tar_xz_file.first
111
+ end
112
+ end
113
+ @input = i # Should be an array, always.
114
+ end
115
+
116
+ # ========================================================================= #
117
+ # === be_silent
118
+ # ========================================================================= #
119
+ def be_silent
120
+ @be_silent = true
121
+ end
122
+
123
+ # ========================================================================= #
124
+ # === be_verbose
125
+ # ========================================================================= #
126
+ def be_verbose
127
+ @be_silent = false
128
+ end; alias show_commands_used be_verbose # === show_commands_used
129
+
130
+ # ========================================================================= #
131
+ # === notify_the_user_that_no_input_was_given_but_this_file_was_found
132
+ # ========================================================================= #
133
+ def notify_the_user_that_no_input_was_given_but_this_file_was_found(
134
+ this_file
135
+ )
136
+ opn; e 'No input was given to '+sfancy(NAMESPACE)+' but a '\
137
+ '.zip file was'
138
+ opn; e 'found in this directory ('+sdir(Dir.pwd)+'): '+
139
+ sfancy(this_file)
140
+ opn; e 'We will use this zip file.'
141
+ end
142
+
143
+ # ========================================================================= #
144
+ # === extract_input
145
+ # ========================================================================= #
146
+ def extract_input
147
+ pp @input if @debug
148
+ @input.each {|entry|
149
+ to_this_dir = Dir.pwd
150
+ to_this_dir << '/' unless to_this_dir.end_with? '/'
151
+ unless File.exist? entry
152
+ entry = try_to_glob_on(entry)
153
+ end
154
+ # ===================================================================== #
155
+ # Delegate to class Extracter next.
156
+ # ===================================================================== #
157
+ Extracter.extract_what_to(
158
+ entry,
159
+ to_this_dir,
160
+ @be_silent
161
+ )
162
+ _ = RemoveFileSuffix[entry]
163
+ if File.exist? entry
164
+ # =================================================================== #
165
+ # Must also check whether the extracted directory exists.
166
+ # =================================================================== #
167
+ name_of_the_extracted_archive = to_this_dir+_
168
+ ARRAY_ARCHIVE_TYPES.each {|extension_name|
169
+ if name_of_the_extracted_archive.include? extension_name
170
+ quoted = Regexp.quote(extension_name)
171
+ name_of_the_extracted_archive.sub!(/#{quoted}$/,'')
172
+ end
173
+ }
174
+ if File.exist?(name_of_the_extracted_archive) and
175
+ # ================================================================= #
176
+ # The following check ensures that we really have another name
177
+ # for the extracted directory.
178
+ # ================================================================= #
179
+ !(entry == name_of_the_extracted_archive)
180
+ opn; e "Finished extracting #{sfile(_)} to `#{sdir(to_this_dir)}`."
181
+ else
182
+ opn; e "No file called `#{sfile(name_of_the_extracted_archive)}"\
183
+ "` appears to exist."
184
+ end
185
+ end
186
+ }
187
+ end
188
+
189
+ # ========================================================================= #
190
+ # === is_archive?
191
+ # ========================================================================= #
192
+ def is_archive?(i)
193
+ ARRAY_ARCHIVE_TYPES.include?(
194
+ File.extname(File.basename(i))
195
+ )
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === try_to_glob_on
200
+ # ========================================================================= #
201
+ def try_to_glob_on(i)
202
+ result = Dir["#{i}*"]
203
+ # ======================================================================= #
204
+ # Next, sort this result to put archives on the beginning of the Array.
205
+ # ======================================================================= #
206
+ result = result.partition {|entry| is_archive?(entry) }
207
+ result.flatten!
208
+ unless result.empty?
209
+ # ===================================================================== #
210
+ # Ok, we grab the first entry next.
211
+ # ===================================================================== #
212
+ i = result.first
213
+ opn; e "No result could be found for the given input, thus "\
214
+ "using #{sfancy(i)} instead."
215
+ end
216
+ i
217
+ end
218
+
219
+ # ========================================================================= #
220
+ # === run (run tag)
221
+ # ========================================================================= #
222
+ def run
223
+ extract_input
224
+ end
225
+
226
+ # ========================================================================= #
227
+ # === Extracter::ExtractIt[]
228
+ # ========================================================================= #
229
+ def self.[](i = '')
230
+ new(i)
231
+ end
232
+
233
+ end; end
234
+
235
+ if __FILE__ == $PROGRAM_NAME
236
+ Extracter::ExtractIt.new(ARGV)
237
+ end # extract_it.rb
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Extracter
6
+ #
7
+ # The purpose of this class is to abstract extracting source files to
8
+ # a target location. You just pass the argument of the file that has
9
+ # to be extracted to this class, and it should handle the rest.
10
+ #
11
+ # We can also "extract" Audio files, by calling the module ExtractAudio.
12
+ # You can try this - just pass a .mp4 file as first argument to
13
+ # this class.
14
+ #
15
+ # Usage examples for class Extracter:
16
+ #
17
+ # Extracter.new('foo.mp3')
18
+ # Extracter.new('xyz-1.0.tar.gz')
19
+ #
20
+ # Usage example:
21
+ #
22
+ # Extracter.new
23
+ #
24
+ # =========================================================================== #
25
+ # require 'extracter/extracter.rb'
26
+ # =========================================================================== #
27
+
28
+ # =========================================================================== #
29
+ # Next, load up .rb files that belong to extracter/.
30
+ # =========================================================================== #
31
+ require 'extracter/version/version.rb'
32
+ require 'extracter/constants/constants.rb'
33
+ require 'extracter/class_methods.rb'
34
+ require 'extracter/colours.rb'
35
+ require 'extracter/do_extract_what_to.rb'
36
+ require 'extracter/help.rb'
37
+ require 'extracter/initialize.rb'
38
+ require 'extracter/misc.rb'
39
+ require 'extracter/reset.rb'
40
+ require 'extracter/opn.rb'
41
+
42
+ module Extracter
43
+
44
+ class Extracter # === Extracter
45
+ end
46
+
47
+ end
48
+
49
+ if __FILE__ == $PROGRAM_NAME
50
+ # The second argument to Extracter.new is where we will
51
+ # extract to.
52
+ if ARGV.size > 2
53
+ _ = Extracter::Extracter.new(ARGV, :default, false)
54
+ else
55
+ _ = Extracter::Extracter.new(ARGV[0], ARGV[1], false)
56
+ end
57
+ _.extract_to Dir.pwd unless ARGV[1]
58
+ # _.enable_debug
59
+ _.be_verbose
60
+ _.run
61
+ end # extracter
62
+ # extracter htop-1.0.2.tar.xz
63
+ # extracter xfig-3.2.5.tar.bz2
64
+ # extract htop* /Depot/
65
+ # extract recode-3.7.tar.xz /Depot/
66
+ # extract qt-4.8.6.tar.xz --to=/home/Temp
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module Extracter
6
+
7
+ class Extracter
8
+
9
+ # ========================================================================= #
10
+ # === show_help (help tag)
11
+ #
12
+ # This method will show the available - and documented - help options
13
+ # for class Extracter.
14
+ # ========================================================================= #
15
+ def show_help
16
+ e
17
+ opnn; e 'How to extract archives, without helper scripts?'
18
+ e
19
+ opnn; e ' tar -zxvf foobar.tar.gz # for .tar.gz'
20
+ opnn; e ' tar xvzf foobar.tgz # for .tgz'
21
+ opnn; e ' tar xvfJ foobar.tar.xz # for .tar.xz'
22
+ opnn; e ' tar jxf foobar.tar.bz2 # for .tar.bz2'
23
+ opnn; e ' tar -xf foobar.tar.bz2 # for .tbz'
24
+ opnn; e ' tar --lzip -xvf zutils-1.5.tar.lz # for .tar.lz'
25
+ opnn; e ' unsquashfs foobar-1.2.3.sxz # for .sxz'
26
+ e
27
+ opnn; e 'Furthermore, there are some commandline options '\
28
+ 'that can be used for this class (class Extracter).'
29
+ e
30
+ opnn; e ' --to=/home/Temp # extract into the '\
31
+ 'directory /home/Temp/'
32
+ e
33
+ end
34
+
35
+ end; end
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'extracter/initialize.rb'
6
+ # =========================================================================== #
7
+ module Extracter
8
+
9
+ class Extracter
10
+
11
+ # ========================================================================= #
12
+ # === initialize
13
+ #
14
+ # The first argument to this method is the archive that should be extracted.
15
+ # This must be a (locally) existing archive, such as foobar.tar.xz or
16
+ # something similar.
17
+ #
18
+ # The second argument to this method, called `to`, specifies the target
19
+ # location, where this class will extract the archive into, if available.
20
+ # Some keywords and shortcuts exist for this option - for instance, TEMP
21
+ # means $MY_TEMP, which can be set by the user.
22
+ #
23
+ # Specific usage example in pure Ruby:
24
+ #
25
+ # x = Extracter.what_to('pry-0.9.9.4.gem', '/Depot/Temp')
26
+ #
27
+ # ========================================================================= #
28
+ def initialize(
29
+ what = nil,
30
+ where_to = nil, # Where to extract into.
31
+ run_already = true
32
+ )
33
+ register_sigint
34
+ reset
35
+ if where_to.is_a? Symbol
36
+ if where_to.to_s.include? 'dont' # This also covers :dont_run_yet
37
+ where_to = nil # This is ok because we expect the user to provide the target location.
38
+ run_already = false
39
+ end
40
+ end
41
+ if debug? # Some debug-information.
42
+ e "The first argument what is: `#{what}`"
43
+ e "The second argument to is: `#{to}`"
44
+ end
45
+ set_source_location(what)
46
+ set_extract_to(where_to)
47
+ # ======================================================================= #
48
+ # === Handle blocks next
49
+ # ======================================================================= #
50
+ if block_given?
51
+ yielded = yield
52
+ # ===================================================================== #
53
+ # === Handle Hash input next:
54
+ # ===================================================================== #
55
+ if yielded.is_a? Hash
56
+ if yielded.has_key? :run_already
57
+ run_already = yielded.delete(:run_already)
58
+ end
59
+ # =================================================================== #
60
+ # === :use_colours
61
+ # =================================================================== #
62
+ if yielded.has_key? :use_colours
63
+ set_use_colours yielded.delete(:use_colours)
64
+ end
65
+ if yielded.has_key? :extract_to
66
+ set_extract_to yielded.delete(:extract_to)
67
+ end
68
+ if yielded.has_key? :run_simulation
69
+ set_run_simulation(yielded.delete(:run_simulation))
70
+ end
71
+ if yielded.has_key? :use_opn
72
+ set_use_opn(yielded.delete(:use_opn))
73
+ end
74
+ else
75
+ case yielded
76
+ when :dont_run_yet,
77
+ :do_not_run_yet
78
+ run_already = false
79
+ end
80
+ end
81
+ end
82
+ case run_already
83
+ when :dont_run_yet,
84
+ :do_not_run_yet
85
+ run_already = false
86
+ end
87
+ run if run_already
88
+ end
89
+
90
+ end; end
@@ -0,0 +1,430 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'extracter/misc.rb'
6
+ # =========================================================================== #
7
+ module Extracter
8
+
9
+ class Extracter # === Extracter
10
+
11
+ require 'fileutils'
12
+
13
+ begin
14
+ require 'multimedia_paradise/audio/extract_audio/extract_audio.rb'
15
+ rescue LoadError; end
16
+
17
+ begin
18
+ require 'remove_file_suffix'
19
+ rescue LoadError; end
20
+
21
+ # ========================================================================= #
22
+ # Shall we run in simulation mode or not.
23
+ # ========================================================================= #
24
+ attr_accessor :run_simulation
25
+
26
+ # ========================================================================= #
27
+ # === debug?
28
+ # ========================================================================= #
29
+ def debug?
30
+ @debug
31
+ end
32
+
33
+ # ========================================================================= #
34
+ # === enable_debug
35
+ # ========================================================================= #
36
+ def enable_debug
37
+ @debug = true
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === do_not_show_name
42
+ #
43
+ # Tells us whether to use opn() or not.
44
+ # ========================================================================= #
45
+ def do_not_show_name
46
+ @do_not_show_name = true
47
+ end
48
+
49
+ # ========================================================================= #
50
+ # === do_show_name
51
+ #
52
+ # If this is enabled, we will show the name of the file when we invoke
53
+ # copn().
54
+ # ========================================================================= #
55
+ def do_show_name
56
+ @do_not_show_name = false
57
+ end
58
+
59
+ # ========================================================================= #
60
+ # === sanitize_input
61
+ # ========================================================================= #
62
+ def sanitize_input(i)
63
+ if i.include? '('
64
+ i.gsub!(/\(/,'\(')
65
+ i.gsub!(/\)/,'\)') if i.include? ')'
66
+ i = pad(i, '"')
67
+ end
68
+ return i
69
+ end
70
+
71
+ # ========================================================================= #
72
+ # === check_whether_rar_is_available
73
+ #
74
+ # We try to find out whether unrar is available.
75
+ # ========================================================================= #
76
+ def check_whether_rar_is_available
77
+ is_available = false
78
+ ENV['PATH'].split(':').each {|entry|
79
+ is_available = true if File.exist? entry+'/unrar'
80
+ }
81
+ unless is_available
82
+ copn; e 'Sorry, unrar is not available. Please install it first.'
83
+ end
84
+ end
85
+
86
+ # ========================================================================= #
87
+ # === run_simulation?
88
+ # ========================================================================= #
89
+ def run_simulation?
90
+ @run_simulation
91
+ end
92
+
93
+ # ========================================================================= #
94
+ # === set_run_simulation
95
+ # ========================================================================= #
96
+ def set_run_simulation(i)
97
+ @run_simulation = i
98
+ end
99
+
100
+ # ========================================================================= #
101
+ # === pad
102
+ # ========================================================================= #
103
+ def pad(i, with_this_character = "'")
104
+ return with_this_character+i+with_this_character
105
+ end
106
+
107
+ # ========================================================================= #
108
+ # === extract_to?
109
+ #
110
+ # Simply output the result of @extract_to_this_location variable.
111
+ # ========================================================================= #
112
+ def extract_to?
113
+ @extract_to_this_location.to_s
114
+ end; alias source_package_location extract_to? # === source_package
115
+
116
+ # ========================================================================= #
117
+ # === set_source_location
118
+ #
119
+ # Use this method to designate the source location of a given (input)
120
+ # program. In other words - the tarball or archive that must be
121
+ # extracted. It will however be stored as Array.
122
+ #
123
+ # If we pass a hash to this method, we assume that the user wants
124
+ # to also populate some other values.
125
+ # ========================================================================= #
126
+ def set_source_location(i = nil)
127
+ if i.nil?
128
+ copn; e 'You should set a file.'
129
+ end
130
+ if i.is_a? Array
131
+ i = i.flatten
132
+ else
133
+ i = [i]
134
+ end # After this point, we will have an Array.
135
+ case i.first # case tag
136
+ when /^-?-?help$/i
137
+ show_help
138
+ exit
139
+ end
140
+ i.map! {|entry| # Iterate over our Array next.
141
+ # ======================================================================= #
142
+ # Handle the case when the user did input a number.
143
+ # ======================================================================= #
144
+ begin
145
+ if entry =~ /^\d$/
146
+ entry = Dir['*'][( entry.to_i - 1 )] unless File.exist?(entry)
147
+ end
148
+ rescue ArgumentError => error
149
+ e 'Error for '+sfancy(entry)+':'
150
+ pp error
151
+ end
152
+ entry = rds(entry.to_s)
153
+ # ======================================================================= #
154
+ # Next, find the proper working directory.
155
+ # ======================================================================= #
156
+ unless entry.include? '/'
157
+ entry = rds( (Dir.pwd+'/'+entry) )
158
+ end
159
+ # ======================================================================= #
160
+ # If the user supplied a directory instead, we will randomly grab an
161
+ # entry from said directory.
162
+ # ======================================================================= #
163
+ if File.directory? entry
164
+ entry = Dir[rds(entry+'/')+'*'].sample
165
+ end
166
+ entry
167
+ } # Sanitize the result, just in case.
168
+ i = [i] unless i.is_a? Array # Much more convenient to work with an array.
169
+ @source_location = i
170
+ end; alias set_what set_source_location # === set_what
171
+
172
+ # ========================================================================= #
173
+ # === source_location?
174
+ # ========================================================================= #
175
+ def source_location?
176
+ @source_location.first
177
+ end; alias input? source_location? # === input?
178
+
179
+ # ========================================================================= #
180
+ # === did_we_extract_already?
181
+ #
182
+ # Whether we already did extract or whether we did not.
183
+ # ========================================================================= #
184
+ def did_we_extract_already?
185
+ @did_we_extract_already
186
+ end; alias did_we_extract_already did_we_extract_already? # === did_we_extract_already
187
+
188
+ # ========================================================================= #
189
+ # === extract_to_this_location?
190
+ #
191
+ # Extract to this location.
192
+ # ========================================================================= #
193
+ def extract_to_this_location?
194
+ @extract_to_this_location
195
+ end; alias extract_to_this_location extract_to_this_location? # === extract_to_this_location
196
+
197
+ # ========================================================================= #
198
+ # === extracted_to?
199
+ #
200
+ # This method is different from extract_to?.
201
+ #
202
+ # It will keep track of the directory to where we extracted to
203
+ # exactly.
204
+ # ========================================================================= #
205
+ def extracted_to?
206
+ rds(
207
+ extract_to?+
208
+ File.basename(input?).sub(/\.xz$/,'').sub(/\.gz$/,'').
209
+ sub(/\.tar$/,'')+'/'
210
+ )
211
+ end; alias extracted_path? extracted_to? # === extracted_path?
212
+
213
+ # ========================================================================= #
214
+ # === namespace?
215
+ # ========================================================================= #
216
+ def namespace?
217
+ @namespace
218
+ end
219
+
220
+ # ========================================================================= #
221
+ # === set_extract_to_this_location
222
+ #
223
+ # Use this when setting the variable @extract_to_this_location.
224
+ #
225
+ # This can be modified from the commandline such as by doing this:
226
+ # ========================================================================= #
227
+ def set_extract_to_this_location(
228
+ i = TEMP_DIR
229
+ )
230
+ if i.is_a? Hash
231
+ if i.has_key? :to
232
+ i = i.delete :to
233
+ elsif i.has_key? :extract_to
234
+ i = i.delete :extract_to
235
+ end
236
+ end
237
+ case i # case tag
238
+ when :default
239
+ i = Dir.pwd
240
+ when 'TEMP',
241
+ 'MY_TEMP',
242
+ 'MYTEMP'
243
+ i = TEMP_DIR
244
+ end
245
+ i = TEMP_DIR if i.nil?
246
+ i = i.to_s.dup
247
+ i << '/' unless i.end_with? '/'
248
+ i = rds(i)
249
+ i.gsub!(/--to=/,'') if i.include? '--to='
250
+ @extract_to_this_location = i
251
+ end; alias set_extract_to set_extract_to_this_location # === set_extract_to
252
+ alias extract_to= set_extract_to_this_location # === extract_to=
253
+ alias extract_to set_extract_to_this_location # === extract_to
254
+
255
+ # ========================================================================= #
256
+ # === run_this_system_command
257
+ # ========================================================================= #
258
+ def run_this_system_command(
259
+ i, instruction = :do_nothing_special
260
+ )
261
+ if instruction == :also_show_what_we_will_do
262
+ copn; e i
263
+ end
264
+ return `#{i}` # system tag
265
+ end
266
+
267
+ # ========================================================================= #
268
+ # === prefix_namespace_with
269
+ # ========================================================================= #
270
+ def prefix_namespace_with(i)
271
+ @namespace = "#{i}#{@namespace.dup}"
272
+ update_the_opn_hash # Also update the opn-hash here.
273
+ end
274
+
275
+ # ========================================================================= #
276
+ # === report_to_the_user
277
+ #
278
+ # This method reports to the user. Usually this is done only via this
279
+ # file here though.
280
+ # ========================================================================= #
281
+ def report_to_the_user
282
+ if @be_verbose
283
+ unless @skip_extracting
284
+ copn; e 'Finished extracting to `'+sdir(
285
+ extract_to?+remove_file_extension(
286
+ @source_location.first # This is an Array.
287
+ )+'/'
288
+ )+'`.'
289
+ end
290
+ end
291
+ end
292
+
293
+ # ========================================================================= #
294
+ # === be_verbose?
295
+ #
296
+ # Getter method for whether we will be verbose or not.
297
+ # ========================================================================= #
298
+ def be_verbose?
299
+ @be_verbose
300
+ end
301
+
302
+ # ========================================================================= #
303
+ # === be_verbose
304
+ # ========================================================================= #
305
+ def be_verbose
306
+ set_be_verbose(true)
307
+ end
308
+
309
+ # ========================================================================= #
310
+ # === be_silent
311
+ # ========================================================================= #
312
+ def be_silent
313
+ set_be_verbose(false)
314
+ end
315
+
316
+ # ========================================================================= #
317
+ # === set_be_verbose
318
+ #
319
+ # This sets the verbosity level of the class. Use only this method
320
+ # when you wish to modify the @be_verbose instance variable.
321
+ # ========================================================================= #
322
+ def set_be_verbose(i = false)
323
+ @be_verbose = i
324
+ end; alias set_verbosity set_be_verbose # === set_verbosity
325
+
326
+ # ========================================================================= #
327
+ # === determine_default_opn_hash
328
+ # ========================================================================= #
329
+ def determine_default_opn_hash
330
+ @use_this_opn_hash = {
331
+ namespace: namespace?,
332
+ use_colours: use_colours?
333
+ }
334
+ end; alias update_the_opn_hash determine_default_opn_hash # === update_the_opn_hash
335
+
336
+ # ========================================================================= #
337
+ # === register_sigint
338
+ # ========================================================================= #
339
+ def register_sigint
340
+ Signal.trap('SIGINT') {
341
+ e sfancy('Requesting a graceful exit from ')+
342
+ colour_to_use_for_directories?+
343
+ 'class Extracter'+
344
+ sfancy('. Exiting now.')
345
+ exit
346
+ }
347
+ end
348
+
349
+ # ========================================================================= #
350
+ # === create_directory
351
+ #
352
+ # Use this to create directories.
353
+ # ========================================================================= #
354
+ def create_directory(i)
355
+ FileUtils.mkdir_p(i)
356
+ end; alias mkdir create_directory # === mkdir
357
+
358
+ # ========================================================================= #
359
+ # === remove_file_extension
360
+ # ========================================================================= #
361
+ def remove_file_extension(i)
362
+ _ = File.basename(i)
363
+ return RemoveFileSuffix[_]
364
+ end
365
+
366
+ # ========================================================================= #
367
+ # === rds
368
+ # ========================================================================= #
369
+ def rds(i)
370
+ i.squeeze('/')
371
+ end
372
+
373
+ # ========================================================================= #
374
+ # === esystem
375
+ # ========================================================================= #
376
+ def esystem(i)
377
+ e i
378
+ system i
379
+ end
380
+
381
+ # ========================================================================= #
382
+ # === e
383
+ # ========================================================================= #
384
+ def e(i = '')
385
+ puts i
386
+ end
387
+
388
+ # ========================================================================= #
389
+ # === do_show_the_full_name_of_the_archive
390
+ # ========================================================================= #
391
+ def do_show_the_full_name_of_the_archive
392
+ @show_only_the_short_name_of_the_archive = false
393
+ end
394
+
395
+ # ========================================================================= #
396
+ # === fail_message_not_registered
397
+ #
398
+ # Output a fail message when the archive format is not registered.
399
+ # ========================================================================= #
400
+ def fail_message_not_registered(i)
401
+ copn; e "Can not extract `#{sfancy(i)}` - it is not "\
402
+ "registered."
403
+ end
404
+
405
+ # ========================================================================= #
406
+ # === work_on_the_given_input
407
+ # ========================================================================= #
408
+ def work_on_the_given_input
409
+ if @source_location.empty?
410
+ copn; e 'Can not extract anything as no input has been given.'
411
+ else
412
+ @source_location.each {|entry|
413
+ if Extracter.is_this_a_valid_archive?(entry)
414
+ do_extract_what_to(entry)
415
+ report_to_the_user
416
+ else
417
+ fail_message_not_registered(entry)
418
+ end
419
+ }
420
+ end
421
+ end
422
+
423
+ # ========================================================================= #
424
+ # === run (run tag, def tag)
425
+ # ========================================================================= #
426
+ def run
427
+ work_on_the_given_input
428
+ end
429
+
430
+ end; end