extracter 1.2.32 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,289 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'extracter/class/extract_this_archive.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
require 'extracter/base/base.rb'
|
8
|
-
|
9
|
-
module Extracter
|
10
|
-
|
11
|
-
class Extracter < ::Extracter::Base # === Extracter::Extracter
|
12
|
-
|
13
|
-
# ========================================================================= #
|
14
|
-
# === consider_verbosity_for
|
15
|
-
# ========================================================================= #
|
16
|
-
def consider_verbosity_for(i)
|
17
|
-
i = i.dup
|
18
|
-
unless be_verbose?
|
19
|
-
case i
|
20
|
-
# "tar -xvf" must become "tar -xvf" here.
|
21
|
-
when COMMAND_TO_EXTRACT_TAR_XZ_FILES
|
22
|
-
i.delete!('v')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
return i
|
26
|
-
end
|
27
|
-
|
28
|
-
# ========================================================================= #
|
29
|
-
# === extract_this_archive (extract tag)
|
30
|
-
# ========================================================================= #
|
31
|
-
def extract_this_archive(
|
32
|
-
i, extract_to = extract_to?
|
33
|
-
)
|
34
|
-
i = File.absolute_path(i)
|
35
|
-
# ======================================================================= #
|
36
|
-
# Next handle the situation when we are on Windows:
|
37
|
-
# ======================================================================= #
|
38
|
-
if ::Extracter.are_we_on_windows?
|
39
|
-
# ===================================================================== #
|
40
|
-
# On windows we will overrule this completely, for now.
|
41
|
-
# ===================================================================== #
|
42
|
-
_ = UNPACK_COMMAND_TO_USE_ON_WINDOWS+' '+
|
43
|
-
File.absolute_path(i)+
|
44
|
-
' | '+
|
45
|
-
SECOND_UNPACK_COMMAND_TO_USE_ON_WINDOWS
|
46
|
-
esystem _
|
47
|
-
return
|
48
|
-
end
|
49
|
-
# ======================================================================= #
|
50
|
-
# First determine whether we can extract the archive or whether we can
|
51
|
-
# not:
|
52
|
-
# ======================================================================= #
|
53
|
-
if ::Extracter.is_this_a_valid_archive?(i) or i.end_with?('.pdf')
|
54
|
-
if be_verbose?
|
55
|
-
if show_only_the_short_name_of_the_archive?
|
56
|
-
name_of_the_archive = File.basename(i)
|
57
|
-
copn; e "#{rev}Extracting `#{sfancy(name_of_the_archive)}#{rev}` "\
|
58
|
-
"to `#{sdir(extract_to)}#{rev}`."
|
59
|
-
else
|
60
|
-
copn; e "#{rev}Extracting `#{sfancy(i)}` to "\
|
61
|
-
"`#{sdir(extract_to)}#{rev}`."
|
62
|
-
end
|
63
|
-
end
|
64
|
-
unless File.writable? extract_to
|
65
|
-
copn; ewarn 'You do not have sufficient permissions to'
|
66
|
-
copn; ewarn "modify #{sdir(extract_to)}#{swarn('.')}"
|
67
|
-
return
|
68
|
-
end
|
69
|
-
# ===================================================================== #
|
70
|
-
# Next, pad it if it includes a ' ' character or (). This was
|
71
|
-
# disabled as of July 2022.
|
72
|
-
# ===================================================================== #
|
73
|
-
# i = pad(i) if i.include?(' ') or i.include?(')')
|
74
|
-
case i # case tag; those listed on top are more important.
|
75
|
-
# ===================================================================== #
|
76
|
-
# === .rpm
|
77
|
-
#
|
78
|
-
# This entry point will handle .rpm files.
|
79
|
-
# ===================================================================== #
|
80
|
-
when /\.rpm$/i
|
81
|
-
name_of_the_directory = i.delete_suffix('.rpm')
|
82
|
-
mkdir(name_of_the_directory)
|
83
|
-
set_extract_to(File.absolute_path(name_of_the_directory))
|
84
|
-
cd(name_of_the_directory)
|
85
|
-
esystem 'rpm2cpio ../'+File.basename(i)+' | cpio -idmv'
|
86
|
-
return # Early return.
|
87
|
-
# ===================================================================== #
|
88
|
-
# === .tar.xz
|
89
|
-
#
|
90
|
-
# Note that .txz is just .tar.xz. Support for .txz was added here
|
91
|
-
# in January of 2012.
|
92
|
-
# ===================================================================== #
|
93
|
-
when /\.tar\.xz$/i,
|
94
|
-
/\.txz$/i,
|
95
|
-
/\.xz$/i
|
96
|
-
esystem consider_verbosity_for(COMMAND_TO_EXTRACT_TAR_XZ_FILES)+' '+i+padded_extract_to?
|
97
|
-
# ===================================================================== #
|
98
|
-
# === .tar
|
99
|
-
#
|
100
|
-
# This entry point is for simple .tar files.
|
101
|
-
# ===================================================================== #
|
102
|
-
when /\.tar$/i
|
103
|
-
esystem COMMAND_TO_EXTRACT_TAR_FILES+' '+i+padded_extract_to?
|
104
|
-
# ===================================================================== #
|
105
|
-
# === zip
|
106
|
-
# ===================================================================== #
|
107
|
-
when /.zip$/i,
|
108
|
-
/.xpi$/i,
|
109
|
-
/.docx$/i,
|
110
|
-
/.odt$/i, # .docx and .odt format types can be unpacked with zip too.
|
111
|
-
/.apkg$/
|
112
|
-
# =================================================================== #
|
113
|
-
# 'ar -jxf' # unzip #{what} <-- this should work as well.
|
114
|
-
# =================================================================== #
|
115
|
-
i = pad(i) if i.include?(' ') or i.include?(')')
|
116
|
-
esystem "unzip #{i}"
|
117
|
-
# ===================================================================== #
|
118
|
-
# === tgz
|
119
|
-
#
|
120
|
-
# This entry point will also handle ".tar.Z" files.
|
121
|
-
# ===================================================================== #
|
122
|
-
when /\.?tgz$/i,
|
123
|
-
/\.?tar.Z$/i,
|
124
|
-
/\.?taz$/i
|
125
|
-
esystem COMMAND_TO_EXTRACT_TGZ_FILES+' '+i+padded_extract_to?
|
126
|
-
# ===================================================================== #
|
127
|
-
# === 7z
|
128
|
-
# ===================================================================== #
|
129
|
-
when '.7z' # 7z does not accept the -C commandline.
|
130
|
-
# _ << '7za e' # <- Deprecated this variant as of 05.06.2020.
|
131
|
-
esystem "7z x #{i}"
|
132
|
-
# ===================================================================== #
|
133
|
-
# === .tar.bz2
|
134
|
-
# ===================================================================== #
|
135
|
-
when /\.tar\.bz2$/i,
|
136
|
-
/\.tbz$/i
|
137
|
-
esystem COMMAND_TO_EXTRACT_TAR_BZ2_FILES+' '+i+padded_extract_to?
|
138
|
-
# ===================================================================== #
|
139
|
-
# === gz
|
140
|
-
# ===================================================================== #
|
141
|
-
when /\.?gz$/i,
|
142
|
-
/\.?apk$/i
|
143
|
-
if i.include? '.tar' # Handle .tar.gz here.
|
144
|
-
esystem 'tar -zxvf '+i+padded_extract_to?
|
145
|
-
else
|
146
|
-
esystem 'gunzip '+i
|
147
|
-
end
|
148
|
-
# ===================================================================== #
|
149
|
-
# === .bz2
|
150
|
-
# ===================================================================== #
|
151
|
-
when /\.?bz2$/,
|
152
|
-
/\.?tbz2$/
|
153
|
-
if i.include? '.tar' # Treat it as a .tar file.
|
154
|
-
esystem 'tar -vjxf '+i
|
155
|
-
else
|
156
|
-
esystem 'bunzip2 '+i
|
157
|
-
end
|
158
|
-
# ===================================================================== #
|
159
|
-
# === rar
|
160
|
-
# ===================================================================== #
|
161
|
-
when '.rar'
|
162
|
-
check_whether_rar_is_available
|
163
|
-
esystem 'unrar e '+i
|
164
|
-
# ===================================================================== #
|
165
|
-
# === .zst
|
166
|
-
#
|
167
|
-
# This entry point is for e. g. "pymol-2.3.0-3-x86_64.pkg.tar.zst".
|
168
|
-
# ===================================================================== #
|
169
|
-
when '.zst','.tar.zst'
|
170
|
-
esystem COMMAND_TO_EXTRACT_ZST_ARCHIVES+' '+i
|
171
|
-
# ===================================================================== #
|
172
|
-
# === deb
|
173
|
-
#
|
174
|
-
# We could use dpkg-deb too, such as via "dpkg-deb". But using "ar"
|
175
|
-
# seems to be the better choice.
|
176
|
-
# ===================================================================== #
|
177
|
-
when /\.?deb$/i
|
178
|
-
esystem COMMAND_TO_EXTRACT_DEB_FILES+' '+i
|
179
|
-
# ===================================================================== #
|
180
|
-
# === gem
|
181
|
-
#
|
182
|
-
# The gem commands needs a specific --target=DIRECTORY option.
|
183
|
-
# ===================================================================== #
|
184
|
-
when /\.?gem$/i
|
185
|
-
esystem GEM_UNPACK_COMMAND+' '+i+" --target=#{extract_to}"
|
186
|
-
# ===================================================================== #
|
187
|
-
# === lzma
|
188
|
-
# ===================================================================== #
|
189
|
-
when '.lzma'
|
190
|
-
esystem "#{COMMAND_TO_EXTRACT_LZMA_FILES} #{i}"
|
191
|
-
# ===================================================================== #
|
192
|
-
# === bin
|
193
|
-
#
|
194
|
-
# This entry point allows the user to handle .bin files. In this
|
195
|
-
# context, "handling" means to simply run that file as-is.
|
196
|
-
# ===================================================================== #
|
197
|
-
when /\.?bin$/i
|
198
|
-
esystem("./#{i}")
|
199
|
-
# ===================================================================== #
|
200
|
-
# === iso
|
201
|
-
# ===================================================================== #
|
202
|
-
when /\.?iso$/i
|
203
|
-
try_to_extract_this_iso_file(i)
|
204
|
-
return
|
205
|
-
# ===================================================================== #
|
206
|
-
# === img
|
207
|
-
#
|
208
|
-
# Note that .img in this context refers to squafhs .img files.
|
209
|
-
# ===================================================================== #
|
210
|
-
when /\.?img$/i,
|
211
|
-
/\.?squashfs$/i
|
212
|
-
try_to_extract_this_img_file(i)
|
213
|
-
return # Must return early in this case.
|
214
|
-
# ===================================================================== #
|
215
|
-
# === lz
|
216
|
-
#
|
217
|
-
# This entry point requires lzip to be installed.
|
218
|
-
# ===================================================================== #
|
219
|
-
when /\.?lz$/i,
|
220
|
-
/\.?tar\.?lz$/i
|
221
|
-
esystem("#{COMMAND_TO_EXTRACT_LZ_FILES} #{i}#{padded_extract_to?}")
|
222
|
-
# ===================================================================== #
|
223
|
-
# === mp4
|
224
|
-
#
|
225
|
-
# If it is a .mp4 file, we delegate to MultimediaParadise.extract_audio.
|
226
|
-
#
|
227
|
-
# Usage example:
|
228
|
-
#
|
229
|
-
# rubyextract foobar.mp4
|
230
|
-
#
|
231
|
-
# ===================================================================== #
|
232
|
-
when /\.?mp4$/i
|
233
|
-
begin
|
234
|
-
require 'multimedia_paradise/audio/extract_audio/extract_audio.rb'
|
235
|
-
rescue LoadError; end
|
236
|
-
if Object.const_defined? :MultimediaParadise
|
237
|
-
MultimediaParadise.extract_audio(i)
|
238
|
-
end
|
239
|
-
# ===================================================================== #
|
240
|
-
# === ps
|
241
|
-
# ===================================================================== #
|
242
|
-
when/\.?ps$/i
|
243
|
-
esystem 'ps2ascii '+i+padded_extract_to?
|
244
|
-
# ===================================================================== #
|
245
|
-
# === .jar
|
246
|
-
# ===================================================================== #
|
247
|
-
when /\.?jar$/i
|
248
|
-
esystem COMMAND_TO_EXTRACT_JAR_ARCHIVES+' '+i
|
249
|
-
# ===================================================================== #
|
250
|
-
# === rpm
|
251
|
-
# ===================================================================== #
|
252
|
-
when '.rpm'
|
253
|
-
esystem "#{COMMAND_TO_EXTRACT_BSDTAR_ARCHIVES} #{i}"
|
254
|
-
# ===================================================================== #
|
255
|
-
# === sxz
|
256
|
-
# ===================================================================== #
|
257
|
-
when '.sxz'
|
258
|
-
esystem "unsquashfs #{i}"
|
259
|
-
# ===================================================================== #
|
260
|
-
# === pdf
|
261
|
-
#
|
262
|
-
# For pdf-files we will tap into the pdf_paradise project, if it
|
263
|
-
# is available.
|
264
|
-
# ===================================================================== #
|
265
|
-
when /\.?pdf$/
|
266
|
-
begin
|
267
|
-
require 'pdf_paradise/utility_scripts/convert_pdf_to_text.rb'
|
268
|
-
_ = PdfParadise::ConvertPdfToText.new(i)
|
269
|
-
e _.output_file?
|
270
|
-
rescue LoadError => error
|
271
|
-
e 'No, not there.'
|
272
|
-
pp error # Show the error to the user here.
|
273
|
-
end
|
274
|
-
return # Must return early in this case.
|
275
|
-
else # else tag. We did not find the extension type.
|
276
|
-
notify_the_user_that_this_extension_has_not_been_registered_yet(i)
|
277
|
-
end
|
278
|
-
else
|
279
|
-
if File.exist? i
|
280
|
-
notify_the_user_that_this_extension_has_not_been_registered_yet(i)
|
281
|
-
else
|
282
|
-
opnn; e "No file exists at `#{sfile(i)}`."
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end; alias do_extract_to extract_this_archive # === do_extract_to
|
286
|
-
alias do_extract_what_to extract_this_archive # === do_extract_what_to
|
287
|
-
alias start extract_this_archive # === start
|
288
|
-
|
289
|
-
end; end
|
@@ -1,241 +0,0 @@
|
|
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
|
-
require 'extracter/base/base.rb'
|
18
|
-
|
19
|
-
module Extracter
|
20
|
-
|
21
|
-
class ExtractIt < ::Extracter::Base # === Extracter::ExtractIt
|
22
|
-
|
23
|
-
require 'extracter/class/extracter.rb' # This file will pull in some other .rb files.
|
24
|
-
require 'extracter/constants/constants.rb'
|
25
|
-
require 'extracter/toplevel_methods/misc.rb'
|
26
|
-
|
27
|
-
# ========================================================================= #
|
28
|
-
# === ExtractIt::NAMESPACE
|
29
|
-
# ========================================================================= #
|
30
|
-
NAMESPACE = inspect
|
31
|
-
|
32
|
-
# ========================================================================= #
|
33
|
-
# === ExtractIt::ARRAY_ARCHIVE_TYPES
|
34
|
-
#
|
35
|
-
# Register the available (and handled) archive types here.
|
36
|
-
# ========================================================================= #
|
37
|
-
ARRAY_ARCHIVE_TYPES = ::Extracter::ARRAY_REGISTERED_ARCHIVES
|
38
|
-
|
39
|
-
# ========================================================================= #
|
40
|
-
# === initialize
|
41
|
-
# ========================================================================= #
|
42
|
-
def initialize(
|
43
|
-
optional_set_input = nil,
|
44
|
-
run_already = true
|
45
|
-
)
|
46
|
-
reset
|
47
|
-
set_input(optional_set_input)
|
48
|
-
run if run_already
|
49
|
-
end
|
50
|
-
|
51
|
-
# ========================================================================= #
|
52
|
-
# === reset (reset tag)
|
53
|
-
# ========================================================================= #
|
54
|
-
def reset
|
55
|
-
super()
|
56
|
-
# ======================================================================= #
|
57
|
-
# === @debug
|
58
|
-
# ======================================================================= #
|
59
|
-
@debug = false
|
60
|
-
end
|
61
|
-
|
62
|
-
# ========================================================================= #
|
63
|
-
# === show_help
|
64
|
-
# ========================================================================= #
|
65
|
-
def show_help
|
66
|
-
e 'We will show a little bit help, then exit.'
|
67
|
-
e
|
68
|
-
e 'To extract .tar.xz, do:'
|
69
|
-
e
|
70
|
-
efancy ' → tar -xJf *.tar.xz'
|
71
|
-
end
|
72
|
-
|
73
|
-
# ========================================================================= #
|
74
|
-
# === set_input
|
75
|
-
#
|
76
|
-
# We will work on an Array as value to @input, at the end of this
|
77
|
-
# method.
|
78
|
-
# ========================================================================= #
|
79
|
-
def set_input(i = N)
|
80
|
-
case i
|
81
|
-
# ======================================================================= #
|
82
|
-
# === extract_it --help
|
83
|
-
# ======================================================================= #
|
84
|
-
when /-?-?help$/i # Show some help stuff here.
|
85
|
-
show_help
|
86
|
-
exit
|
87
|
-
end
|
88
|
-
i = [i] if i.is_a? String # Need an Array.
|
89
|
-
if @debug
|
90
|
-
opn; e 'The input given to us is: `'+sfile(i)+'`'
|
91
|
-
end
|
92
|
-
if i.is_a?(Array) and i.empty?
|
93
|
-
# ===================================================================== #
|
94
|
-
# In this case, try to see if the current directory has a .zip
|
95
|
-
# file. We will use this in that case.
|
96
|
-
# ===================================================================== #
|
97
|
-
is_there_a_zip_file = Dir['*.zip']
|
98
|
-
unless is_there_a_zip_file.empty?
|
99
|
-
use_this_zip_file = is_there_a_zip_file.first
|
100
|
-
notify_the_user_that_no_input_was_given_but_this_file_was_found(use_this_zip_file)
|
101
|
-
i << use_this_zip_file
|
102
|
-
end
|
103
|
-
is_there_at_the_least_one_tar_xz_file = Dir['*.tar.xz']
|
104
|
-
unless is_there_at_the_least_one_tar_xz_file.empty?
|
105
|
-
i << is_there_at_the_least_one_tar_xz_file.first
|
106
|
-
end
|
107
|
-
end
|
108
|
-
@input = i # Should be an array, always.
|
109
|
-
end
|
110
|
-
|
111
|
-
# ========================================================================= #
|
112
|
-
# === be_silent
|
113
|
-
# ========================================================================= #
|
114
|
-
def be_silent
|
115
|
-
@be_silent = true
|
116
|
-
end
|
117
|
-
|
118
|
-
# ========================================================================= #
|
119
|
-
# === be_verbose
|
120
|
-
# ========================================================================= #
|
121
|
-
def be_verbose
|
122
|
-
@be_silent = false
|
123
|
-
end; alias show_commands_used be_verbose # === show_commands_used
|
124
|
-
|
125
|
-
# ========================================================================= #
|
126
|
-
# === notify_the_user_that_no_input_was_given_but_this_file_was_found
|
127
|
-
# ========================================================================= #
|
128
|
-
def notify_the_user_that_no_input_was_given_but_this_file_was_found(
|
129
|
-
this_file
|
130
|
-
)
|
131
|
-
opn; e "No input was given to #{sfancy(NAMESPACE)} but a "\
|
132
|
-
".zip file was"
|
133
|
-
opn; e 'found in this directory ('+sdir(Dir.pwd)+'): '+
|
134
|
-
sfancy(this_file)
|
135
|
-
opn; e 'We will use this zip file.'
|
136
|
-
end
|
137
|
-
|
138
|
-
# ========================================================================= #
|
139
|
-
# === try_to_glob_on
|
140
|
-
# ========================================================================= #
|
141
|
-
def try_to_glob_on(i)
|
142
|
-
result = Dir["#{i}*"]
|
143
|
-
# ======================================================================= #
|
144
|
-
# Next, sort this result to put archives on the beginning of the Array.
|
145
|
-
# ======================================================================= #
|
146
|
-
result = result.partition {|entry| is_archive?(entry) }
|
147
|
-
result.flatten!
|
148
|
-
unless result.empty?
|
149
|
-
# ===================================================================== #
|
150
|
-
# Ok, we grab the first entry next.
|
151
|
-
# ===================================================================== #
|
152
|
-
i = result.first
|
153
|
-
opn; e "#{rev}No result could be found for the given input, "\
|
154
|
-
"thus using #{sfancy(i)} #{rev}instead."
|
155
|
-
end
|
156
|
-
i
|
157
|
-
end
|
158
|
-
|
159
|
-
# ========================================================================= #
|
160
|
-
# === extract_input
|
161
|
-
# ========================================================================= #
|
162
|
-
def extract_input
|
163
|
-
pp @input if @debug
|
164
|
-
@input.each {|entry|
|
165
|
-
to_this_dir = Dir.pwd
|
166
|
-
to_this_dir << '/' unless to_this_dir.end_with? '/'
|
167
|
-
unless File.exist? entry
|
168
|
-
entry = try_to_glob_on(entry)
|
169
|
-
end
|
170
|
-
# ===================================================================== #
|
171
|
-
# Delegate to class Extracter next.
|
172
|
-
# ===================================================================== #
|
173
|
-
Extracter.extract_what_to(
|
174
|
-
entry,
|
175
|
-
to_this_dir
|
176
|
-
) {{ be_verbose: @be_silent }}
|
177
|
-
_ = ::Extracter.remove_file_suffix(entry)
|
178
|
-
if File.exist? entry
|
179
|
-
# =================================================================== #
|
180
|
-
# Must also check whether the extracted directory exists.
|
181
|
-
# =================================================================== #
|
182
|
-
name_of_the_extracted_archive = to_this_dir+_
|
183
|
-
ARRAY_ARCHIVE_TYPES.each {|extension_name|
|
184
|
-
if name_of_the_extracted_archive.include? extension_name
|
185
|
-
quoted = Regexp.quote(extension_name)
|
186
|
-
name_of_the_extracted_archive.sub!(/#{quoted}$/,'')
|
187
|
-
end
|
188
|
-
}
|
189
|
-
if File.exist?(name_of_the_extracted_archive) and
|
190
|
-
# ================================================================= #
|
191
|
-
# The following check ensures that we really have another name
|
192
|
-
# for the extracted directory.
|
193
|
-
# ================================================================= #
|
194
|
-
!(entry == name_of_the_extracted_archive)
|
195
|
-
opn; e "#{rev}Finished extracting "\
|
196
|
-
"#{sfile(_)}#{rev} to `#{sdir(to_this_dir)}#{rev}`."
|
197
|
-
else
|
198
|
-
opn; e "#{rev}No file called `#{sfile(name_of_the_extracted_archive)}"\
|
199
|
-
"#{rev}` appears to exist."
|
200
|
-
end
|
201
|
-
end
|
202
|
-
}
|
203
|
-
end
|
204
|
-
|
205
|
-
# ========================================================================= #
|
206
|
-
# === is_archive?
|
207
|
-
# ========================================================================= #
|
208
|
-
def is_archive?(i)
|
209
|
-
ARRAY_ARCHIVE_TYPES.include?(
|
210
|
-
File.extname(File.basename(i))
|
211
|
-
)
|
212
|
-
end
|
213
|
-
|
214
|
-
# ========================================================================= #
|
215
|
-
# === run (run tag)
|
216
|
-
# ========================================================================= #
|
217
|
-
def run
|
218
|
-
extract_input
|
219
|
-
end
|
220
|
-
|
221
|
-
# ========================================================================= #
|
222
|
-
# === Extracter::ExtractIt[]
|
223
|
-
# ========================================================================= #
|
224
|
-
def self.[](i = '')
|
225
|
-
new(i)
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
# =========================================================================== #
|
231
|
-
# === Extracter.extract_it
|
232
|
-
# =========================================================================== #
|
233
|
-
def self.extract_it(i = ARGV, run_already = true)
|
234
|
-
::Extracter::ExtractIt.new(i, run_already)
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
if __FILE__ == $PROGRAM_NAME
|
240
|
-
Extracter::ExtractIt.new(ARGV)
|
241
|
-
end # extractitrb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'extracter/toplevel_methods/is_this_a_valid_archive.rb'
|
6
|
-
# Extracter.is_this_a_valid_archive?
|
7
|
-
# =========================================================================== #
|
8
|
-
module Extracter
|
9
|
-
|
10
|
-
require 'extracter/constants/constants.rb'
|
11
|
-
|
12
|
-
# ========================================================================= #
|
13
|
-
# === Extracter.is_this_a_valid_archive?
|
14
|
-
#
|
15
|
-
# Query whether the input given to this method is a valid archive.
|
16
|
-
# This allows us to determine whether the Extracter project can
|
17
|
-
# deal with the given archive at hand or whether it can not.
|
18
|
-
#
|
19
|
-
# The registered formats are stored in the constant
|
20
|
-
# ARRAY_REGISTERED_ARCHIVES.
|
21
|
-
# ========================================================================= #
|
22
|
-
def self.is_this_a_valid_archive?(
|
23
|
-
i, # The given input, such as "foobar.zip".
|
24
|
-
array_registered_archives = ARRAY_REGISTERED_ARCHIVES
|
25
|
-
)
|
26
|
-
if i.is_a? Array
|
27
|
-
i = i.first
|
28
|
-
end
|
29
|
-
return_value = false
|
30
|
-
array_registered_archives.each {|entry|
|
31
|
-
return_value = true if i =~ /#{entry}$/i
|
32
|
-
}
|
33
|
-
return return_value
|
34
|
-
end; self.instance_eval { alias is_archive? is_this_a_valid_archive? } # === Extracter.is_archive?
|
35
|
-
self.instance_eval { alias is_this_a_valid_archive? is_this_a_valid_archive? } # === Extracter.is_this_a_valid_archive?
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
if __FILE__ == $PROGRAM_NAME
|
40
|
-
pp Extracter.is_this_a_valid_archive?(ARGV)
|
41
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# === require 'extracter/toplevel_methods/misc.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module Extracter
|
8
|
-
|
9
|
-
# ========================================================================= #
|
10
|
-
# === Extracter.remove_archive_type
|
11
|
-
# ========================================================================= #
|
12
|
-
def self.remove_archive_type(i)
|
13
|
-
return i.delete_suffix('.xz').
|
14
|
-
delete_suffix('.tgz').
|
15
|
-
delete_suffix('.bz2').
|
16
|
-
delete_suffix('.gz').
|
17
|
-
delete_suffix('.tar').
|
18
|
-
delete_suffix('.zip').
|
19
|
-
delete_suffix('.gem')
|
20
|
-
end; self.instance_eval { alias remove_file_suffix remove_archive_type } # === Extracter.remove_file_suffix
|
21
|
-
|
22
|
-
# ========================================================================= #
|
23
|
-
# === Extracter.are_we_on_windows?
|
24
|
-
# ========================================================================= #
|
25
|
-
def self.are_we_on_windows?
|
26
|
-
RUBY_PLATFORM.include?('win') or
|
27
|
-
RUBY_PLATFORM.include?('mingw')
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
if __FILE__ == $PROGRAM_NAME
|
33
|
-
puts Extracter.are_we_on_windows?
|
34
|
-
end
|