extracter 1.2.32 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +116 -87
- data/bin/extract +2 -2
- data/doc/README.gen +117 -88
- data/extracter.gemspec +12 -32
- data/lib/extracter/base/base.rb +354 -43
- data/lib/extracter/class/extracter.rb +722 -559
- data/lib/extracter/constants/constants.rb +38 -39
- data/lib/extracter/requires/require_the_extracter_project.rb +1 -1
- data/lib/extracter/requires/require_the_toplevel_methods.rb +7 -0
- data/lib/extracter/toplevel_methods/toplevel_methods.rb +99 -0
- data/lib/extracter/version/version.rb +2 -2
- data/lib/extracter.rb +0 -0
- data/test/testing_are_we_on_windows.rb +10 -0
- data/test/testing_class_extracter.rb +3 -2
- data/test/testing_class_method_extract_what_to.rb +4 -1
- metadata +31 -35
- data/bin/extract_it +0 -13
- data/lib/extracter/class/extract_this_archive.rb +0 -289
- data/lib/extracter/extract_it/extract_it.rb +0 -241
- data/lib/extracter/toplevel_methods/is_this_a_valid_archive.rb +0 -41
- data/lib/extracter/toplevel_methods/misc.rb +0 -34
data/extracter.gemspec
CHANGED
@@ -15,40 +15,20 @@ Gem::Specification.new { |s|
|
|
15
15
|
|
16
16
|
DESCRIPTION = <<-EOF
|
17
17
|
|
18
|
-
This fairly small
|
19
|
-
archive formats such as .tar.bz2
|
20
|
-
|
18
|
+
This fairly small gem can be used to extract different
|
19
|
+
archive formats, such as .tar.bz2, .tar.gz, .tbz,
|
20
|
+
.zip, .gem, .lzma and various more.
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
be - optional, though. If you have no such use case then you
|
25
|
-
won't need to install the multimedia_paradise gem.
|
22
|
+
Audio can be extracted as well, via ffmpeg, if the gem called
|
23
|
+
multimedia_paradise is installed.
|
26
24
|
|
27
|
-
|
25
|
+
This project, however had, depends on external tools,
|
26
|
+
such as tar (on Linux) or 7z / 7zip (on Windows), so
|
27
|
+
these have to be installed first.
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
The second argument that can be passed to the method new()
|
34
|
-
specifies where this should be extract to.
|
35
|
-
|
36
|
-
For example:
|
37
|
-
|
38
|
-
Extracter.new('/foo/bla-1.0.tar.bz2', '/opt')
|
39
|
-
|
40
|
-
This would extract to the /opt directory.
|
41
|
-
|
42
|
-
You can query whether input is an archive or not via:
|
43
|
-
|
44
|
-
Extracter.is_archive? 'foo.tar.xz'
|
45
|
-
|
46
|
-
As of April 2014 we also provide a bin/extract file, so that
|
47
|
-
you can simply extract something from the commandline.
|
48
|
-
|
49
|
-
Since as of November 2018, class Extracter can also "extract"
|
50
|
-
.iso files. (The .iso will be mounted to a directory that
|
51
|
-
will be created, actually.)
|
29
|
+
For more information about this project have a look
|
30
|
+
at the homepage, at
|
31
|
+
https://rubygems.org/gems/extracter.
|
52
32
|
|
53
33
|
EOF
|
54
34
|
|
@@ -106,4 +86,4 @@ EOF
|
|
106
86
|
# ========================================================================= #
|
107
87
|
s.add_dependency 'opn'
|
108
88
|
|
109
|
-
}
|
89
|
+
}
|
data/lib/extracter/base/base.rb
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
# =========================================================================== #
|
5
5
|
# === Extracter::Base
|
6
6
|
#
|
7
|
+
# This is the base class for the extracter-gem.
|
8
|
+
#
|
7
9
|
# Usage example:
|
8
10
|
#
|
9
11
|
# Extracter::Base.new(ARGV)
|
@@ -15,24 +17,52 @@ module Extracter
|
|
15
17
|
|
16
18
|
class Base # === Extracter::Base
|
17
19
|
|
20
|
+
require 'fileutils' # We always need fileutils.
|
21
|
+
|
18
22
|
begin
|
19
23
|
require 'colours/html_colours'
|
20
24
|
rescue LoadError; end
|
21
25
|
|
26
|
+
require 'extracter/toplevel_methods/toplevel_methods.rb'
|
27
|
+
|
22
28
|
# ========================================================================= #
|
23
|
-
# === reset
|
29
|
+
# === reset (reset tag)
|
24
30
|
# ========================================================================= #
|
25
31
|
def reset
|
26
32
|
# ======================================================================= #
|
27
33
|
# === @internal_hash
|
34
|
+
#
|
35
|
+
# The internal Hash must be created first.
|
28
36
|
# ======================================================================= #
|
29
|
-
|
37
|
+
create_the_internal_hash
|
38
|
+
# ======================================================================= #
|
39
|
+
# === :debug
|
40
|
+
# ======================================================================= #
|
41
|
+
@internal_hash[:debug] = false
|
30
42
|
# ======================================================================= #
|
31
|
-
# === :
|
43
|
+
# === :be_verbose
|
44
|
+
# ======================================================================= #
|
45
|
+
@internal_hash[:be_verbose] = true
|
46
|
+
# ======================================================================= #
|
47
|
+
# === :colour_to_use_for_directories
|
48
|
+
# ======================================================================= #
|
49
|
+
@internal_hash[:colour_to_use_for_directories] = 'cyan'
|
50
|
+
# ======================================================================= #
|
51
|
+
# === :use_opn
|
52
|
+
# ======================================================================= #
|
53
|
+
@internal_hash[:use_opn] = true # ← Whether to use make use of Opn by default or not.
|
32
54
|
# ======================================================================= #
|
33
|
-
@internal_hash[:use_colours] = true
|
34
55
|
# Next check whether the Colours gem is available.
|
56
|
+
# ======================================================================= #
|
35
57
|
check_whether_the_colours_gem_is_available
|
58
|
+
do_try_to_use_colours
|
59
|
+
end
|
60
|
+
|
61
|
+
# ========================================================================= #
|
62
|
+
# === create_the_internal_hash
|
63
|
+
# ========================================================================= #
|
64
|
+
def create_the_internal_hash
|
65
|
+
@internal_hash = {}
|
36
66
|
end
|
37
67
|
|
38
68
|
# ========================================================================= #
|
@@ -45,22 +75,39 @@ class Base # === Extracter::Base
|
|
45
75
|
Colours.respond_to?(:sdir) and
|
46
76
|
Colours.respond_to?(:simp)
|
47
77
|
else
|
48
|
-
|
78
|
+
do_not_make_use_of_colours
|
49
79
|
end
|
50
80
|
end
|
51
81
|
|
82
|
+
# ========================================================================= #
|
83
|
+
# === do_not_make_use_of_colours
|
84
|
+
# ========================================================================= #
|
85
|
+
def do_not_make_use_of_colours
|
86
|
+
@internal_hash[:use_colours] = false
|
87
|
+
end
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === change_directory
|
91
|
+
# ========================================================================= #
|
92
|
+
def change_directory(i)
|
93
|
+
Dir.chdir(i)
|
94
|
+
end; alias cd change_directory # === cd
|
95
|
+
|
52
96
|
# ========================================================================= #
|
53
97
|
# === cyan
|
54
98
|
# ========================================================================= #
|
55
|
-
def cyan?
|
56
|
-
return Colours::CYAN if Object.const_defined?(:Colours) and use_colours
|
99
|
+
def cyan?(use_colours = use_colours?)
|
100
|
+
return Colours::CYAN if Object.const_defined?(:Colours) and use_colours
|
57
101
|
return ''
|
58
102
|
end
|
59
103
|
|
60
104
|
# ========================================================================= #
|
61
105
|
# === tomato
|
62
106
|
# ========================================================================= #
|
63
|
-
def tomato(
|
107
|
+
def tomato(
|
108
|
+
i = '',
|
109
|
+
use_colours = use_colours?
|
110
|
+
)
|
64
111
|
return Colours.tomato(i) if use_colours
|
65
112
|
return i
|
66
113
|
end
|
@@ -68,30 +115,74 @@ class Base # === Extracter::Base
|
|
68
115
|
# ========================================================================= #
|
69
116
|
# === simp
|
70
117
|
# ========================================================================= #
|
71
|
-
def simp(
|
72
|
-
|
118
|
+
def simp(
|
119
|
+
i = '',
|
120
|
+
use_colours = use_colours?
|
121
|
+
)
|
122
|
+
return Colours.simp(i) if use_colours
|
73
123
|
return i
|
74
124
|
end
|
75
125
|
|
76
126
|
# ========================================================================= #
|
77
127
|
# === steelblue
|
78
128
|
# ========================================================================= #
|
79
|
-
def steelblue(
|
80
|
-
|
129
|
+
def steelblue(
|
130
|
+
i = '',
|
131
|
+
use_colours = use_colours?
|
132
|
+
)
|
133
|
+
return ::Colours.steelblue(i) if use_colours and ::Colours.respond_to?(:steelblue)
|
81
134
|
return i
|
82
135
|
end
|
83
136
|
|
84
137
|
# ========================================================================= #
|
85
138
|
# === ewarn
|
86
139
|
# ========================================================================= #
|
87
|
-
def ewarn(
|
88
|
-
|
140
|
+
def ewarn(
|
141
|
+
i = '',
|
142
|
+
use_colours = use_colours?
|
143
|
+
)
|
144
|
+
if use_colours and Object.const_defined?(:Colours)
|
89
145
|
e Colours.swarn(i)
|
90
146
|
else
|
91
147
|
e i
|
92
148
|
end
|
93
149
|
end
|
94
150
|
|
151
|
+
# ========================================================================= #
|
152
|
+
# === cpr
|
153
|
+
# ========================================================================= #
|
154
|
+
def cpr(a, b)
|
155
|
+
try_to_require_fileutils
|
156
|
+
FileUtils.cp_r(a, b)
|
157
|
+
end
|
158
|
+
|
159
|
+
# ========================================================================= #
|
160
|
+
# === move
|
161
|
+
# ========================================================================= #
|
162
|
+
def move(a, b)
|
163
|
+
try_to_require_fileutils
|
164
|
+
FileUtils.mv(a, b)
|
165
|
+
end; alias mv move # === mv
|
166
|
+
|
167
|
+
# ========================================================================= #
|
168
|
+
# === remove_this_directory
|
169
|
+
#
|
170
|
+
# This method can be used to remove a directory.
|
171
|
+
# ========================================================================= #
|
172
|
+
def remove_this_directory(i)
|
173
|
+
if File.directory? i
|
174
|
+
try_to_require_fileutils
|
175
|
+
FileUtils.rm_r(i) unless i == '/'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# ========================================================================= #
|
180
|
+
# === try_to_require_fileutils
|
181
|
+
# ========================================================================= #
|
182
|
+
def try_to_require_fileutils
|
183
|
+
require 'fileutils' unless Object.const_defined?(:FileUtils)
|
184
|
+
end
|
185
|
+
|
95
186
|
# ========================================================================= #
|
96
187
|
# === sfile
|
97
188
|
# ========================================================================= #
|
@@ -117,62 +208,282 @@ class Base # === Extracter::Base
|
|
117
208
|
end
|
118
209
|
|
119
210
|
# ========================================================================= #
|
120
|
-
# ===
|
211
|
+
# === e (e tag)
|
212
|
+
# ========================================================================= #
|
213
|
+
def e(i = '')
|
214
|
+
puts i
|
215
|
+
end
|
216
|
+
|
217
|
+
# ========================================================================= #
|
218
|
+
# === rev (rev tag)
|
219
|
+
# ========================================================================= #
|
220
|
+
def rev
|
221
|
+
if use_colours?
|
222
|
+
::Colours.rev
|
223
|
+
else
|
224
|
+
''
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# ========================================================================= #
|
229
|
+
# === are_we_on_windows?
|
230
|
+
# ========================================================================= #
|
231
|
+
def are_we_on_windows?
|
232
|
+
::Extracter.are_we_on_windows?
|
233
|
+
end
|
234
|
+
|
235
|
+
# ========================================================================= #
|
236
|
+
# === be_verbose?
|
121
237
|
#
|
122
|
-
#
|
238
|
+
# Getter method for whether we will be verbose or not.
|
123
239
|
# ========================================================================= #
|
124
|
-
def
|
125
|
-
@internal_hash[:
|
126
|
-
end
|
240
|
+
def be_verbose?
|
241
|
+
@internal_hash[:be_verbose]
|
242
|
+
end
|
127
243
|
|
128
244
|
# ========================================================================= #
|
129
|
-
# ===
|
245
|
+
# === register_sigint
|
130
246
|
# ========================================================================= #
|
131
|
-
def
|
132
|
-
|
247
|
+
def register_sigint(this_class_name = 'Extracter')
|
248
|
+
Signal.trap('SIGINT') {
|
249
|
+
e sfancy('Requesting a graceful exit from ')+
|
250
|
+
colour_to_use_for_directories?+
|
251
|
+
'class '+this_class_name+sfancy('. Exiting now.')
|
252
|
+
exit
|
253
|
+
}
|
133
254
|
end
|
134
255
|
|
135
256
|
# ========================================================================= #
|
136
|
-
# ===
|
257
|
+
# === colour_to_use_for_directories?
|
137
258
|
# ========================================================================= #
|
138
|
-
def
|
139
|
-
|
140
|
-
|
259
|
+
def colour_to_use_for_directories?
|
260
|
+
if use_colours?
|
261
|
+
return @internal_hash[:colour_to_use_for_directories]
|
262
|
+
else
|
263
|
+
return ''
|
264
|
+
end
|
141
265
|
end
|
142
266
|
|
143
267
|
# ========================================================================= #
|
144
|
-
# ===
|
268
|
+
# === disable_colours
|
269
|
+
#
|
270
|
+
# Use this method if you want to disable colour-support of this class.
|
145
271
|
# ========================================================================= #
|
146
|
-
def
|
147
|
-
|
148
|
-
|
149
|
-
end
|
272
|
+
def disable_colours
|
273
|
+
set_use_colours(false)
|
274
|
+
@internal_hash[:colour_to_use_for_directories] = ''.dup
|
275
|
+
end
|
150
276
|
|
151
277
|
# ========================================================================= #
|
152
|
-
# ===
|
278
|
+
# === create_directory (mkdir tag)
|
279
|
+
#
|
280
|
+
# Use this to create directories.
|
153
281
|
# ========================================================================= #
|
154
|
-
def
|
155
|
-
|
156
|
-
|
282
|
+
def create_directory(i)
|
283
|
+
FileUtils.mkdir_p(i) unless File.directory?(i)
|
284
|
+
end; alias mkdir create_directory # === mkdir
|
285
|
+
|
286
|
+
# ========================================================================= #
|
287
|
+
# === be_verbose
|
288
|
+
# ========================================================================= #
|
289
|
+
def be_verbose
|
290
|
+
set_be_verbose(true)
|
291
|
+
end
|
292
|
+
|
293
|
+
# ========================================================================= #
|
294
|
+
# === do_be_quiet
|
295
|
+
# ========================================================================= #
|
296
|
+
def do_be_quiet
|
297
|
+
set_be_verbose(false)
|
298
|
+
end; alias be_silent do_be_quiet # === be_silent
|
299
|
+
alias be_quiet do_be_quiet # === be_quiet
|
300
|
+
|
301
|
+
# ========================================================================= #
|
302
|
+
# === rds
|
303
|
+
# ========================================================================= #
|
304
|
+
def rds(i)
|
305
|
+
return i.squeeze('/') if i.respond_to? :squeeze
|
306
|
+
return i
|
307
|
+
end
|
308
|
+
|
309
|
+
# ========================================================================= #
|
310
|
+
# === set_be_verbose
|
311
|
+
#
|
312
|
+
# This sets the verbosity level of the class. Use only this method
|
313
|
+
# when you wish to modify the @be_verbose instance variable.
|
314
|
+
# ========================================================================= #
|
315
|
+
def set_be_verbose(i = false)
|
316
|
+
@internal_hash[:be_verbose] = i
|
317
|
+
end; alias set_verbosity set_be_verbose # === set_verbosity
|
318
|
+
alias show_commands_used set_be_verbose # === show_commands_used
|
319
|
+
|
320
|
+
# ========================================================================= #
|
321
|
+
# === remove_file_extension
|
322
|
+
# ========================================================================= #
|
323
|
+
def remove_file_extension(i)
|
324
|
+
_ = File.basename(i)
|
325
|
+
return ::Extracter.remove_archive_type(_)
|
326
|
+
end; alias remove_extension remove_file_extension # === remove_extensions
|
327
|
+
alias remove_ext remove_file_extension # === remove_ext
|
328
|
+
|
329
|
+
# ========================================================================= #
|
330
|
+
# === set_commandline_arguments
|
331
|
+
# ========================================================================= #
|
332
|
+
def set_commandline_arguments(i = '')
|
333
|
+
i = [i].flatten.compact
|
334
|
+
@commandline_arguments = i
|
335
|
+
end
|
336
|
+
|
337
|
+
# ========================================================================= #
|
338
|
+
# === commandline_arguments?
|
339
|
+
# ========================================================================= #
|
340
|
+
def commandline_arguments?
|
341
|
+
@commandline_arguments
|
342
|
+
end
|
343
|
+
|
344
|
+
# ========================================================================= #
|
345
|
+
# === first_argument?
|
346
|
+
# ========================================================================= #
|
347
|
+
def first_argument?
|
348
|
+
@commandline_arguments.first
|
349
|
+
end; alias first? first_argument? # === first?
|
350
|
+
|
351
|
+
# ========================================================================= #
|
352
|
+
# === return_pwd
|
353
|
+
# ========================================================================= #
|
354
|
+
def return_pwd
|
355
|
+
"#{Dir.pwd}/".squeeze('/')
|
356
|
+
end
|
357
|
+
|
358
|
+
# ========================================================================= #
|
359
|
+
# === debug?
|
360
|
+
# ========================================================================= #
|
361
|
+
def debug?
|
362
|
+
@internal_hash[:debug]
|
363
|
+
end
|
364
|
+
|
365
|
+
# ========================================================================= #
|
366
|
+
# === enable_debug
|
367
|
+
# ========================================================================= #
|
368
|
+
def enable_debug
|
369
|
+
@internal_hash[:debug] = true
|
370
|
+
end
|
371
|
+
|
372
|
+
# ========================================================================= #
|
373
|
+
# === namespace?
|
374
|
+
# ========================================================================= #
|
375
|
+
def namespace?
|
376
|
+
@internal_hash[:namespace]
|
377
|
+
end
|
378
|
+
|
379
|
+
# ========================================================================= #
|
380
|
+
# === enable_colours
|
381
|
+
# ========================================================================= #
|
382
|
+
def enable_colours
|
383
|
+
set_use_colours(true)
|
384
|
+
@internal_hash[:colour_to_use_for_directories] = cyan?
|
385
|
+
end
|
386
|
+
|
387
|
+
# ========================================================================= #
|
388
|
+
# === set_use_colours
|
389
|
+
# ========================================================================= #
|
390
|
+
def set_use_colours(i, main_hash = main_hash?)
|
391
|
+
# ======================================================================= #
|
392
|
+
# We must also sync this towards our main Hash, for opn(). The next
|
393
|
+
# line of code achieves precisely that.
|
394
|
+
# ======================================================================= #
|
395
|
+
main_hash.update(use_colours: i) if main_hash
|
396
|
+
@internal_hash[:try_to_use_colours] = i
|
397
|
+
end
|
398
|
+
|
399
|
+
# ========================================================================= #
|
400
|
+
# === do_try_to_use_colours
|
401
|
+
# ========================================================================= #
|
402
|
+
def do_try_to_use_colours
|
403
|
+
set_use_colours(true)
|
404
|
+
end
|
405
|
+
|
406
|
+
# ========================================================================= #
|
407
|
+
# === try_to_use_colours?
|
408
|
+
#
|
409
|
+
# Determine whether we will use colours for class Extracter::Base
|
410
|
+
# and its subclass.
|
411
|
+
# ========================================================================= #
|
412
|
+
def try_to_use_colours?
|
413
|
+
@internal_hash[:try_to_use_colours]
|
414
|
+
end; alias use_colours? try_to_use_colours? # === use_colours?
|
415
|
+
alias colours? try_to_use_colours? # === colours?
|
416
|
+
|
417
|
+
# ========================================================================= #
|
418
|
+
# === set_use_opn
|
419
|
+
# ========================================================================= #
|
420
|
+
def set_use_opn(i = true)
|
421
|
+
@internal_hash[:use_opn] = i
|
422
|
+
end
|
423
|
+
|
424
|
+
# ========================================================================= #
|
425
|
+
# === use_opn?
|
426
|
+
# ========================================================================= #
|
427
|
+
def use_opn?
|
428
|
+
@internal_hash[:use_opn]
|
429
|
+
end
|
430
|
+
|
431
|
+
# ========================================================================= #
|
432
|
+
# === opne
|
433
|
+
# ========================================================================= #
|
434
|
+
def opne(i = '')
|
435
|
+
opnn; e i
|
436
|
+
end
|
437
|
+
|
438
|
+
# ========================================================================= #
|
439
|
+
# === use_this_opn_hash?
|
440
|
+
# ========================================================================= #
|
441
|
+
def use_this_opn_hash?
|
442
|
+
@internal_hash[:use_this_opn_hash]
|
443
|
+
end; alias main_hash? use_this_opn_hash? # === main_hash?
|
444
|
+
|
445
|
+
# ========================================================================= #
|
446
|
+
# === opnn
|
447
|
+
#
|
448
|
+
# This variant will also check whether we should show the name or not.
|
449
|
+
# ========================================================================= #
|
450
|
+
def opnn(
|
451
|
+
use_this_hash = use_this_opn_hash?
|
452
|
+
)
|
453
|
+
if use_opn? and Object.const_defined?(:Opn)
|
454
|
+
Opn.opn(use_this_hash)
|
157
455
|
end
|
456
|
+
end; alias opn opnn # === opn
|
457
|
+
alias copn opnn # === copn
|
458
|
+
|
459
|
+
# ========================================================================= #
|
460
|
+
# === is_archive?
|
461
|
+
#
|
462
|
+
# This method queries whether the given file at hand (as input to
|
463
|
+
# this method) is assumed to be an archive or whether it is not.
|
464
|
+
# ========================================================================= #
|
465
|
+
def is_archive?(i)
|
466
|
+
ARRAY_ARCHIVE_TYPES.include?(
|
467
|
+
File.extname(File.basename(i))
|
468
|
+
)
|
158
469
|
end
|
159
470
|
|
160
471
|
# ========================================================================= #
|
161
|
-
# ===
|
472
|
+
# === array_archive_types?
|
162
473
|
# ========================================================================= #
|
163
|
-
def
|
164
|
-
|
165
|
-
end
|
474
|
+
def array_archive_types?
|
475
|
+
ARRAY_REGISTERED_ARCHIVES
|
476
|
+
end
|
166
477
|
|
167
478
|
# ========================================================================= #
|
168
|
-
# ===
|
479
|
+
# === orev
|
169
480
|
# ========================================================================= #
|
170
|
-
def
|
171
|
-
|
481
|
+
def orev(i = '')
|
482
|
+
opne "#{rev}#{i}"
|
172
483
|
end
|
173
484
|
|
174
485
|
end; end
|
175
486
|
|
176
487
|
if __FILE__ == $PROGRAM_NAME
|
177
488
|
Extracter::Extracter.new(ARGV)
|
178
|
-
end # base.rb
|
489
|
+
end # base.rb
|