Class: Extracter::Extracter
- Inherits:
-
Base
- Object
- Base
- Extracter::Extracter
show all
- Defined in:
- lib/extracter/class/extracter.rb,
lib/extracter/class/extract_this_archive.rb
Overview
Constant Summary
collapse
- NAMESPACE =
inspect
- SHOW_ONLY_THE_SHORT_NAME_OF_THE_ARCHIVE =
#
SHOW_ONLY_THE_SHORT_NAME_OF_THE_ARCHIVE
If this constant is set to true then we will only show the shortened name of the archive in question by default.
#
true
Class Method Summary
collapse
Instance Method Summary
collapse
-
#be_verbose ⇒ Object
# === be_verbose ========================================================================= #.
-
#be_verbose? ⇒ Boolean
# === be_verbose?.
-
#check_whether_rar_is_available ⇒ Object
# === check_whether_rar_is_available.
-
#colour_to_use_for_directories? ⇒ Boolean
# === colour_to_use_for_directories? ========================================================================= #.
-
#commandline_arguments? ⇒ Boolean
# === commandline_arguments? ========================================================================= #.
-
#consider_verbosity_for(i) ⇒ Object
# === consider_verbosity_for ========================================================================= #.
-
#create_directory(i) ⇒ Object
(also: #mkdir)
# === create_directory (mkdir tag).
-
#debug? ⇒ Boolean
# === debug? ========================================================================= #.
-
#disable_colours ⇒ Object
# === disable_colours.
-
#do_be_quiet ⇒ Object
(also: #be_silent, #be_quiet)
# === do_be_quiet ========================================================================= #.
-
#do_not_show_name ⇒ Object
# === do_not_show_name.
-
#do_show_name ⇒ Object
# === do_show_name.
-
#do_show_the_full_name_of_the_archive ⇒ Object
# === do_show_the_full_name_of_the_archive ========================================================================= #.
-
#enable_colours ⇒ Object
# === enable_colours ========================================================================= #.
-
#enable_debug ⇒ Object
# === enable_debug ========================================================================= #.
-
#esystem(i, try_to_use_colours = try_to_use_colours? ) ⇒ Object
(also: #run_this_system_command)
# === esystem (system tag, esystem tag) ========================================================================= #.
-
#extract_this_archive(i, extract_to = extract_to? ) ⇒ Object
(also: #do_extract_to, #do_extract_what_to, #start)
-
#extract_to? ⇒ Boolean
(also: #source_package_location, #extract_to_this_location?, #extracted_to?, #extracted_path?)
-
#fail_message_not_registered(i) ⇒ Object
# === fail_message_not_registered.
-
#first_argument? ⇒ Boolean
(also: #first?)
# === first_argument? ========================================================================= #.
-
#initialize(commandline_arguments = ARGV, extract_to = nil, run_already = true, &block) ⇒ Extracter
constructor
# === initialize.
-
#menu(i = commandline_arguments? ) ⇒ Object
-
#namespace? ⇒ Boolean
# === namespace? ========================================================================= #.
-
#notify_the_user_that_this_extension_has_not_been_registered_yet(i) ⇒ Object
# === notify_the_user_that_this_extension_has_not_been_registered_yet ========================================================================= #.
-
#opnn(use_this_hash = use_this_opn_hash? ) ⇒ Object
(also: #opn, #copn)
# === opnn.
-
#pad(i, with_this_character = "'") ⇒ Object
# === pad (pad tag).
-
#pad_opn_with_n_tokens(n_tokens = nil) ⇒ Object
(also: #set_pad_opn_with_n_tokens)
# === pad_opn_with_n_tokens ========================================================================= #.
-
#padded_extract_to? ⇒ Boolean
-
#prefix_namespace_with(i) ⇒ Object
# === prefix_namespace_with ========================================================================= #.
-
#prepare_the_hash_for_opn(use_this_hash = { namespace: namespace?, use_colours: use_colours? }) ⇒ Object
(also: #update_the_opn_hash, #determine_default_opn_hash, #determine_the_default_opn_hash, #update_the_main_hash)
# === prepare_the_hash_for_opn ========================================================================= #.
-
#rds(i) ⇒ Object
# === rds ========================================================================= #.
-
#register_sigint ⇒ Object
# === register_sigint ========================================================================= #.
-
#remove_file_extension(i) ⇒ Object
(also: #remove_extension, #remove_ext)
# === remove_file_extension ========================================================================= #.
-
#report_to_the_user(i, extract_to = extract_to? ) ⇒ Object
# === report_to_the_user.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_pwd ⇒ Object
# === return_pwd ========================================================================= #.
-
#run ⇒ Object
# === run (run tag, def tag) ========================================================================= #.
-
#run_already? ⇒ Boolean
# === run_already? ========================================================================= #.
-
#run_simulation=(i) ⇒ Object
# === run_simulation= ========================================================================= #.
-
#run_simulation? ⇒ Boolean
# === run_simulation? ========================================================================= #.
-
#set_be_verbose(i = false) ⇒ Object
(also: #set_verbosity)
# === set_be_verbose.
-
#set_colour_for_directories(i) ⇒ Object
# === set_colour_for_directories.
-
#set_commandline_arguments(i = '') ⇒ Object
# === set_commandline_arguments ========================================================================= #.
-
#set_extract_to(i = :temp_dir) ⇒ Object
(also: #set_extract_to_this_location, #extract_to=, #extract_to)
-
#set_run_simulation(i = false) ⇒ Object
# === set_run_simulation ========================================================================= #.
-
#set_use_colours(i) ⇒ Object
# === set_use_colours ========================================================================= #.
-
#set_use_opn(i = true) ⇒ Object
# === set_use_opn ========================================================================= #.
-
#show_help ⇒ Object
# === show_help (help tag).
-
#show_only_the_short_name_of_the_archive? ⇒ Boolean
# === show_only_the_short_name_of_the_archive? ========================================================================= #.
-
#show_the_name? ⇒ Boolean
# === show_the_name? ========================================================================= #.
-
#strip_components(by_n = 1) ⇒ Object
# === strip_components.
-
#try_to_extract_this_img_file(i) ⇒ Object
-
#try_to_extract_this_iso_file(i) ⇒ Object
-
#try_to_use_colours? ⇒ Boolean
# === try_to_use_colours? ========================================================================= #.
-
#use_opn? ⇒ Boolean
# === use_opn? ========================================================================= #.
-
#use_this_opn_hash? ⇒ Boolean
(also: #main_hash?)
# === use_this_opn_hash? ========================================================================= #.
-
#work_on_the_given_input(array = commandline_arguments?, , extract_to = extract_to? ) ⇒ Object
Methods inherited from Base
#change_directory, #check_whether_the_colours_gem_is_available, #cpr, #cyan?, #e, #ewarn, #move, #remove_this_directory, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato, #use_colours?
Constructor Details
#initialize(commandline_arguments = ARGV, extract_to = nil, run_already = true, &block) ⇒ Extracter
#
initialize
The first argument to this method should be the archive that the user wants to extract. This must be a (locally) existing archive, such as foobar.tar.xz or something similar.
The second argument to this method, called ‘extract_to`, specifies the target location, where this class will extract the archive into, if available. Some keywords and shortcuts exist for this option - for instance, TEMP means $MY_TEMP, which can be set by the user.
Specific usage example in pure Ruby:
x = Extracter.what_to('pry-0.9.9.4.gem', '/home/Temp')
#
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
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/extracter/class/extracter.rb', line 71
def initialize(
commandline_arguments = ARGV,
= nil,
run_already = true,
&block
)
register_sigint
reset
@internal_hash[:run_already] = run_already
set_commandline_arguments(
commandline_arguments
)
if debug? e "The first argument what is: `#{commandline_arguments}`"
e "The second argument where_to is: `#{}`"
end
case run_already
when :dont_run_yet,
:do_not_run_yet,
:default
@internal_hash[:run_already] = false
end
() if
if block_given?
yielded = yield
case yielded
when :be_silent,
:be_quiet
do_be_quiet
when :dont_run_yet,
:do_not_run_yet,
:default
@internal_hash[:run_already] = false
when :show_the_full_name_of_the_archive
do_show_the_full_name_of_the_archive
end
end
run if run_already?
end
|
Class Method Details
.[](i = ARGV, extract_where_to = Dir.pwd) ⇒ Object
1016
1017
1018
|
# File 'lib/extracter/class/extracter.rb', line 1016
def self.[](i = ARGV, = Dir.pwd)
new(i, )
end
|
#
This method provides a convenient API to extract something to a specified directory, as a class method. It defaults to the current working directory, as that is by far the most convenient way to extract a source tarball/archive.
#
1003
1004
1005
1006
1007
1008
1009
|
# File 'lib/extracter/class/extracter.rb', line 1003
def self.(
i = ARGV,
to = {}, &block
)
::Extracter::Extracter.new(ARGV, to, &block)
end
|
Instance Method Details
#be_verbose ⇒ Object
974
975
976
|
# File 'lib/extracter/class/extracter.rb', line 974
def be_verbose
set_be_verbose(true)
end
|
#be_verbose? ⇒ Boolean
#
be_verbose?
Getter method for whether we will be verbose or not.
#
418
419
420
|
# File 'lib/extracter/class/extracter.rb', line 418
def be_verbose?
@internal_hash[:be_verbose]
end
|
#check_whether_rar_is_available ⇒ Object
#
check_whether_rar_is_available
We try to find out whether unrar is available.
#
218
219
220
221
222
223
224
225
226
|
# File 'lib/extracter/class/extracter.rb', line 218
def check_whether_rar_is_available
is_available = false
ENV['PATH'].split(':').each {|entry|
is_available = true if File.exist? "#{entry}/unrar"
}
unless is_available
copn; e 'Sorry, unrar is not available. Please install it first.'
end
end
|
#colour_to_use_for_directories? ⇒ Boolean
#
colour_to_use_for_directories?
#
438
439
440
441
442
443
444
|
# File 'lib/extracter/class/extracter.rb', line 438
def colour_to_use_for_directories?
if use_colours?
return @internal_hash[:colour_to_use_for_directories]
else
return ''
end
end
|
#commandline_arguments? ⇒ Boolean
#
commandline_arguments?
#
281
282
283
|
# File 'lib/extracter/class/extracter.rb', line 281
def commandline_arguments?
@commandline_arguments
end
|
#consider_verbosity_for(i) ⇒ Object
#
consider_verbosity_for
#
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/extracter/class/extract_this_archive.rb', line 16
def consider_verbosity_for(i)
i = i.dup
unless be_verbose?
case i
when COMMAND_TO_EXTRACT_TAR_XZ_FILES
i.delete!('v')
end
end
return i
end
|
#create_directory(i) ⇒ Object
Also known as:
mkdir
#
create_directory (mkdir tag)
Use this to create directories.
#
834
835
836
|
# File 'lib/extracter/class/extracter.rb', line 834
def create_directory(i)
FileUtils.mkdir_p(i) unless File.directory?(i)
end
|
#debug? ⇒ Boolean
231
232
233
|
# File 'lib/extracter/class/extracter.rb', line 231
def debug?
@internal_hash[:debug]
end
|
#disable_colours ⇒ Object
#
disable_colours
Use this method if you want to disable colour-support of this class.
#
554
555
556
557
|
# File 'lib/extracter/class/extracter.rb', line 554
def disable_colours
set_use_colours(false)
@internal_hash[:colour_to_use_for_directories] = ''.dup
end
|
#do_be_quiet ⇒ Object
Also known as:
be_silent, be_quiet
981
982
983
|
# File 'lib/extracter/class/extracter.rb', line 981
def do_be_quiet
set_be_verbose(false)
end
|
#do_not_show_name ⇒ Object
#
do_not_show_name
Tells us whether to use opn() or not.
#
202
203
204
|
# File 'lib/extracter/class/extracter.rb', line 202
def do_not_show_name
@internal_hash[:show_the_name] = false
end
|
#do_show_name ⇒ Object
#
do_show_name
If this method is called then the class here will show the name of the file on the commandline, via opn().
#
537
538
539
|
# File 'lib/extracter/class/extracter.rb', line 537
def do_show_name
@internal_hash[:show_the_name] = true
end
|
#do_show_the_full_name_of_the_archive ⇒ Object
#
do_show_the_full_name_of_the_archive
#
449
450
451
|
# File 'lib/extracter/class/extracter.rb', line 449
def do_show_the_full_name_of_the_archive
@internal_hash[:show_the_full_name_of_the_archive] = true
end
|
#enable_colours ⇒ Object
544
545
546
547
|
# File 'lib/extracter/class/extracter.rb', line 544
def enable_colours
set_use_colours(true)
@internal_hash[:colour_to_use_for_directories] = cyan?
end
|
#enable_debug ⇒ Object
245
246
247
|
# File 'lib/extracter/class/extracter.rb', line 245
def enable_debug
@internal_hash[:debug] = true
end
|
#esystem(i, try_to_use_colours = try_to_use_colours?
) ⇒ Object
Also known as:
run_this_system_command
#
esystem (system tag, esystem tag)
#
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
|
# File 'lib/extracter/class/extracter.rb', line 892
def esystem(
i, try_to_use_colours = try_to_use_colours?
)
i = i.dup if i.frozen?
_ = @internal_hash[:append_this_to_the_commandline]
unless _.empty?
if i.include? ' '
splitted = i.split(' ')
splitted[0] << " #{_}"
i = splitted.join(' ')
else
i << " #{_}"
end
end
if run_simulation?
copn; e 'As we are running in simulation mode, the following command '
copn; e 'is the one that we would have been used if we were to not run '
copn; e 'in simulation mode:'
if be_verbose?
if try_to_use_colours
e steelblue(i)
else
e i
end
end
else
if be_verbose?
if try_to_use_colours
e steelblue(i)
else
e i
end
end
begin
system i
rescue Exception => error
e 'An error has happened upon attempting to run this system command:'
e
e " #{i}"
e
pp error
e '-----------'
pp error.class
e '-----------'
end
end
end
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
113
114
115
116
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/extracter/class/extract_this_archive.rb', line 31
def (
i, =
)
i = File.absolute_path(i)
if ::Extracter.are_we_on_windows?
_ = UNPACK_COMMAND_TO_USE_ON_WINDOWS+' '+
File.absolute_path(i)+
' | '+
SECOND_UNPACK_COMMAND_TO_USE_ON_WINDOWS
esystem _
return
end
if ::Extracter.is_this_a_valid_archive?(i) or i.end_with?('.pdf')
if be_verbose?
if show_only_the_short_name_of_the_archive?
name_of_the_archive = File.basename(i)
copn; e "#{rev}Extracting `#{sfancy(name_of_the_archive)}#{rev}` "\
"to `#{sdir()}#{rev}`."
else
copn; e "#{rev}Extracting `#{sfancy(i)}` to "\
"`#{sdir()}#{rev}`."
end
end
unless File.writable?
copn; ewarn 'You do not have sufficient permissions to'
copn; ewarn "modify #{sdir()}#{swarn('.')}"
return
end
case i when /\.rpm$/i
name_of_the_directory = i.delete_suffix('.rpm')
mkdir(name_of_the_directory)
(File.absolute_path(name_of_the_directory))
cd(name_of_the_directory)
esystem 'rpm2cpio ../'+File.basename(i)+' | cpio -idmv'
return when /\.tar\.xz$/i,
/\.txz$/i,
/\.xz$/i
esystem consider_verbosity_for(COMMAND_TO_EXTRACT_TAR_XZ_FILES)+' '+i+
when /\.tar$/i
esystem COMMAND_TO_EXTRACT_TAR_FILES+' '+i+
when /.zip$/i,
/.xpi$/i,
/.docx$/i,
/.odt$/i, /.apkg$/
i = pad(i) if i.include?(' ') or i.include?(')')
esystem "unzip #{i}"
when /\.?tgz$/i,
/\.?tar.Z$/i,
/\.?taz$/i
esystem COMMAND_TO_EXTRACT_TGZ_FILES+' '+i+
when '.7z' esystem "7z x #{i}"
when /\.tar\.bz2$/i,
/\.tbz$/i
esystem COMMAND_TO_EXTRACT_TAR_BZ2_FILES+' '+i+
when /\.?gz$/i,
/\.?apk$/i
if i.include? '.tar' esystem 'tar -zxvf '+i+
else
esystem 'gunzip '+i
end
when /\.?bz2$/,
/\.?tbz2$/
if i.include? '.tar' esystem 'tar -vjxf '+i
else
esystem 'bunzip2 '+i
end
when '.rar'
check_whether_rar_is_available
esystem 'unrar e '+i
when '.zst','.tar.zst'
esystem COMMAND_TO_EXTRACT_ZST_ARCHIVES+' '+i
when /\.?deb$/i
esystem COMMAND_TO_EXTRACT_DEB_FILES+' '+i
when /\.?gem$/i
esystem GEM_UNPACK_COMMAND+' '+i+" --target=#{}"
when '.lzma'
esystem "#{COMMAND_TO_EXTRACT_LZMA_FILES} #{i}"
when /\.?bin$/i
esystem("./#{i}")
when /\.?iso$/i
(i)
return
when /\.?img$/i,
/\.?squashfs$/i
(i)
return when /\.?lz$/i,
/\.?tar\.?lz$/i
esystem("#{COMMAND_TO_EXTRACT_LZ_FILES} #{i}#{}")
when /\.?mp4$/i
begin
require 'multimedia_paradise/audio/extract_audio/extract_audio.rb'
rescue LoadError; end
if Object.const_defined? :MultimediaParadise
MultimediaParadise.(i)
end
when/\.?ps$/i
esystem 'ps2ascii '+i+
when /\.?jar$/i
esystem COMMAND_TO_EXTRACT_JAR_ARCHIVES+' '+i
when '.rpm'
esystem "#{COMMAND_TO_EXTRACT_BSDTAR_ARCHIVES} #{i}"
when '.sxz'
esystem "unsquashfs #{i}"
when /\.?pdf$/
begin
require 'pdf_paradise/utility_scripts/convert_pdf_to_text.rb'
_ = PdfParadise::ConvertPdfToText.new(i)
e _.output_file?
rescue LoadError => error
e 'No, not there.'
pp error end
return else notify_the_user_that_this_extension_has_not_been_registered_yet(i)
end
else
if File.exist? i
notify_the_user_that_this_extension_has_not_been_registered_yet(i)
else
opnn; e "No file exists at `#{sfile(i)}`."
end
end
end
|
#
Note that this method is guaranteed to return a String.
#
313
314
315
|
# File 'lib/extracter/class/extracter.rb', line 313
def
@internal_hash[:extract_to].to_s
end
|
#fail_message_not_registered(i) ⇒ Object
#
fail_message_not_registered
Output a fail message when the archive format is not registered.
#
852
853
854
855
|
# File 'lib/extracter/class/extracter.rb', line 852
def fail_message_not_registered(i)
copn; e "#{rev}Can not extract `#{sfancy(i)}#{rev}` - it is "\
"not registered."
end
|
#first_argument? ⇒ Boolean
Also known as:
first?
288
289
290
|
# File 'lib/extracter/class/extracter.rb', line 288
def first_argument?
@commandline_arguments.first
end
|
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
# File 'lib/extracter/class/extracter.rb', line 872
def (
i = commandline_arguments?
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i
when /^-?-?help$/i
show_help
exit
end
end
end
|
#namespace? ⇒ Boolean
399
400
401
|
# File 'lib/extracter/class/extracter.rb', line 399
def namespace?
@internal_hash[:namespace]
end
|
#notify_the_user_that_this_extension_has_not_been_registered_yet(i) ⇒ Object
#
notify_the_user_that_this_extension_has_not_been_registered_yet
#
841
842
843
844
845
|
# File 'lib/extracter/class/extracter.rb', line 841
def notify_the_user_that_this_extension_has_not_been_registered_yet(i)
opnn; e "The archive at `#{i}` is #{tomato('not')}"
opnn; e "registered as a permissive extension."
fail_message_not_registered(i)
end
|
#opnn(use_this_hash = use_this_opn_hash?
) ⇒ Object
Also known as:
opn, copn
#
opnn
This variant will also check whether we should show the name or not.
#
325
326
327
328
329
330
331
|
# File 'lib/extracter/class/extracter.rb', line 325
def opnn(
use_this_hash = use_this_opn_hash?
)
if use_opn? and Object.const_defined?(:Opn) and show_the_name?
Opn.opn(use_this_hash)
end
end
|
#pad(i, with_this_character = "'") ⇒ Object
#
pad (pad tag)
This method must be able to deal with ‘ ’ as well as with ‘()’.
The second character is the character that will be used for the padding.
#
382
383
384
385
386
387
388
389
390
391
392
393
394
|
# File 'lib/extracter/class/extracter.rb', line 382
def pad(
i, with_this_character = "'"
)
if i.include?('(') or i.include?(')')
i.tr!('(','\(')
i.tr!(')','\)') if i.include? ')'
i = pad(i, '"')
else
return with_this_character+
i+
with_this_character
end
end
|
#pad_opn_with_n_tokens(n_tokens = nil) ⇒ Object
Also known as:
set_pad_opn_with_n_tokens
#
pad_opn_with_n_tokens
#
464
465
466
467
468
469
|
# File 'lib/extracter/class/extracter.rb', line 464
def pad_opn_with_n_tokens(n_tokens = nil)
if n_tokens
determine_default_opn_hash main_hash?.update(padding: n_tokens)
end
end
|
295
296
297
|
# File 'lib/extracter/class/extracter.rb', line 295
def
" -C #{} "
end
|
#prefix_namespace_with(i) ⇒ Object
#
prefix_namespace_with
#
456
457
458
459
|
# File 'lib/extracter/class/extracter.rb', line 456
def prefix_namespace_with(i)
@internal_hash[:namespace] = "#{i}#{@internal_hash[:namespace].dup}"
update_the_main_hash end
|
#prepare_the_hash_for_opn(use_this_hash = {
namespace: namespace?,
use_colours: use_colours?
}) ⇒ Object
Also known as:
update_the_opn_hash, determine_default_opn_hash, determine_the_default_opn_hash, update_the_main_hash
#
prepare_the_hash_for_opn
#
474
475
476
477
478
479
480
481
482
483
484
485
|
# File 'lib/extracter/class/extracter.rb', line 474
def prepare_the_hash_for_opn(
use_this_hash = {
namespace: namespace?,
use_colours: use_colours?
}
)
@internal_hash[:use_this_opn_hash] = use_this_hash
return @internal_hash[:use_this_opn_hash]
end
|
#rds(i) ⇒ Object
590
591
592
593
|
# File 'lib/extracter/class/extracter.rb', line 590
def rds(i)
return i.squeeze('/') if i.respond_to? :squeeze
return i
end
|
#register_sigint ⇒ Object
425
426
427
428
429
430
431
432
433
|
# File 'lib/extracter/class/extracter.rb', line 425
def register_sigint
Signal.trap('SIGINT') {
e sfancy('Requesting a graceful exit from ')+
colour_to_use_for_directories?+
'class Extracter'+
sfancy('. Exiting now.')
exit
}
end
|
#remove_file_extension(i) ⇒ Object
Also known as:
remove_extension, remove_ext
#
remove_file_extension
#
581
582
583
584
|
# File 'lib/extracter/class/extracter.rb', line 581
def remove_file_extension(i)
_ = File.basename(i)
return ::Extracter.remove_archive_type(_)
end
|
#report_to_the_user(i, extract_to = extract_to?
) ⇒ Object
#
report_to_the_user
This method reports to the user. Usually this is done only via this file here though.
#
956
957
958
959
960
961
962
963
964
965
966
967
968
969
|
# File 'lib/extracter/class/extracter.rb', line 956
def report_to_the_user(
i,
=
)
if be_verbose?
target = +
remove_file_extension(
File.basename(i)
)+
'/'
opnn; e "#{rev}Finished extracting to `"\
"#{sdir(target)}#{rev}`." end
end
|
#reset ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/extracter/class/extracter.rb', line 129
def reset
super()
@internal_hash[:try_to_use_colours] = true
@internal_hash[:colour_to_use_for_directories] = 'cyan'
@internal_hash[:use_opn] = true @internal_hash[:show_the_full_name_of_the_archive] = false
@internal_hash[:debug] = false
@internal_hash[:append_this_to_the_commandline] = ''.dup
@internal_hash[:namespace] = NAMESPACE
@internal_hash[:be_verbose] = true
@internal_hash[:show_the_name] = false
@internal_hash[:show_only_the_short_name_of_the_archive] =
SHOW_ONLY_THE_SHORT_NAME_OF_THE_ARCHIVE
@internal_hash[:run_simulation] = false @internal_hash[:extract_to] = return_pwd
do_show_name prepare_the_hash_for_opn
enable_colours
end
|
#return_pwd ⇒ Object
252
253
254
|
# File 'lib/extracter/class/extracter.rb', line 252
def return_pwd
"#{Dir.pwd}/".squeeze('/')
end
|
#run ⇒ Object
#
run (run tag, def tag)
#
989
990
991
992
|
# File 'lib/extracter/class/extracter.rb', line 989
def run
work_on_the_given_input
end
|
#run_already? ⇒ Boolean
238
239
240
|
# File 'lib/extracter/class/extracter.rb', line 238
def run_already?
@internal_hash[:run_already]
end
|
#run_simulation=(i) ⇒ Object
507
508
509
|
# File 'lib/extracter/class/extracter.rb', line 507
def run_simulation=(i)
@internal_hash[:run_simulation] = i
end
|
#run_simulation? ⇒ Boolean
514
515
516
|
# File 'lib/extracter/class/extracter.rb', line 514
def run_simulation?
@internal_hash[:run_simulation]
end
|
#set_be_verbose(i = false) ⇒ Object
Also known as:
set_verbosity
#
set_be_verbose
This sets the verbosity level of the class. Use only this method when you wish to modify the @be_verbose instance variable.
#
409
410
411
|
# File 'lib/extracter/class/extracter.rb', line 409
def set_be_verbose(i = false)
@internal_hash[:be_verbose] = i
end
|
#set_colour_for_directories(i) ⇒ Object
#
set_colour_for_directories
Set the colour for directories to use.
#
304
305
306
|
# File 'lib/extracter/class/extracter.rb', line 304
def set_colour_for_directories(i)
@internal_hash[:colour_to_use_for_directories] = ::Colours.beautify(i)
end
|
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
273
274
275
276
|
# File 'lib/extracter/class/extracter.rb', line 273
def set_commandline_arguments(i = '')
i = [i].flatten.compact
@commandline_arguments = i
end
|
#
This is the method that should be used to determine into which directory this class will extract archives into.
Note that this target can be modified from the commandline, if the user wants to do so.
#
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
|
# File 'lib/extracter/class/extracter.rb', line 604
def (
i = :temp_dir
)
if i.is_a?(Hash) and i.empty?
i = :temp_dir
end
if i.is_a? Hash
if i.has_key? :run_already
@internal_hash[:run_already] = i.delete(:run_already)
end
if i.has_key? :prepend_this_namespace
prefix_with_this = i.delete(:prepend_this_namespace) prefix_namespace_with(prefix_with_this)
end
if i.has_key? :use_colours
set_use_colours(i.delete(:use_colours))
end
if i.has_key? :verbosity
set_be_verbose(i.delete(:verbosity))
elsif i.has_key? :be_verbose
set_be_verbose(i.delete(:be_verbose))
end
if i.has_key? :append_this_to_the_commandline
@internal_hash[:append_this_to_the_commandline] =
i.delete(:append_this_to_the_commandline)
end
if i.has_key? :use_opn
set_use_opn(i.delete(:use_opn))
end
if i.has_key? :pad_opn_with_n_tokens
set_pad_opn_with_n_tokens(i.delete(:pad_opn_with_n_tokens))
end
if i.has_key? :run_simulation
set_run_simulation(i.delete(:run_simulation))
end
if i.has_key? :use_colours
set_use_colours(i.delete(use_colours))
end
if i.has_key? :extract_to
i = i.delete(:extract_to)
elsif i.has_key? :to
i = i.delete(:to)
end
end
case i when :default
i = return_pwd
when 'TEMP',
'MY_TEMP',
'MYTEMP',
:temp_dir,
nil
i = TEMP_DIR
end
i = rds(i)
i.gsub!(/--to=/,'') if i.include? '--to='
i = i.to_s.dup @internal_hash[:extract_to] = i
end
|
#set_run_simulation(i = false) ⇒ Object
500
501
502
|
# File 'lib/extracter/class/extracter.rb', line 500
def set_run_simulation(i = false) @internal_hash[:run_simulation] = i
end
|
#set_use_colours(i) ⇒ Object
562
563
564
565
566
567
568
569
|
# File 'lib/extracter/class/extracter.rb', line 562
def set_use_colours(i)
main_hash?.update(use_colours: i)
@internal_hash[:try_to_use_colours] = i
end
|
#set_use_opn(i = true) ⇒ Object
259
260
261
|
# File 'lib/extracter/class/extracter.rb', line 259
def set_use_opn(i = true)
@internal_hash[:use_opn] = i
end
|
#show_help ⇒ Object
#
show_help (help tag)
This method will show the available - and documented - help options for class Extracter.
To call this method via the commandline try:
--help
#
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/extracter/class/extracter.rb', line 352
def show_help
e
opnn; e 'How to extract archives, without helper scripts?'
e
e ' tar -zxvf foobar.tar.gz # for .tar.gz'
e ' tar xvzf foobar.tgz # for .tgz'
e ' tar xvfJ foobar.tar.xz # for .tar.xz'
e ' tar jxf foobar.tar.bz2 # for .tar.bz2'
e ' tar -xf foobar.tar.bz2 # for .tbz'
e ' tar --lzip -xvf zutils-1.5.tar.lz # for .tar.lz'
e ' unsquashfs foobar-1.2.3.sxz # for .sxz'
e ' 7z x -so C:\home\x\src\htop\htop-3.0.5.tar.xz | 6z x -si -ttar # on windows'
e
opnn; e 'Furthermore, there are some commandline options '\
'that can'
opnn; e 'be used for this class (class Extracter).'
e
e ' --to=/home/Temp # extract into the '\
'directory /home/Temp/'
e
end
|
#show_only_the_short_name_of_the_archive? ⇒ Boolean
#
show_only_the_short_name_of_the_archive?
#
493
494
495
|
# File 'lib/extracter/class/extracter.rb', line 493
def show_only_the_short_name_of_the_archive?
@internal_hash[:show_only_the_short_name_of_the_archive]
end
|
#show_the_name? ⇒ Boolean
209
210
211
|
# File 'lib/extracter/class/extracter.rb', line 209
def show_the_name?
@internal_hash[:show_the_name]
end
|
#strip_components(by_n = 1) ⇒ Object
#
strip_components
The first argument to this method will determine how far “down” tar will strip the components.
#
524
525
526
527
528
529
|
# File 'lib/extracter/class/extracter.rb', line 524
def strip_components(
by_n = 1
)
@internal_hash[:append_this_to_the_commandline] <<
" --strip-components=#{by_n}"
end
|
860
861
862
863
864
865
866
867
|
# File 'lib/extracter/class/extracter.rb', line 860
def (i)
opnn; e 'Handling a squashfs .img file format next:'
name_without_extension = i.delete_suffix(File.extname(i))
mkdir(name_without_extension) unless File.directory? name_without_extension
esystem "mount -o loop -t squashfs #{i} #{name_without_extension}"
e 'The content of the extracted (or rather, mounted) archive is:'
pp Dir["#{name_without_extension}*"]
end
|
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
|
# File 'lib/extracter/class/extracter.rb', line 719
def (i)
opnn; e 'Extracting an .iso file is a bit more complicated '\
'than extracting a .tar.gz tarball'
opnn; e 'archive. This class will first create a helper '\
'directory; then mount the .iso there,'
opnn; e 'then copy the content to the main directory.'
helper_directory = File.dirname(i)+
'/READ_ONLY_DIRECTORY_'+
File.basename(
i.delete_suffix(File.extname(i))
)+
'/'
mkdir(helper_directory) unless File.directory? helper_directory
esystem 'mount -o loop '+i+' '+helper_directory
e 'The helper directory in use is '\
'`'+sdir(File.absolute_path(helper_directory))+'`.'
main_directory = File.dirname(i)+
'/'+
File.basename(
i.delete_suffix(File.extname(i))
)+
'/'
e 'Next creating the main directory at `'+sdir(main_directory)+'`.'
mkdir(main_directory) unless File.directory? main_directory
e 'Next copying the content of the helper directory recursively '
e 'from `'+sdir(helper_directory)+'`'
e 'onto `'+sdir(
main_directory+File.basename(helper_directory)+'/'
)+'`.'
cpr(
helper_directory,
main_directory+File.basename(helper_directory)+'/'
)
a = main_directory+File.basename(helper_directory)+'/'
e 'Relocating the files next from:'
e
e " #{sdir(a)}"
e
Dir[a+'*'].each {|entry|
mv(
entry,
main_directory
)
}
remove_this_directory(a)
e 'The content of the extracted (or rather, mounted) archive is:'
e
pp Dir["#{main_directory}*"]
e
end
|
#try_to_use_colours? ⇒ Boolean
574
575
576
|
# File 'lib/extracter/class/extracter.rb', line 574
def try_to_use_colours?
@internal_hash[:try_to_use_colours]
end
|
#use_opn? ⇒ Boolean
266
267
268
|
# File 'lib/extracter/class/extracter.rb', line 266
def use_opn?
@internal_hash[:use_opn]
end
|
#use_this_opn_hash? ⇒ Boolean
Also known as:
main_hash?
337
338
339
|
# File 'lib/extracter/class/extracter.rb', line 337
def use_this_opn_hash?
@internal_hash[:use_this_opn_hash]
end
|
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
# File 'lib/extracter/class/extracter.rb', line 776
def work_on_the_given_input(
array = commandline_arguments?,
=
)
if array.is_a?(String) and File.directory?(array)
array = Dir[rds("#{array}/")+'*'].sample
end
case
when nil
=
end
if array.empty?
opnn; e 'No archive (input) was provided. Please provide the file'
opnn; e 'that is to be extracted.'
else
array.each {|this_file|
create_directory() unless File.directory?()
begin
if this_file =~ /^\d$/
this_file = Dir['*'][( this_file.to_i - 1 )] unless File.exist?(this_file)
end
rescue ArgumentError => error
e 'Error for '+sfancy(this_file)+':'
pp error
end
if File.directory? this_file
this_file = Dir[rds("#{this_file}/")+'*'].sample
end
(this_file, )
report_to_the_user(this_file, )
}
end
end
|